From 8a93be8c6a153b0cca11339d2e1244c7f2779849 Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 2 Nov 2023 14:32:38 +0000 Subject: [PATCH] Don't throw annotation deprication warning when `ingressClassName` is not used in an Ingress resource (#4564) Signed-off-by: Shaun --- internal/k8s/controller.go | 2 +- internal/k8s/controller_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/k8s/controller.go b/internal/k8s/controller.go index 19d6e3f5f3..e38efa699b 100644 --- a/internal/k8s/controller.go +++ b/internal/k8s/controller.go @@ -3980,7 +3980,7 @@ func (lbc *LoadBalancerController) HasCorrectIngressClass(obj interface{}) bool class = obj.Annotations[ingressClassKey] if class == "" && obj.Spec.IngressClassName != nil { class = *obj.Spec.IngressClassName - } else { + } else if class != "" { // the annotation takes precedence over the field glog.Warningln("Using the DEPRECATED annotation 'kubernetes.io/ingress.class'. The 'ingressClassName' field will be ignored.") } diff --git a/internal/k8s/controller_test.go b/internal/k8s/controller_test.go index 3d57c9d9bd..4a30de2aa7 100644 --- a/internal/k8s/controller_test.go +++ b/internal/k8s/controller_test.go @@ -139,6 +139,16 @@ func TestHasCorrectIngressClass(t *testing.T) { }, true, }, + { + &LoadBalancerController{ + ingressClass: ingressClass, + metricsCollector: collectors.NewControllerFakeCollector(), + }, + &networking.Ingress{ + Spec: networking.IngressSpec{}, + }, + false, + }, } for _, test := range tests {