@@ -32,6 +32,8 @@ import (
3232
3333 "github.com/apache/apisix-ingress-controller/api/v1alpha1"
3434 apiv2 "github.com/apache/apisix-ingress-controller/api/v2"
35+ v2 "github.com/apache/apisix-ingress-controller/api/v2"
36+ "github.com/apache/apisix-ingress-controller/internal/controller/indexer"
3537 "github.com/apache/apisix-ingress-controller/internal/controller/status"
3638 "github.com/apache/apisix-ingress-controller/internal/provider"
3739 "github.com/apache/apisix-ingress-controller/internal/utils"
@@ -70,30 +72,34 @@ func (r *ApisixConsumerReconciler) Reconcile(ctx context.Context, req ctrl.Reque
7072 }
7173
7274 var (
73- tctx = provider .NewDefaultTranslateContext (ctx )
74- err error
75+ tctx = provider .NewDefaultTranslateContext (ctx )
76+ reasonErr error
7577 )
7678 defer func () {
77- r .updateStatus (ac , err )
79+ r .updateStatus (ac , reasonErr )
7880 }()
7981
8082 ingressClass , err := GetIngressClass (tctx , r .Client , r .Log , ac .Spec .IngressClassName )
8183 if err != nil {
8284 r .Log .Error (err , "failed to get IngressClass" )
85+ reasonErr = err
8386 return ctrl.Result {}, err
8487 }
8588
8689 if err := ProcessIngressClassParameters (tctx , r .Client , r .Log , ac , ingressClass ); err != nil {
8790 r .Log .Error (err , "failed to process IngressClass parameters" , "ingressClass" , ingressClass .Name )
91+ reasonErr = err
8892 return ctrl.Result {}, err
8993 }
9094
9195 if err := r .processSpec (ctx , tctx , ac ); err != nil {
96+ reasonErr = err
9297 return ctrl.Result {}, err
9398 }
9499
95100 if err := r .Provider .Update (ctx , tctx , ac ); err != nil {
96101 r .Log .Error (err , "failed to update provider" , "ApisixConsumer" , ac )
102+ reasonErr = err
97103 return ctrl.Result {}, err
98104 }
99105 return ctrl.Result {}, nil
@@ -122,6 +128,9 @@ func (r *ApisixConsumerReconciler) SetupWithManager(mgr ctrl.Manager) error {
122128 Watches (& v1alpha1.GatewayProxy {},
123129 handler .EnqueueRequestsFromMapFunc (r .listApisixConsumerForGatewayProxy ),
124130 ).
131+ Watches (& corev1.Secret {},
132+ handler .EnqueueRequestsFromMapFunc (r .listApisixConsumerForSecret ),
133+ ).
125134 Named ("apisixconsumer" ).
126135 Complete (r )
127136}
@@ -161,6 +170,23 @@ func (r *ApisixConsumerReconciler) listApisixConsumerForIngressClass(ctx context
161170 )
162171}
163172
173+ func (r * ApisixConsumerReconciler ) listApisixConsumerForSecret (ctx context.Context , obj client.Object ) []reconcile.Request {
174+ secret , ok := obj .(* corev1.Secret )
175+ if ! ok {
176+ r .Log .Error (nil , "failed to convert to Secret" , "object" , obj )
177+ return nil
178+ }
179+ return ListRequests (
180+ ctx ,
181+ r .Client ,
182+ r .Log ,
183+ & v2.ApisixConsumerList {},
184+ client.MatchingFields {
185+ indexer .SecretIndexRef : indexer .GenIndexKey (secret .GetNamespace (), secret .GetName ()),
186+ },
187+ )
188+ }
189+
164190func (r * ApisixConsumerReconciler ) processSpec (ctx context.Context , tctx * provider.TranslateContext , ac * apiv2.ApisixConsumer ) error {
165191 var secretRef * corev1.LocalObjectReference
166192 if ac .Spec .AuthParameter .KeyAuth != nil {
@@ -205,11 +231,7 @@ func (r *ApisixConsumerReconciler) updateStatus(consumer *apiv2.ApisixConsumer,
205231 NamespacedName : utils .NamespacedName (consumer ),
206232 Resource : & apiv2.ApisixConsumer {},
207233 Mutator : status .MutatorFunc (func (obj client.Object ) client.Object {
208- ac , ok := obj .(* apiv2.ApisixConsumer )
209- if ! ok {
210- err := fmt .Errorf ("unsupported object type %T" , obj )
211- panic (err )
212- }
234+ ac := obj .(* apiv2.ApisixConsumer )
213235 acCopy := ac .DeepCopy ()
214236 acCopy .Status = consumer .Status
215237 return acCopy
0 commit comments