Skip to content

Commit

Permalink
fix for OCPBUGS-31550-deleting_SMCP_breaks_Gateway_API
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhAgniRedhat committed Aug 7, 2024
1 parent a9b7292 commit 93c20b7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
22 changes: 22 additions & 0 deletions pkg/operator/controller/gatewayclass/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/controller/gatewayclass/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 93c20b7

Please sign in to comment.