diff --git a/source/ingress.go b/source/ingress.go index bf204a266..af7a9dc99 100644 --- a/source/ingress.go +++ b/source/ingress.go @@ -258,9 +258,10 @@ func (sc *ingressSource) filterByIngressClass(ingresses []*networkv1.Ingress) ([ var matched = false for _, nameFilter := range sc.ingressClassNames { - if ingress.Spec.IngressClassName != nil && nameFilter == *ingress.Spec.IngressClassName { - matched = true - + if ingress.Spec.IngressClassName != nil && len(*ingress.Spec.IngressClassName) > 0 { + if nameFilter == *ingress.Spec.IngressClassName { + matched = true + } } else if matchLabelSelector(selector, ingress.Annotations) { matched = true } diff --git a/source/ingress_test.go b/source/ingress_test.go index b76dd439a..2be3eddfd 100644 --- a/source/ingress_test.go +++ b/source/ingress_test.go @@ -1282,7 +1282,7 @@ func testIngressEndpoints(t *testing.T) { tlsdnsnames: [][]string{{"int-annodmz.example.org"}}, ips: []string{"5.6.7.8"}, annotations: map[string]string{ - "kubernetes.io/ingress.class": "dmz", // match + "kubernetes.io/ingress.class": "dmz", // match but ignored (non-empty ingressClassName) }, ingressClassName: "internal", }, @@ -1302,7 +1302,7 @@ func testIngressEndpoints(t *testing.T) { tlsdnsnames: [][]string{{"empty-annotdmz.example.org"}}, ips: []string{"7.8.9.0"}, annotations: map[string]string{ - "kubernetes.io/ingress.class": "dmz", // match + "kubernetes.io/ingress.class": "dmz", // match (empty ingressClassName) }, ingressClassName: "", }, @@ -1333,11 +1333,6 @@ func testIngressEndpoints(t *testing.T) { RecordType: endpoint.RecordTypeA, Targets: endpoint.Targets{"4.5.6.7"}, }, - { - DNSName: "int-annodmz.example.org", - RecordType: endpoint.RecordTypeA, - Targets: endpoint.Targets{"5.6.7.8"}, - }, { DNSName: "dmz-annoint.example.org", RecordType: endpoint.RecordTypeA,