-
Notifications
You must be signed in to change notification settings - Fork 2
chore: remove useless watch #173
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,17 +17,11 @@ import ( | |
| "fmt" | ||
|
|
||
| "github.com/go-logr/logr" | ||
| networkingv1 "k8s.io/api/networking/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/builder" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/handler" | ||
| "sigs.k8s.io/controller-runtime/pkg/predicate" | ||
| "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
|
||
| "github.com/apache/apisix-ingress-controller/api/v1alpha1" | ||
| apiv2 "github.com/apache/apisix-ingress-controller/api/v2" | ||
| "github.com/apache/apisix-ingress-controller/internal/controller/status" | ||
| "github.com/apache/apisix-ingress-controller/internal/utils" | ||
|
|
@@ -46,15 +40,6 @@ func (r *ApisixPluginConfigReconciler) SetupWithManager(mgr ctrl.Manager) error | |
| return ctrl.NewControllerManagedBy(mgr). | ||
| For(&apiv2.ApisixPluginConfig{}). | ||
| WithEventFilter(predicate.GenerationChangedPredicate{}). | ||
| Watches(&networkingv1.IngressClass{}, | ||
| handler.EnqueueRequestsFromMapFunc(r.listApisixPluginConfigForIngressClass), | ||
| builder.WithPredicates( | ||
| predicate.NewPredicateFuncs(r.matchesIngressController), | ||
| ), | ||
| ). | ||
| Watches(&v1alpha1.GatewayProxy{}, | ||
| handler.EnqueueRequestsFromMapFunc(r.listApisixPluginConfigForGatewayProxy), | ||
| ). | ||
| Named("apisixpluginconfig"). | ||
| Complete(r) | ||
| } | ||
|
|
@@ -65,123 +50,15 @@ func (r *ApisixPluginConfigReconciler) Reconcile(ctx context.Context, req ctrl.R | |
| return ctrl.Result{}, client.IgnoreNotFound(err) | ||
| } | ||
|
|
||
| var ( | ||
| ic *networkingv1.IngressClass | ||
| err error | ||
| ) | ||
| var err error | ||
| defer func() { | ||
| r.updateStatus(&pc, err) | ||
| }() | ||
|
|
||
| if ic, err = r.getIngressClass(&pc); err != nil { | ||
| return ctrl.Result{}, err | ||
| } | ||
| if err = r.processIngressClassParameters(ctx, &pc, ic); err != nil { | ||
| return ctrl.Result{}, err | ||
| } | ||
| // Only update status | ||
| return ctrl.Result{}, nil | ||
| } | ||
|
||
|
|
||
| func (r *ApisixPluginConfigReconciler) listApisixPluginConfigForIngressClass(ctx context.Context, object client.Object) (requests []reconcile.Request) { | ||
| ic, ok := object.(*networkingv1.IngressClass) | ||
| if !ok { | ||
| return nil | ||
| } | ||
|
|
||
| isDefaultIngressClass := IsDefaultIngressClass(ic) | ||
| var pcList apiv2.ApisixPluginConfigList | ||
| if err := r.List(ctx, &pcList); err != nil { | ||
| return nil | ||
| } | ||
| for _, pc := range pcList.Items { | ||
| if pc.Spec.IngressClassName == ic.Name || (isDefaultIngressClass && pc.Spec.IngressClassName == "") { | ||
| requests = append(requests, reconcile.Request{NamespacedName: utils.NamespacedName(&pc)}) | ||
| } | ||
| } | ||
| return requests | ||
| } | ||
|
|
||
| func (r *ApisixPluginConfigReconciler) listApisixPluginConfigForGatewayProxy(ctx context.Context, object client.Object) (requests []reconcile.Request) { | ||
| gp, ok := object.(*v1alpha1.GatewayProxy) | ||
| if !ok { | ||
| return nil | ||
| } | ||
|
|
||
| var icList networkingv1.IngressClassList | ||
| if err := r.List(ctx, &icList); err != nil { | ||
| r.Log.Error(err, "failed to list ingress classes for gateway proxy", "gatewayproxy", gp.GetName()) | ||
| return nil | ||
| } | ||
|
|
||
| for _, ic := range icList.Items { | ||
| requests = append(requests, r.listApisixPluginConfigForIngressClass(ctx, &ic)...) | ||
| } | ||
|
|
||
| return requests | ||
| } | ||
|
|
||
| func (r *ApisixPluginConfigReconciler) matchesIngressController(obj client.Object) bool { | ||
| ingressClass, ok := obj.(*networkingv1.IngressClass) | ||
| if !ok { | ||
| return false | ||
| } | ||
| return matchesController(ingressClass.Spec.Controller) | ||
| } | ||
|
|
||
| func (r *ApisixPluginConfigReconciler) getIngressClass(pc *apiv2.ApisixPluginConfig) (*networkingv1.IngressClass, error) { | ||
| if pc.Spec.IngressClassName == "" { | ||
| return r.getDefaultIngressClass() | ||
| } | ||
|
|
||
| var ic networkingv1.IngressClass | ||
| if err := r.Get(context.Background(), client.ObjectKey{Name: pc.Spec.IngressClassName}, &ic); err != nil { | ||
| return nil, err | ||
| } | ||
| return &ic, nil | ||
| } | ||
|
|
||
| func (r *ApisixPluginConfigReconciler) getDefaultIngressClass() (*networkingv1.IngressClass, error) { | ||
| var icList networkingv1.IngressClassList | ||
| if err := r.List(context.Background(), &icList); err != nil { | ||
| r.Log.Error(err, "failed to list ingress classes") | ||
| return nil, err | ||
| } | ||
| for _, ic := range icList.Items { | ||
| if IsDefaultIngressClass(&ic) && matchesController(ic.Spec.Controller) { | ||
| return &ic, nil | ||
| } | ||
| } | ||
| return nil, ReasonError{ | ||
| Reason: string(metav1.StatusReasonNotFound), | ||
| Message: "default ingress class not found or does not match the controller", | ||
| } | ||
| } | ||
|
|
||
| // processIngressClassParameters processes the IngressClass parameters that reference GatewayProxy | ||
| func (r *ApisixPluginConfigReconciler) processIngressClassParameters(ctx context.Context, pc *apiv2.ApisixPluginConfig, ingressClass *networkingv1.IngressClass) error { | ||
| if ingressClass == nil || ingressClass.Spec.Parameters == nil { | ||
| return nil | ||
| } | ||
|
|
||
| var ( | ||
| parameters = ingressClass.Spec.Parameters | ||
| ) | ||
| if parameters.APIGroup == nil || *parameters.APIGroup != v1alpha1.GroupVersion.Group || parameters.Kind != KindGatewayProxy { | ||
| return nil | ||
| } | ||
|
|
||
| // check if the parameters reference GatewayProxy | ||
| var ( | ||
| gatewayProxy v1alpha1.GatewayProxy | ||
| ns = parameters.Namespace | ||
| ) | ||
| if ns == nil { | ||
| ns = &pc.Namespace | ||
| } | ||
|
|
||
| return r.Get(ctx, client.ObjectKey{Namespace: *ns, Name: parameters.Name}, &gatewayProxy) | ||
| } | ||
|
|
||
| func (r *ApisixPluginConfigReconciler) updateStatus(pc *apiv2.ApisixPluginConfig, err error) { | ||
| SetApisixCRDConditionAccepted(&pc.Status, pc.GetGeneration(), err) | ||
| r.Updater.Update(status.Update{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,21 +13,14 @@ | |||||||||||
| package controller | ||||||||||||
|
|
||||||||||||
| import ( | ||||||||||||
| "cmp" | ||||||||||||
| "context" | ||||||||||||
|
|
||||||||||||
| "github.com/go-logr/logr" | ||||||||||||
| networkingv1 "k8s.io/api/networking/v1" | ||||||||||||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||||||||
| "k8s.io/apimachinery/pkg/runtime" | ||||||||||||
| ctrl "sigs.k8s.io/controller-runtime" | ||||||||||||
| "sigs.k8s.io/controller-runtime/pkg/builder" | ||||||||||||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||||||||||||
| "sigs.k8s.io/controller-runtime/pkg/handler" | ||||||||||||
| "sigs.k8s.io/controller-runtime/pkg/predicate" | ||||||||||||
| "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||||||||||||
|
|
||||||||||||
| "github.com/apache/apisix-ingress-controller/api/v1alpha1" | ||||||||||||
| apiv2 "github.com/apache/apisix-ingress-controller/api/v2" | ||||||||||||
| "github.com/apache/apisix-ingress-controller/internal/controller/status" | ||||||||||||
| "github.com/apache/apisix-ingress-controller/internal/utils" | ||||||||||||
|
|
@@ -46,15 +39,6 @@ func (r *ApisixUpstreamReconciler) SetupWithManager(mgr ctrl.Manager) error { | |||||||||||
| return ctrl.NewControllerManagedBy(mgr). | ||||||||||||
| For(&apiv2.ApisixUpstream{}). | ||||||||||||
| WithEventFilter(predicate.GenerationChangedPredicate{}). | ||||||||||||
| Watches(&networkingv1.IngressClass{}, | ||||||||||||
| handler.EnqueueRequestsFromMapFunc(r.listApisixUpstreamForIngressClass), | ||||||||||||
| builder.WithPredicates( | ||||||||||||
| predicate.NewPredicateFuncs(r.matchesIngressController), | ||||||||||||
| ), | ||||||||||||
| ). | ||||||||||||
| Watches(&v1alpha1.GatewayProxy{}, | ||||||||||||
| handler.EnqueueRequestsFromMapFunc(r.listApisixUpstreamForGatewayProxy), | ||||||||||||
| ). | ||||||||||||
| Named("apisixupstream"). | ||||||||||||
| Complete(r) | ||||||||||||
| } | ||||||||||||
|
|
@@ -65,119 +49,15 @@ func (r *ApisixUpstreamReconciler) Reconcile(ctx context.Context, req ctrl.Reque | |||||||||||
| return ctrl.Result{}, client.IgnoreNotFound(err) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| var ( | ||||||||||||
| ic *networkingv1.IngressClass | ||||||||||||
| err error | ||||||||||||
| ) | ||||||||||||
| var err error | ||||||||||||
| defer func() { | ||||||||||||
| r.updateStatus(&au, err) | ||||||||||||
|
||||||||||||
| var err error | |
| defer func() { | |
| r.updateStatus(&au, err) | |
| defer func() { | |
| r.updateStatus(&au, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The declared error variable 'err' is never used before Reconcile returns; updateStatus will always treat the operation as successful. Either remove this declaration or wire up actual error propagation.