From d1a0c9902c99f3699b7abc78e4d013564658347f Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Thu, 6 Jul 2023 10:38:12 +0300 Subject: [PATCH] Exclude skipped resources from apply events Signed-off-by: Stefan Prodan (cherry picked from commit b1d2b72b11252adf76e5f6156885fec4bb24c230) --- internal/controller/kustomization_controller.go | 6 +++--- internal/controller/utils.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/controller/kustomization_controller.go b/internal/controller/kustomization_controller.go index 84f43e4e..3def3efc 100644 --- a/internal/controller/kustomization_controller.go +++ b/internal/controller/kustomization_controller.go @@ -741,7 +741,7 @@ func (r *KustomizationReconciler) apply(ctx context.Context, if changeSet != nil && len(changeSet.Entries) > 0 { log.Info("server-side apply for cluster definitions completed", "output", changeSet.ToMap()) for _, change := range changeSet.Entries { - if change.Action != ssa.UnchangedAction { + if HasChanged(change.Action) { changeSetLog.WriteString(change.String() + "\n") } } @@ -766,7 +766,7 @@ func (r *KustomizationReconciler) apply(ctx context.Context, if changeSet != nil && len(changeSet.Entries) > 0 { log.Info("server-side apply for cluster class types completed", "output", changeSet.ToMap()) for _, change := range changeSet.Entries { - if change.Action != ssa.UnchangedAction { + if HasChanged(change.Action) { changeSetLog.WriteString(change.String() + "\n") } } @@ -792,7 +792,7 @@ func (r *KustomizationReconciler) apply(ctx context.Context, if changeSet != nil && len(changeSet.Entries) > 0 { log.Info("server-side apply completed", "output", changeSet.ToMap(), "revision", revision) for _, change := range changeSet.Entries { - if change.Action != ssa.UnchangedAction { + if HasChanged(change.Action) { changeSetLog.WriteString(change.String() + "\n") } } diff --git a/internal/controller/utils.go b/internal/controller/utils.go index b9135a30..c186fdec 100644 --- a/internal/controller/utils.go +++ b/internal/controller/utils.go @@ -20,6 +20,8 @@ import ( "fmt" "os" "path/filepath" + + "github.com/fluxcd/pkg/ssa" ) // MkdirTempAbs creates a tmp dir and returns the absolute path to the dir. @@ -36,3 +38,16 @@ func MkdirTempAbs(dir, pattern string) (string, error) { } return tmpDir, nil } + +// HasChanged evaluates the given action and returns true +// if the action type matches a resource mutation or deletion. +func HasChanged(action ssa.Action) bool { + switch action { + case ssa.SkippedAction: + return false + case ssa.UnchangedAction: + return false + default: + return true + } +}