Skip to content

Commit

Permalink
Ignore no match errors on deleting obsolete resources (#1741)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <[email protected]>
Co-authored-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
knative-prow-robot and pierDipi authored Mar 13, 2024
1 parent 99c1778 commit d8ca9ef
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/reconciler/common/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ package common

import (
"context"
"fmt"

mf "github.com/manifestival/manifestival"
"knative.dev/operator/pkg/apis/operator/base"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"knative.dev/pkg/logging"

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

// Stage represents a step in the reconcile process
Expand Down Expand Up @@ -110,6 +114,12 @@ func DeleteObsoleteResources(ctx context.Context, instance base.KComponent, fetc
return NoOp
}
return func(_ context.Context, manifest *mf.Manifest, _ base.KComponent) error {
return installed.Filter(mf.NoCRDs, mf.Not(mf.In(*manifest))).Delete()
for _, r := range installed.Filter(mf.NoCRDs, mf.Not(mf.In(*manifest))).Resources() {
m, _ := mf.ManifestFrom(mf.Slice([]unstructured.Unstructured{r}), mf.UseClient(manifest.Client))
if err := m.Delete(); err != nil && !meta.IsNoMatchError(err) {
return fmt.Errorf("failed to delete obsolete resources: %w", err)
}
}
return nil
}
}

0 comments on commit d8ca9ef

Please sign in to comment.