Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubernetes v1.22: Update controller to use networking.k8s.io/v1 Ingress. #2281

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions docs/tutorials/ultradns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_route53_k8s_txt_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
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:
Expand Down
22 changes: 11 additions & 11 deletions source/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -57,7 +57,7 @@ type ingressSource struct {
fqdnTemplate *template.Template
combineFQDNAnnotation bool
ignoreHostnameAnnotation bool
ingressInformer extinformers.IngressInformer
ingressInformer netinformers.IngressInformer
ignoreIngressTLSSpec bool
ignoreIngressRulesSpec bool
}
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions source/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -37,7 +37,7 @@ var _ Source = &ingressSource{}
type IngressSuite struct {
suite.Suite
sc Source
fooWithTargets *v1beta1.Ingress
fooWithTargets *networkv1.Ingress
}

func (suite *IngressSuite) SetupTest() {
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
})
}
Expand Down