From 93c20b74ba414bd396234a485a405e6f3190ddb8 Mon Sep 17 00:00:00 2001 From: anirudhAgniRedhat Date: Thu, 1 Aug 2024 17:07:00 +0530 Subject: [PATCH] fix for OCPBUGS-31550-deleting_SMCP_breaks_Gateway_API --- .../controller/gatewayclass/controller.go | 22 +++++++++++++++++++ .../gatewayclass/servicemeshcontrolplane.go | 4 ++-- .../controller/gatewayclass/subscription.go | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pkg/operator/controller/gatewayclass/controller.go b/pkg/operator/controller/gatewayclass/controller.go index 800214ac53..9eb5e7751c 100644 --- a/pkg/operator/controller/gatewayclass/controller.go +++ b/pkg/operator/controller/gatewayclass/controller.go @@ -5,6 +5,9 @@ import ( logf "github.com/openshift/cluster-ingress-operator/pkg/log" + maistrav2 "github.com/maistra/istio-operator/pkg/apis/maistra/v2" + operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" + "k8s.io/client-go/tools/record" gatewayapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" @@ -14,6 +17,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/predicate" @@ -61,6 +65,24 @@ func NewUnmanaged(mgr manager.Manager, config Config) (controller.Controller, er if err := c.Watch(source.Kind(operatorCache, &gatewayapiv1beta1.GatewayClass{}), &handler.EnqueueRequestForObject{}, isOurGatewayClass, predicate.Not(isIstioGatewayClass)); err != nil { return nil, err } + if err := c.Watch(source.Kind(operatorCache, &maistrav2.ServiceMeshControlPlane{}), &handler.EnqueueRequestForObject{}, predicate.Funcs{ + CreateFunc: func(e event.CreateEvent) bool { return false }, + DeleteFunc: func(e event.DeleteEvent) bool { return true }, + UpdateFunc: func(e event.UpdateEvent) bool { return false }, + GenericFunc: func(e event.GenericEvent) bool { return false }, + }); err != nil { + return nil, err + } + + if err := c.Watch(source.Kind(operatorCache, &operatorsv1alpha1.Subscription{}), &handler.EnqueueRequestForObject{}, isOurGatewayClass, predicate.Funcs{ + CreateFunc: func(e event.CreateEvent) bool { return false }, + DeleteFunc: func(e event.DeleteEvent) bool { return true }, + UpdateFunc: func(e event.UpdateEvent) bool { return false }, + GenericFunc: func(e event.GenericEvent) bool { return false }, + }); err != nil { + return nil, err + } + return c, nil } diff --git a/pkg/operator/controller/gatewayclass/servicemeshcontrolplane.go b/pkg/operator/controller/gatewayclass/servicemeshcontrolplane.go index 29083939e3..97151008b7 100644 --- a/pkg/operator/controller/gatewayclass/servicemeshcontrolplane.go +++ b/pkg/operator/controller/gatewayclass/servicemeshcontrolplane.go @@ -24,7 +24,7 @@ import ( func (r *reconciler) ensureServiceMeshControlPlane(ctx context.Context, gatewayclass *gatewayapiv1beta1.GatewayClass) (bool, *maistrav2.ServiceMeshControlPlane, error) { name := controller.ServiceMeshControlPlaneName(r.config.OperandNamespace) have, current, err := r.currentServiceMeshControlPlane(ctx, name) - if err != nil { + if err != nil && !errors.IsNotFound(err) { return false, nil, err } @@ -162,7 +162,7 @@ func (r *reconciler) currentServiceMeshControlPlane(ctx context.Context, name ty var smcp maistrav2.ServiceMeshControlPlane if err := r.cache.Get(ctx, name, &smcp); err != nil { if errors.IsNotFound(err) { - return false, nil, nil + return false, nil, err } return false, nil, fmt.Errorf("failed to get ServiceMeshControlPlane %s: %w", name, err) } diff --git a/pkg/operator/controller/gatewayclass/subscription.go b/pkg/operator/controller/gatewayclass/subscription.go index a37388fa4d..fb59d72928 100644 --- a/pkg/operator/controller/gatewayclass/subscription.go +++ b/pkg/operator/controller/gatewayclass/subscription.go @@ -22,7 +22,7 @@ import ( func (r *reconciler) ensureServiceMeshOperatorSubscription(ctx context.Context) (bool, *operatorsv1alpha1.Subscription, error) { name := operatorcontroller.ServiceMeshSubscriptionName() have, current, err := r.currentSubscription(ctx, name) - if err != nil { + if err != nil && !errors.IsNotFound(err) { return false, nil, err } @@ -70,7 +70,7 @@ func (r *reconciler) currentSubscription(ctx context.Context, name types.Namespa var subscription operatorsv1alpha1.Subscription if err := r.client.Get(ctx, name, &subscription); err != nil { if errors.IsNotFound(err) { - return false, nil, nil + return false, nil, err } return false, nil, fmt.Errorf("failed to get subscription %s: %w", name, err) }