Skip to content

Commit dab658f

Browse files
committed
diff: add premature diff debug log
As there are currently no other utilities to properly see what change the controller detected, this allows people to have an insight into the observed changes by configuring the controller with `--log-level=debug`. Signed-off-by: Hidde Beydals <hidde@hhh.computer>
1 parent 997a910 commit dab658f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

internal/diff/differ.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ package diff
1919
import (
2020
"context"
2121
"fmt"
22+
"github.com/fluxcd/pkg/runtime/logger"
23+
"github.com/google/go-cmp/cmp"
24+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
25+
ctrl "sigs.k8s.io/controller-runtime"
2226
"strings"
2327

2428
"helm.sh/helm/v3/pkg/release"
@@ -105,7 +109,7 @@ func (d *Differ) Diff(ctx context.Context, rel *release.Release) (*ssa.ChangeSet
105109
}
106110
}
107111

108-
entry, _, _, err := resourceManager.Diff(ctx, obj, ssa.DiffOptions{
112+
entry, releaseObject, clusterObject, err := resourceManager.Diff(ctx, obj, ssa.DiffOptions{
109113
Exclusions: map[string]string{
110114
MetadataKey: MetadataDisabledValue,
111115
},
@@ -118,6 +122,15 @@ func (d *Differ) Diff(ctx context.Context, rel *release.Release) (*ssa.ChangeSet
118122
case ssa.CreatedAction, ssa.ConfiguredAction:
119123
diff = true
120124
changeSet.Add(*entry)
125+
126+
if entry.Action == ssa.ConfiguredAction {
127+
// TODO: remove this once we have a better way to log the diff
128+
// for example using a custom dyff reporter, or a flux CLI command
129+
ctrl.LoggerFrom(ctx).V(logger.DebugLevel).Info(entry.Subject + " diff:" + cmp.Diff(
130+
unstructuredWithoutStatus(releaseObject).UnstructuredContent(),
131+
unstructuredWithoutStatus(clusterObject).UnstructuredContent(),
132+
))
133+
}
121134
case ssa.SkippedAction:
122135
changeSet.Add(*entry)
123136
}
@@ -129,3 +142,9 @@ func (d *Differ) Diff(ctx context.Context, rel *release.Release) (*ssa.ChangeSet
129142
}
130143
return changeSet, diff, err
131144
}
145+
146+
func unstructuredWithoutStatus(obj *unstructured.Unstructured) *unstructured.Unstructured {
147+
obj = obj.DeepCopy()
148+
delete(obj.Object, "status")
149+
return obj
150+
}

0 commit comments

Comments
 (0)