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

Improve KnativeEventing finalization for TLS resources #1590

Merged
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: 4 additions & 2 deletions pkg/reconciler/knativeeventing/eventing_tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ import (
"knative.dev/operator/pkg/apis/operator/v1beta1"
)

var (
tlsResourcesPred = byGroup("cert-manager.io")
)

func (r *Reconciler) handleTLSResources(ctx context.Context, manifests *mf.Manifest, comp base.KComponent) error {
instance := comp.(*v1beta1.KnativeEventing)

if isTLSEnabled(instance) {
return nil
}

tlsResourcesPred := byGroup("cert-manager.io")

// Delete TLS resources (if present)
toBeDeleted := manifests.Filter(tlsResourcesPred)
if err := toBeDeleted.Delete(mf.IgnoreNotFound(true)); err != nil && !meta.IsNoMatchError(err) {
Expand Down
21 changes: 20 additions & 1 deletion pkg/reconciler/knativeeventing/knativeeventing.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"

mf "github.com/manifestival/manifestival"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

Expand Down Expand Up @@ -90,9 +91,27 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, original *v1beta1.Knative
return nil
}

if err = common.Uninstall(manifest); err != nil {
// For optional resources like cert-manager's Certificates and Issuers, we don't want to fail
// finalization when such operator is not installed, so we split the resources in
// - optional resources (TLS resources, etc)
// - resources (core k8s resources)
//
// Then, we delete `resources` first and after we delete optional resources while also ignoring
// errors returned when such operators are not installed.

optionalResourcesPred := mf.Any(tlsResourcesPred)

optionalResources := manifest.Filter(optionalResourcesPred)
resources := manifest.Filter(mf.Not(optionalResourcesPred))

if err = common.Uninstall(&resources); err != nil {
logger.Error("Failed to finalize platform resources", err)
}

if err := common.Uninstall(&optionalResources); err != nil && !meta.IsNoMatchError(err) {
logger.Error("Failed to finalize platform resources", err)
}

return nil
}

Expand Down
Loading