@@ -70,7 +70,7 @@ func (r *IngressReconciler) SetupWithManager(mgr ctrl.Manager) error {
7070 return ctrl .NewControllerManagedBy (mgr ).
7171 For (& networkingv1.Ingress {},
7272 builder .WithPredicates (
73- predicate . NewPredicateFuncs (r .checkIngressClass ),
73+ MatchesIngressClassPredicate (r .Client , r . Log ),
7474 ),
7575 ).
7676 WithEventFilter (
@@ -151,10 +151,13 @@ func (r *IngressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
151151 // create a translate context
152152 tctx := provider .NewDefaultTranslateContext (ctx )
153153
154- ingressClass , err := r . getIngressClass ( ctx , ingress )
154+ ingressClass , err := FindMatchingIngressClass ( tctx , r . Client , r . Log , ingress )
155155 if err != nil {
156- r .Log .Error (err , "failed to get IngressClass" )
157- return ctrl.Result {}, err
156+ if err := r .Provider .Delete (ctx , ingress ); err != nil {
157+ r .Log .Error (err , "failed to delete ingress resources" , "ingress" , ingress .Name )
158+ return ctrl.Result {}, nil
159+ }
160+ return ctrl.Result {}, nil
158161 }
159162
160163 tctx .RouteParentRefs = append (tctx .RouteParentRefs , gatewayv1.ParentReference {
@@ -207,22 +210,6 @@ func (r *IngressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
207210 return ctrl.Result {}, nil
208211}
209212
210- // getIngressClass get the ingress class for the ingress
211- func (r * IngressReconciler ) getIngressClass (ctx context.Context , obj client.Object ) (* networkingv1.IngressClass , error ) {
212- ingress := obj .(* networkingv1.Ingress )
213- var ingressClassName string
214- if ingress .Spec .IngressClassName != nil {
215- ingressClassName = * ingress .Spec .IngressClassName
216- }
217- return GetIngressClass (ctx , r .Client , r .Log , ingressClassName )
218- }
219-
220- // checkIngressClass check if the ingress uses the ingress class that we control
221- func (r * IngressReconciler ) checkIngressClass (obj client.Object ) bool {
222- _ , err := r .getIngressClass (context .Background (), obj )
223- return err == nil
224- }
225-
226213// matchesIngressController check if the ingress class is controlled by us
227214func (r * IngressReconciler ) matchesIngressController (obj client.Object ) bool {
228215 ingressClass , ok := obj .(* networkingv1.IngressClass )
@@ -307,7 +294,7 @@ func (r *IngressReconciler) listIngressesByService(ctx context.Context, obj clie
307294
308295 requests := make ([]reconcile.Request , 0 , len (ingressList .Items ))
309296 for _ , ingress := range ingressList .Items {
310- if r . checkIngressClass ( & ingress ) {
297+ if MatchesIngressClass ( r . Client , r . Log , & ingress ) {
311298 requests = append (requests , reconcile.Request {
312299 NamespacedName : client.ObjectKey {
313300 Namespace : ingress .Namespace ,
@@ -340,7 +327,7 @@ func (r *IngressReconciler) listIngressesBySecret(ctx context.Context, obj clien
340327
341328 requests := make ([]reconcile.Request , 0 , len (ingressList .Items ))
342329 for _ , ingress := range ingressList .Items {
343- if r . checkIngressClass ( & ingress ) {
330+ if MatchesIngressClass ( r . Client , r . Log , & ingress ) {
344331 requests = append (requests , reconcile.Request {
345332 NamespacedName : client.ObjectKey {
346333 Namespace : ingress .Namespace ,
0 commit comments