@@ -17,17 +17,11 @@ import (
1717 "fmt"
1818
1919 "github.com/go-logr/logr"
20- networkingv1 "k8s.io/api/networking/v1"
21- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2220 "k8s.io/apimachinery/pkg/runtime"
2321 ctrl "sigs.k8s.io/controller-runtime"
24- "sigs.k8s.io/controller-runtime/pkg/builder"
2522 "sigs.k8s.io/controller-runtime/pkg/client"
26- "sigs.k8s.io/controller-runtime/pkg/handler"
2723 "sigs.k8s.io/controller-runtime/pkg/predicate"
28- "sigs.k8s.io/controller-runtime/pkg/reconcile"
2924
30- "github.com/apache/apisix-ingress-controller/api/v1alpha1"
3125 apiv2 "github.com/apache/apisix-ingress-controller/api/v2"
3226 "github.com/apache/apisix-ingress-controller/internal/controller/status"
3327 "github.com/apache/apisix-ingress-controller/internal/utils"
@@ -46,15 +40,6 @@ func (r *ApisixPluginConfigReconciler) SetupWithManager(mgr ctrl.Manager) error
4640 return ctrl .NewControllerManagedBy (mgr ).
4741 For (& apiv2.ApisixPluginConfig {}).
4842 WithEventFilter (predicate.GenerationChangedPredicate {}).
49- Watches (& networkingv1.IngressClass {},
50- handler .EnqueueRequestsFromMapFunc (r .listApisixPluginConfigForIngressClass ),
51- builder .WithPredicates (
52- predicate .NewPredicateFuncs (r .matchesIngressController ),
53- ),
54- ).
55- Watches (& v1alpha1.GatewayProxy {},
56- handler .EnqueueRequestsFromMapFunc (r .listApisixPluginConfigForGatewayProxy ),
57- ).
5843 Named ("apisixpluginconfig" ).
5944 Complete (r )
6045}
@@ -65,123 +50,11 @@ func (r *ApisixPluginConfigReconciler) Reconcile(ctx context.Context, req ctrl.R
6550 return ctrl.Result {}, client .IgnoreNotFound (err )
6651 }
6752
68- var (
69- ic * networkingv1.IngressClass
70- err error
71- )
72- defer func () {
73- r .updateStatus (& pc , err )
74- }()
75-
76- if ic , err = r .getIngressClass (& pc ); err != nil {
77- return ctrl.Result {}, err
78- }
79- if err = r .processIngressClassParameters (ctx , & pc , ic ); err != nil {
80- return ctrl.Result {}, err
81- }
53+ // Only update status
54+ r .updateStatus (& pc , nil )
8255 return ctrl.Result {}, nil
8356}
8457
85- func (r * ApisixPluginConfigReconciler ) listApisixPluginConfigForIngressClass (ctx context.Context , object client.Object ) (requests []reconcile.Request ) {
86- ic , ok := object .(* networkingv1.IngressClass )
87- if ! ok {
88- return nil
89- }
90-
91- isDefaultIngressClass := IsDefaultIngressClass (ic )
92- var pcList apiv2.ApisixPluginConfigList
93- if err := r .List (ctx , & pcList ); err != nil {
94- return nil
95- }
96- for _ , pc := range pcList .Items {
97- if pc .Spec .IngressClassName == ic .Name || (isDefaultIngressClass && pc .Spec .IngressClassName == "" ) {
98- requests = append (requests , reconcile.Request {NamespacedName : utils .NamespacedName (& pc )})
99- }
100- }
101- return requests
102- }
103-
104- func (r * ApisixPluginConfigReconciler ) listApisixPluginConfigForGatewayProxy (ctx context.Context , object client.Object ) (requests []reconcile.Request ) {
105- gp , ok := object .(* v1alpha1.GatewayProxy )
106- if ! ok {
107- return nil
108- }
109-
110- var icList networkingv1.IngressClassList
111- if err := r .List (ctx , & icList ); err != nil {
112- r .Log .Error (err , "failed to list ingress classes for gateway proxy" , "gatewayproxy" , gp .GetName ())
113- return nil
114- }
115-
116- for _ , ic := range icList .Items {
117- requests = append (requests , r .listApisixPluginConfigForIngressClass (ctx , & ic )... )
118- }
119-
120- return requests
121- }
122-
123- func (r * ApisixPluginConfigReconciler ) matchesIngressController (obj client.Object ) bool {
124- ingressClass , ok := obj .(* networkingv1.IngressClass )
125- if ! ok {
126- return false
127- }
128- return matchesController (ingressClass .Spec .Controller )
129- }
130-
131- func (r * ApisixPluginConfigReconciler ) getIngressClass (pc * apiv2.ApisixPluginConfig ) (* networkingv1.IngressClass , error ) {
132- if pc .Spec .IngressClassName == "" {
133- return r .getDefaultIngressClass ()
134- }
135-
136- var ic networkingv1.IngressClass
137- if err := r .Get (context .Background (), client.ObjectKey {Name : pc .Spec .IngressClassName }, & ic ); err != nil {
138- return nil , err
139- }
140- return & ic , nil
141- }
142-
143- func (r * ApisixPluginConfigReconciler ) getDefaultIngressClass () (* networkingv1.IngressClass , error ) {
144- var icList networkingv1.IngressClassList
145- if err := r .List (context .Background (), & icList ); err != nil {
146- r .Log .Error (err , "failed to list ingress classes" )
147- return nil , err
148- }
149- for _ , ic := range icList .Items {
150- if IsDefaultIngressClass (& ic ) && matchesController (ic .Spec .Controller ) {
151- return & ic , nil
152- }
153- }
154- return nil , ReasonError {
155- Reason : string (metav1 .StatusReasonNotFound ),
156- Message : "default ingress class not found or does not match the controller" ,
157- }
158- }
159-
160- // processIngressClassParameters processes the IngressClass parameters that reference GatewayProxy
161- func (r * ApisixPluginConfigReconciler ) processIngressClassParameters (ctx context.Context , pc * apiv2.ApisixPluginConfig , ingressClass * networkingv1.IngressClass ) error {
162- if ingressClass == nil || ingressClass .Spec .Parameters == nil {
163- return nil
164- }
165-
166- var (
167- parameters = ingressClass .Spec .Parameters
168- )
169- if parameters .APIGroup == nil || * parameters .APIGroup != v1alpha1 .GroupVersion .Group || parameters .Kind != KindGatewayProxy {
170- return nil
171- }
172-
173- // check if the parameters reference GatewayProxy
174- var (
175- gatewayProxy v1alpha1.GatewayProxy
176- ns = parameters .Namespace
177- )
178- if ns == nil {
179- ns = & pc .Namespace
180- }
181-
182- return r .Get (ctx , client.ObjectKey {Namespace : * ns , Name : parameters .Name }, & gatewayProxy )
183- }
184-
18558func (r * ApisixPluginConfigReconciler ) updateStatus (pc * apiv2.ApisixPluginConfig , err error ) {
18659 SetApisixCRDConditionAccepted (& pc .Status , pc .GetGeneration (), err )
18760 r .Updater .Update (status.Update {
0 commit comments