Skip to content

Commit 57c6302

Browse files
authored
Merge pull request #451 from fluxcd/ssa-fix-diff
Fix drift detection in Secrets and ConfigMaps
2 parents f705412 + a292f28 commit 57c6302

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

controllers/kustomization_controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,10 @@ func (r *KustomizationReconciler) build(ctx context.Context, kustomization kusto
611611
func (r *KustomizationReconciler) apply(ctx context.Context, manager *ssa.ResourceManager, kustomization kustomizev1.Kustomization, revision string, objects []*unstructured.Unstructured) (bool, error) {
612612
log := logr.FromContext(ctx)
613613

614+
if err := ssa.SetNativeKindsDefaults(objects); err != nil {
615+
return false, err
616+
}
617+
614618
// contains only CRDs and Namespaces
615619
var stageOne []*unstructured.Unstructured
616620

@@ -651,9 +655,6 @@ func (r *KustomizationReconciler) apply(ctx context.Context, manager *ssa.Resour
651655
// sort by kind, validate and apply all the others objects
652656
sort.Sort(ssa.SortableUnstructureds(stageTwo))
653657
if len(stageTwo) > 0 {
654-
if err := ssa.SetNativeKindsDefaults(stageTwo); err != nil {
655-
return false, err
656-
}
657658
changeSet, err := manager.ApplyAll(ctx, stageTwo, kustomization.Spec.Force)
658659
if err != nil {
659660
return false, fmt.Errorf("%w\n%s", err, changeSetLog.String())

controllers/kustomization_decryptor_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,20 @@ func TestKustomizationReconciler_Decryptor(t *testing.T) {
138138
g.Expect(string(encodedSecret.Data["month.yaml"])).To(Equal("month: May\n"))
139139
})
140140

141+
t.Run("does not emit change events for identical secrets", func(t *testing.T) {
142+
resultK := &kustomizev1.Kustomization{}
143+
revision := "v2.0.0"
144+
err = applyGitRepository(repositoryName, artifactURL, revision, artifactChecksum+"v2")
145+
g.Expect(err).NotTo(HaveOccurred())
146+
147+
g.Eventually(func() bool {
148+
_ = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(kustomization), resultK)
149+
return resultK.Status.LastAttemptedRevision == revision
150+
}, timeout, time.Second).Should(BeTrue())
151+
152+
events := getEvents(resultK.GetName(), map[string]string{"kustomize.toolkit.fluxcd.io/revision": revision})
153+
g.Expect(len(events)).To(BeIdenticalTo(1))
154+
g.Expect(events[0].Message).Should(ContainSubstring("Reconciliation finished"))
155+
g.Expect(events[0].Message).ShouldNot(ContainSubstring("configured"))
156+
})
141157
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/fluxcd/pkg/apis/kustomize v0.2.0
1313
github.com/fluxcd/pkg/apis/meta v0.10.1
1414
github.com/fluxcd/pkg/runtime v0.12.2
15-
github.com/fluxcd/pkg/ssa v0.0.3
15+
github.com/fluxcd/pkg/ssa v0.0.5
1616
github.com/fluxcd/pkg/testserver v0.1.0
1717
github.com/fluxcd/pkg/untar v0.1.0
1818
github.com/fluxcd/source-controller/api v0.16.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ github.com/fluxcd/pkg/apis/meta v0.10.1/go.mod h1:yUblM2vg+X8TE3A2VvJfdhkGmg+uqB
218218
github.com/fluxcd/pkg/runtime v0.12.0/go.mod h1:EyaTR2TOYcjL5U//C4yH3bt2tvTgIOSXpVRbWxUn/C4=
219219
github.com/fluxcd/pkg/runtime v0.12.2 h1:4iOpx2j/w15kNemDOnZrF6ugJ/rhSmRu7aI+xn23+BI=
220220
github.com/fluxcd/pkg/runtime v0.12.2/go.mod h1:tuWdqpWPhgjQvYrSnojdZ4plyU8DRU1NDzsfOhnzl2g=
221-
github.com/fluxcd/pkg/ssa v0.0.3 h1:5s/dZIaJGtI/46w5VRmr5sy/jNJGpxPnSad8oSzAbkc=
222-
github.com/fluxcd/pkg/ssa v0.0.3/go.mod h1:B/6V2gF3zq3P6EstM/qTmOEUf3YgOh1ybFfAAmG4Shw=
221+
github.com/fluxcd/pkg/ssa v0.0.5 h1:WA8ShFeRTOLa8A1QZMyzIPygeMmHufkJhs1IpHEwX5w=
222+
github.com/fluxcd/pkg/ssa v0.0.5/go.mod h1:B/6V2gF3zq3P6EstM/qTmOEUf3YgOh1ybFfAAmG4Shw=
223223
github.com/fluxcd/pkg/testserver v0.1.0 h1:nOYgM1HYFZNNSUFykuWDmrsxj4jQxUCvmLHWOQeqmyA=
224224
github.com/fluxcd/pkg/testserver v0.1.0/go.mod h1:fvt8BHhXw6c1+CLw1QFZxcQprlcXzsrL4rzXaiGM+Iw=
225225
github.com/fluxcd/pkg/untar v0.1.0 h1:k97V/xV5hFrAkIkVPuv5AVhyxh1ZzzAKba/lbDfGo6o=

0 commit comments

Comments
 (0)