From 218eebd98a63287d80eeb2520d2764ef3147ba86 Mon Sep 17 00:00:00 2001 From: KevFan Date: Wed, 8 Jan 2025 11:27:06 +0000 Subject: [PATCH] fix: only register Certificates managed by Kuadrant to the topology Signed-off-by: KevFan --- controllers/state_of_the_world.go | 35 +------------------------------ 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/controllers/state_of_the_world.go b/controllers/state_of_the_world.go index df25bcb3a..a12a0863f 100644 --- a/controllers/state_of_the_world.go +++ b/controllers/state_of_the_world.go @@ -25,7 +25,6 @@ import ( "k8s.io/client-go/dynamic" "k8s.io/utils/env" ctrlruntime "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/event" ctrlruntimepredicate "sigs.k8s.io/controller-runtime/pkg/predicate" gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" @@ -364,29 +363,12 @@ func (b *BootOptionsBuilder) Reconciler() controller.ReconcileFunc { } func certManagerControllerOpts() []controller.ControllerOption { - isCertificateOwnedByTLSPolicy := func(c *certmanagerv1.Certificate) bool { - return isObjectOwnedByGroupKind(c, kuadrantv1.TLSPolicyGroupKind) - } - return []controller.ControllerOption{ controller.WithRunnable("certificate watcher", controller.Watch( &certmanagerv1.Certificate{}, CertManagerCertificatesResource, metav1.NamespaceAll, - controller.WithPredicates(ctrlruntimepredicate.TypedFuncs[*certmanagerv1.Certificate]{ - CreateFunc: func(e event.TypedCreateEvent[*certmanagerv1.Certificate]) bool { - return isCertificateOwnedByTLSPolicy(e.Object) - }, - UpdateFunc: func(e event.TypedUpdateEvent[*certmanagerv1.Certificate]) bool { - return isCertificateOwnedByTLSPolicy(e.ObjectNew) - }, - DeleteFunc: func(e event.TypedDeleteEvent[*certmanagerv1.Certificate]) bool { - return isCertificateOwnedByTLSPolicy(e.Object) - }, - GenericFunc: func(e event.TypedGenericEvent[*certmanagerv1.Certificate]) bool { - return isCertificateOwnedByTLSPolicy(e.Object) - }, - })), + controller.FilterResourcesByLabel[*certmanagerv1.Certificate](fmt.Sprintf("%s=%s", AppLabelKey, AppLabelValue))), ), controller.WithRunnable("issuers watcher", controller.Watch( &certmanagerv1.Issuer{}, @@ -473,18 +455,3 @@ func KuadrantManagedObjectLabels() labels.Set { kuadrantManagedLabelKey: "true", }) } - -func isObjectOwnedByGroupKind(o client.Object, groupKind schema.GroupKind) bool { - for _, o := range o.GetOwnerReferences() { - oGV, err := schema.ParseGroupVersion(o.APIVersion) - if err != nil { - return false - } - - if oGV.Group == groupKind.Group && o.Kind == groupKind.Kind { - return true - } - } - - return false -}