Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/v1.0.x] Exclude skipped resources from apply events #921

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/controller/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand All @@ -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")
}
}
Expand All @@ -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")
}
}
Expand Down
15 changes: 15 additions & 0 deletions internal/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
}