diff --git a/controllers/kustomization_controller.go b/controllers/kustomization_controller.go index 3b9d1cee..a0a4d554 100644 --- a/controllers/kustomization_controller.go +++ b/controllers/kustomization_controller.go @@ -611,6 +611,10 @@ func (r *KustomizationReconciler) build(ctx context.Context, kustomization kusto func (r *KustomizationReconciler) apply(ctx context.Context, manager *ssa.ResourceManager, kustomization kustomizev1.Kustomization, revision string, objects []*unstructured.Unstructured) (bool, error) { log := logr.FromContext(ctx) + if err := ssa.SetNativeKindsDefaults(objects); err != nil { + return false, err + } + // contains only CRDs and Namespaces var stageOne []*unstructured.Unstructured @@ -651,9 +655,6 @@ func (r *KustomizationReconciler) apply(ctx context.Context, manager *ssa.Resour // sort by kind, validate and apply all the others objects sort.Sort(ssa.SortableUnstructureds(stageTwo)) if len(stageTwo) > 0 { - if err := ssa.SetNativeKindsDefaults(stageTwo); err != nil { - return false, err - } changeSet, err := manager.ApplyAll(ctx, stageTwo, kustomization.Spec.Force) if err != nil { return false, fmt.Errorf("%w\n%s", err, changeSetLog.String()) diff --git a/controllers/kustomization_decryptor_test.go b/controllers/kustomization_decryptor_test.go index ab2699a8..12155062 100644 --- a/controllers/kustomization_decryptor_test.go +++ b/controllers/kustomization_decryptor_test.go @@ -138,4 +138,20 @@ func TestKustomizationReconciler_Decryptor(t *testing.T) { g.Expect(string(encodedSecret.Data["month.yaml"])).To(Equal("month: May\n")) }) + t.Run("does not emit change events for identical secrets", func(t *testing.T) { + resultK := &kustomizev1.Kustomization{} + revision := "v2.0.0" + err = applyGitRepository(repositoryName, artifactURL, revision, artifactChecksum+"v2") + g.Expect(err).NotTo(HaveOccurred()) + + g.Eventually(func() bool { + _ = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(kustomization), resultK) + return resultK.Status.LastAttemptedRevision == revision + }, timeout, time.Second).Should(BeTrue()) + + events := getEvents(resultK.GetName(), map[string]string{"kustomize.toolkit.fluxcd.io/revision": revision}) + g.Expect(len(events)).To(BeIdenticalTo(1)) + g.Expect(events[0].Message).Should(ContainSubstring("Reconciliation finished")) + g.Expect(events[0].Message).ShouldNot(ContainSubstring("configured")) + }) } diff --git a/go.mod b/go.mod index 34af32a0..f459afcb 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/fluxcd/pkg/apis/kustomize v0.2.0 github.com/fluxcd/pkg/apis/meta v0.10.1 github.com/fluxcd/pkg/runtime v0.12.2 - github.com/fluxcd/pkg/ssa v0.0.3 + github.com/fluxcd/pkg/ssa v0.0.5 github.com/fluxcd/pkg/testserver v0.1.0 github.com/fluxcd/pkg/untar v0.1.0 github.com/fluxcd/source-controller/api v0.16.0 diff --git a/go.sum b/go.sum index 34a27cab..57dc3545 100644 --- a/go.sum +++ b/go.sum @@ -218,8 +218,8 @@ github.com/fluxcd/pkg/apis/meta v0.10.1/go.mod h1:yUblM2vg+X8TE3A2VvJfdhkGmg+uqB github.com/fluxcd/pkg/runtime v0.12.0/go.mod h1:EyaTR2TOYcjL5U//C4yH3bt2tvTgIOSXpVRbWxUn/C4= github.com/fluxcd/pkg/runtime v0.12.2 h1:4iOpx2j/w15kNemDOnZrF6ugJ/rhSmRu7aI+xn23+BI= github.com/fluxcd/pkg/runtime v0.12.2/go.mod h1:tuWdqpWPhgjQvYrSnojdZ4plyU8DRU1NDzsfOhnzl2g= -github.com/fluxcd/pkg/ssa v0.0.3 h1:5s/dZIaJGtI/46w5VRmr5sy/jNJGpxPnSad8oSzAbkc= -github.com/fluxcd/pkg/ssa v0.0.3/go.mod h1:B/6V2gF3zq3P6EstM/qTmOEUf3YgOh1ybFfAAmG4Shw= +github.com/fluxcd/pkg/ssa v0.0.5 h1:WA8ShFeRTOLa8A1QZMyzIPygeMmHufkJhs1IpHEwX5w= +github.com/fluxcd/pkg/ssa v0.0.5/go.mod h1:B/6V2gF3zq3P6EstM/qTmOEUf3YgOh1ybFfAAmG4Shw= github.com/fluxcd/pkg/testserver v0.1.0 h1:nOYgM1HYFZNNSUFykuWDmrsxj4jQxUCvmLHWOQeqmyA= github.com/fluxcd/pkg/testserver v0.1.0/go.mod h1:fvt8BHhXw6c1+CLw1QFZxcQprlcXzsrL4rzXaiGM+Iw= github.com/fluxcd/pkg/untar v0.1.0 h1:k97V/xV5hFrAkIkVPuv5AVhyxh1ZzzAKba/lbDfGo6o=