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

Fix wrong deletion message on flux diff #2389

Merged
merged 1 commit into from
Feb 7, 2022
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/gonvenience/ytbx v1.4.2
github.com/google/go-cmp v0.5.6
github.com/google/go-containerregistry v0.2.0
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
github.com/homeport/dyff v1.4.6
github.com/lucasb-eyer/go-colorful v1.2.0
Expand Down
13 changes: 6 additions & 7 deletions internal/build/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/gonvenience/bunt"
"github.com/gonvenience/ytbx"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-multierror"
"github.com/homeport/dyff/pkg/dyff"
"github.com/lucasb-eyer/go-colorful"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -76,6 +77,7 @@ func (b *Builder) Diff() (string, bool, error) {
return "", createdOrDrifted, err
}

var diffErrs error
// create an inventory of objects to be reconciled
newInventory := newInventory()
for _, obj := range objects {
Expand All @@ -86,11 +88,8 @@ func (b *Builder) Diff() (string, bool, error) {
}
change, liveObject, mergedObject, err := resourceManager.Diff(ctx, obj, diffOptions)
if err != nil {
if b.kustomization.Spec.Force && ssa.IsImmutableError(err) {
output.WriteString(writeString(fmt.Sprintf("► %s created\n", obj.GetName()), bunt.Green))
} else {
output.WriteString(writeString(fmt.Sprintf("✗ %v\n", err), bunt.Red))
}
// gather errors and continue, as we want to see all the diffs
diffErrs = multierror.Append(diffErrs, err)
continue
}

Expand Down Expand Up @@ -124,7 +123,7 @@ func (b *Builder) Diff() (string, bool, error) {
addObjectsToInventory(newInventory, change)
}

if b.kustomization.Spec.Prune {
if b.kustomization.Spec.Prune && diffErrs == nil {
oldStatus := b.kustomization.Status.DeepCopy()
if oldStatus.Inventory != nil {
diffObjects, err := diffInventory(oldStatus.Inventory, newInventory)
Expand All @@ -137,7 +136,7 @@ func (b *Builder) Diff() (string, bool, error) {
}
}

return output.String(), createdOrDrifted, nil
return output.String(), createdOrDrifted, diffErrs
}

func writeYamls(liveObject, mergedObject *unstructured.Unstructured) (string, string, string, error) {
Expand Down