Skip to content

Commit

Permalink
Improve manifest deletion error handling (#1589)
Browse files Browse the repository at this point in the history
It might happen that not all resources were created successfully
so we should not fail finalization when resources are not found,
we can just ignore not found errors.

Signed-off-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
pierDipi authored Oct 9, 2023
1 parent 3670be5 commit 39c1219
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/reconciler/common/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
"strings"

mf "github.com/manifestival/manifestival"
"knative.dev/pkg/logging"

"knative.dev/operator/pkg/apis/operator/base"
"knative.dev/operator/pkg/apis/operator/v1beta1"
"knative.dev/pkg/logging"
)

var (
Expand Down Expand Up @@ -73,11 +74,11 @@ func Install(ctx context.Context, manifest *mf.Manifest, instance base.KComponen

// Uninstall removes all resources except CRDs, which are never deleted automatically.
func Uninstall(manifest *mf.Manifest) error {
if err := manifest.Filter(mf.NoCRDs, mf.Not(mf.Any(role, rolebinding))).Delete(); err != nil {
if err := manifest.Filter(mf.NoCRDs, mf.Not(mf.Any(role, rolebinding))).Delete(mf.IgnoreNotFound(true)); err != nil {
return fmt.Errorf("failed to remove non-crd/non-rbac resources: %w", err)
}
// Delete Roles last, as they may be useful for human operators to clean up.
if err := manifest.Filter(mf.Any(role, rolebinding)).Delete(); err != nil {
if err := manifest.Filter(mf.Any(role, rolebinding)).Delete(mf.IgnoreNotFound(true)); err != nil {
return fmt.Errorf("failed to remove rbac: %w", err)
}
return nil
Expand Down

0 comments on commit 39c1219

Please sign in to comment.