ingress: ignore annotation when ingressclassname is non empty

This commit is contained in:
Arnaud Lefray 2023-05-05 16:08:04 +02:00
parent e3842a4be6
commit 42077cd35a
No known key found for this signature in database
GPG Key ID: 1049DFCA2DCF465D
2 changed files with 6 additions and 10 deletions

View File

@ -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
}

View File

@ -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,