From 0e27f41fa0457e105b591e76c0d6f57bcb23bc74 Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Wed, 8 Sep 2021 09:29:05 -0700 Subject: [PATCH] Update external-dns to use v1 ingress --- docs/tutorials/ultradns.md | 55 ++++++++++++++++--------- scripts/update_route53_k8s_txt_owner.py | 2 +- source/ingress.go | 22 +++++----- source/ingress_test.go | 22 +++++----- 4 files changed, 58 insertions(+), 43 deletions(-) diff --git a/docs/tutorials/ultradns.md b/docs/tutorials/ultradns.md index 7b7312553..5f37093c5 100644 --- a/docs/tutorials/ultradns.md +++ b/docs/tutorials/ultradns.md @@ -237,7 +237,7 @@ spec: ``` - Then, create service file called 'expose-apple-banana-app.yaml' to expose the services. For more information to deploy ingress controller, refer to (https://kubernetes.github.io/ingress-nginx/deploy/) ```yaml -apiVersion: extensions/v1beta1 +apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress @@ -252,8 +252,10 @@ spec: paths: - path: /apple backend: - serviceName: example-service - servicePort: 5678 + service: + name: example-service + port: + number: 5678 ``` - Then, create the deployment and service: ```console @@ -298,7 +300,7 @@ $ kubectl delete -f external-dns.yaml ports: - port: 5678 # Default port for image --- - apiVersion: extensions/v1beta1 + apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress @@ -313,8 +315,10 @@ $ kubectl delete -f external-dns.yaml paths: - path: /apple backend: - serviceName: example-service - servicePort: 5678 + service: + name: example-service + port: + number: 5678 ``` - _Config File Example – Kubernetes cluster service from different cloud vendors_ ```yaml @@ -434,7 +438,7 @@ $ kubectl delete -f external-dns.yaml ports: - port: 5680 # Default port for image --- - apiVersion: extensions/v1beta1 + apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress @@ -449,10 +453,12 @@ $ kubectl delete -f external-dns.yaml paths: - path: /apple backend: - serviceName: example-service - servicePort: 5678 + service: + name: example-service + port: + number: 5678 --- - apiVersion: extensions/v1beta1 + apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress1 @@ -467,10 +473,12 @@ $ kubectl delete -f external-dns.yaml paths: - path: /apple backend: - serviceName: example-service1 - servicePort: 5679 + service: + name: example-service1 + port: + number: 5679 --- - apiVersion: extensions/v1beta1 + apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress2 @@ -485,8 +493,10 @@ $ kubectl delete -f external-dns.yaml paths: - path: /apple backend: - serviceName: example-service2 - servicePort: 5680 + service: + name: example-service2 + port: + number: 5680 ``` - _Config File Example – Kubernetes cluster service from different cloud vendors_ ```yaml @@ -572,6 +582,7 @@ $ kubectl delete -f external-dns.yaml ports: - port: 5679 # Default port for image --- + apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress @@ -586,10 +597,12 @@ $ kubectl delete -f external-dns.yaml paths: - path: /apple backend: - serviceName: example-service - servicePort: 5678 + service: + name: example-service + port: + number: 5678 --- - apiVersion: extensions/v1beta1 + apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress1 @@ -604,8 +617,10 @@ $ kubectl delete -f external-dns.yaml paths: - path: /apple backend: - serviceName: example-service1 - servicePort: 5679 + service: + name: example-service1 + port: + number: 5679 ``` - Then, create the deployment and service: ```console diff --git a/scripts/update_route53_k8s_txt_owner.py b/scripts/update_route53_k8s_txt_owner.py index ceb1afb31..e81c9025c 100644 --- a/scripts/update_route53_k8s_txt_owner.py +++ b/scripts/update_route53_k8s_txt_owner.py @@ -54,7 +54,7 @@ if external_dns_manages_services: k8s_domains.extend(annotations['domainName'].split(',')) if external_dns_manages_ingresses: - ev1 = client.ExtensionsV1beta1Api() + ev1 = client.NetworkingV1Api() ings = ev1.list_ingress_for_all_namespaces() for i in ings.items: for r in i.spec.rules: diff --git a/source/ingress.go b/source/ingress.go index 08c93b34d..e81f524d1 100644 --- a/source/ingress.go +++ b/source/ingress.go @@ -24,11 +24,11 @@ import ( "text/template" log "github.com/sirupsen/logrus" - "k8s.io/api/extensions/v1beta1" + networkv1 "k8s.io/api/networking/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/wait" kubeinformers "k8s.io/client-go/informers" - extinformers "k8s.io/client-go/informers/extensions/v1beta1" + netinformers "k8s.io/client-go/informers/networking/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" @@ -57,7 +57,7 @@ type ingressSource struct { fqdnTemplate *template.Template combineFQDNAnnotation bool ignoreHostnameAnnotation bool - ingressInformer extinformers.IngressInformer + ingressInformer netinformers.IngressInformer ignoreIngressTLSSpec bool ignoreIngressRulesSpec bool } @@ -72,7 +72,7 @@ func NewIngressSource(kubeClient kubernetes.Interface, namespace, annotationFilt // Use shared informer to listen for add/update/delete of ingresses in the specified namespace. // Set resync period to 0, to prevent processing when nothing has changed. informerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClient, 0, kubeinformers.WithNamespace(namespace)) - ingressInformer := informerFactory.Extensions().V1beta1().Ingresses() + ingressInformer := informerFactory.Networking().V1().Ingresses() // Add default resource event handlers to properly initialize informer. ingressInformer.Informer().AddEventHandler( @@ -161,7 +161,7 @@ func (sc *ingressSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e return endpoints, nil } -func (sc *ingressSource) endpointsFromTemplate(ing *v1beta1.Ingress) ([]*endpoint.Endpoint, error) { +func (sc *ingressSource) endpointsFromTemplate(ing *networkv1.Ingress) ([]*endpoint.Endpoint, error) { hostnames, err := execTemplate(sc.fqdnTemplate, ing) if err != nil { return nil, err @@ -187,7 +187,7 @@ func (sc *ingressSource) endpointsFromTemplate(ing *v1beta1.Ingress) ([]*endpoin } // filterByAnnotations filters a list of ingresses by a given annotation selector. -func (sc *ingressSource) filterByAnnotations(ingresses []*v1beta1.Ingress) ([]*v1beta1.Ingress, error) { +func (sc *ingressSource) filterByAnnotations(ingresses []*networkv1.Ingress) ([]*networkv1.Ingress, error) { selector, err := getLabelSelector(sc.annotationFilter) if err != nil { return nil, err @@ -198,7 +198,7 @@ func (sc *ingressSource) filterByAnnotations(ingresses []*v1beta1.Ingress) ([]*v return ingresses, nil } - filteredList := []*v1beta1.Ingress{} + filteredList := []*networkv1.Ingress{} for _, ingress := range ingresses { // include ingress if its annotations match the selector @@ -210,13 +210,13 @@ func (sc *ingressSource) filterByAnnotations(ingresses []*v1beta1.Ingress) ([]*v return filteredList, nil } -func (sc *ingressSource) setResourceLabel(ingress *v1beta1.Ingress, endpoints []*endpoint.Endpoint) { +func (sc *ingressSource) setResourceLabel(ingress *networkv1.Ingress, endpoints []*endpoint.Endpoint) { for _, ep := range endpoints { ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("ingress/%s/%s", ingress.Namespace, ingress.Name) } } -func (sc *ingressSource) setDualstackLabel(ingress *v1beta1.Ingress, endpoints []*endpoint.Endpoint) { +func (sc *ingressSource) setDualstackLabel(ingress *networkv1.Ingress, endpoints []*endpoint.Endpoint) { val, ok := ingress.Annotations[ALBDualstackAnnotationKey] if ok && val == ALBDualstackAnnotationValue { log.Debugf("Adding dualstack label to ingress %s/%s.", ingress.Namespace, ingress.Name) @@ -227,7 +227,7 @@ func (sc *ingressSource) setDualstackLabel(ingress *v1beta1.Ingress, endpoints [ } // endpointsFromIngress extracts the endpoints from ingress object -func endpointsFromIngress(ing *v1beta1.Ingress, ignoreHostnameAnnotation bool, ignoreIngressTLSSpec bool, ignoreIngressRulesSpec bool) []*endpoint.Endpoint { +func endpointsFromIngress(ing *networkv1.Ingress, ignoreHostnameAnnotation bool, ignoreIngressTLSSpec bool, ignoreIngressRulesSpec bool) []*endpoint.Endpoint { ttl, err := getTTLFromAnnotations(ing.Annotations) if err != nil { log.Warn(err) @@ -290,7 +290,7 @@ func endpointsFromIngress(ing *v1beta1.Ingress, ignoreHostnameAnnotation bool, i return endpoints } -func targetsFromIngressStatus(status v1beta1.IngressStatus) endpoint.Targets { +func targetsFromIngressStatus(status networkv1.IngressStatus) endpoint.Targets { var targets endpoint.Targets for _, lb := range status.LoadBalancer.Ingress { diff --git a/source/ingress_test.go b/source/ingress_test.go index cccf2ca13..c9d35494c 100644 --- a/source/ingress_test.go +++ b/source/ingress_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + networkv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" @@ -37,7 +37,7 @@ var _ Source = &ingressSource{} type IngressSuite struct { suite.Suite sc Source - fooWithTargets *v1beta1.Ingress + fooWithTargets *networkv1.Ingress } func (suite *IngressSuite) SetupTest() { @@ -51,7 +51,7 @@ func (suite *IngressSuite) SetupTest() { hostnames: []string{"v1"}, annotations: map[string]string{ALBDualstackAnnotationKey: ALBDualstackAnnotationValue}, }).Ingress() - _, err := fakeClient.ExtensionsV1beta1().Ingresses(suite.fooWithTargets.Namespace).Create(context.Background(), suite.fooWithTargets, metav1.CreateOptions{}) + _, err := fakeClient.NetworkingV1().Ingresses(suite.fooWithTargets.Namespace).Create(context.Background(), suite.fooWithTargets, metav1.CreateOptions{}) suite.NoError(err, "should succeed") suite.sc, err = NewIngressSource( @@ -1177,7 +1177,7 @@ func testIngressEndpoints(t *testing.T) { fakeClient := fake.NewSimpleClientset() for _, item := range ti.ingressItems { ingress := item.Ingress() - _, err := fakeClient.ExtensionsV1beta1().Ingresses(ingress.Namespace).Create(context.Background(), ingress, metav1.CreateOptions{}) + _, err := fakeClient.NetworkingV1().Ingresses(ingress.Namespace).Create(context.Background(), ingress, metav1.CreateOptions{}) require.NoError(t, err) } source, _ := NewIngressSource( @@ -1213,29 +1213,29 @@ type fakeIngress struct { annotations map[string]string } -func (ing fakeIngress) Ingress() *v1beta1.Ingress { - ingress := &v1beta1.Ingress{ +func (ing fakeIngress) Ingress() *networkv1.Ingress { + ingress := &networkv1.Ingress{ ObjectMeta: metav1.ObjectMeta{ Namespace: ing.namespace, Name: ing.name, Annotations: ing.annotations, }, - Spec: v1beta1.IngressSpec{ - Rules: []v1beta1.IngressRule{}, + Spec: networkv1.IngressSpec{ + Rules: []networkv1.IngressRule{}, }, - Status: v1beta1.IngressStatus{ + Status: networkv1.IngressStatus{ LoadBalancer: v1.LoadBalancerStatus{ Ingress: []v1.LoadBalancerIngress{}, }, }, } for _, dnsname := range ing.dnsnames { - ingress.Spec.Rules = append(ingress.Spec.Rules, v1beta1.IngressRule{ + ingress.Spec.Rules = append(ingress.Spec.Rules, networkv1.IngressRule{ Host: dnsname, }) } for _, hosts := range ing.tlsdnsnames { - ingress.Spec.TLS = append(ingress.Spec.TLS, v1beta1.IngressTLS{ + ingress.Spec.TLS = append(ingress.Spec.TLS, networkv1.IngressTLS{ Hosts: hosts, }) }