mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2026-05-05 14:46:10 +02:00
ingress source: ingressClassNames now feed into annotation filter
This commit is contained in:
parent
71a672fe72
commit
901effbca5
@ -27,6 +27,7 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
networkv1 "k8s.io/api/networking/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/selection"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
kubeinformers "k8s.io/client-go/informers"
|
||||
netinformers "k8s.io/client-go/informers/networking/v1"
|
||||
@ -241,24 +242,34 @@ func (sc *ingressSource) filterByIngressClass(ingresses []*networkv1.Ingress) ([
|
||||
return ingresses, nil
|
||||
}
|
||||
|
||||
classNameReq, err := labels.NewRequirement("kubernetes.io/ingress.class", selection.In, sc.ingressClassNames)
|
||||
if err != nil {
|
||||
return nil, errors.New("Failed to create selector requirement from ingress class names")
|
||||
}
|
||||
|
||||
selector := labels.NewSelector()
|
||||
selector = selector.Add(*classNameReq)
|
||||
|
||||
filteredList := []*networkv1.Ingress{}
|
||||
|
||||
for _, ingress := range ingresses {
|
||||
// we have a filter class but this ingress doesn't have its class set
|
||||
if ingress.Spec.IngressClassName == nil {
|
||||
log.Debugf("Ignoring ingress %s/%s because ingressClassName is not set", ingress.Namespace, ingress.Name)
|
||||
}
|
||||
|
||||
var matched = false;
|
||||
|
||||
for _, nameFilter := range sc.ingressClassNames {
|
||||
if nameFilter == *ingress.Spec.IngressClassName {
|
||||
filteredList = append(filteredList, ingress)
|
||||
if ingress.Spec.IngressClassName != nil && nameFilter == *ingress.Spec.IngressClassName {
|
||||
matched = true;
|
||||
} else if matchLabelSelector(selector, ingress.Annotations) {
|
||||
matched = true;
|
||||
}
|
||||
|
||||
if matched == true {
|
||||
filteredList = append(filteredList, ingress)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if matched == false {
|
||||
log.Debugf("Ignoring ingress %s/%s because ingressClassName '%s' is not in specified list", ingress.Namespace, ingress.Name, *ingress.Spec.IngressClassName)
|
||||
log.Debugf("Discarding ingress %s/%s because it does not match required ingress classes %v", ingress.Namespace, ingress.Name, sc.ingressClassNames)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1198,6 +1198,15 @@ func testIngressEndpoints(t *testing.T) {
|
||||
ips: []string{"3.4.5.6"},
|
||||
ingressClassName: "dmz",
|
||||
},
|
||||
{
|
||||
name: "annotated-dmz",
|
||||
namespace: namespace,
|
||||
tlsdnsnames: [][]string{{"annodmz.example.org"}},
|
||||
ips: []string{"4.5.6.7"},
|
||||
annotations: map[string]string{
|
||||
"kubernetes.io/ingress.class": "dmz",
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: []*endpoint.Endpoint{
|
||||
{
|
||||
@ -1208,6 +1217,10 @@ func testIngressEndpoints(t *testing.T) {
|
||||
DNSName: "dmz.example.org",
|
||||
Targets: endpoint.Targets{"3.4.5.6"},
|
||||
},
|
||||
{
|
||||
DNSName: "annodmz.example.org",
|
||||
Targets: endpoint.Targets{"4.5.6.7"},
|
||||
},
|
||||
},
|
||||
},
|
||||
} {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user