From 980a56d3e6e1d5f79a513af2e1dc412463d2fd32 Mon Sep 17 00:00:00 2001 From: Kareena Hirani Date: Wed, 25 Aug 2021 13:34:24 -0700 Subject: [PATCH] fix: Nginx ingressClassName passed to canary ingress (#1448) * fix: nginx ingressClassName passed to canary ingress Signed-off-by: khhirani --- rollout/trafficrouting/nginx/nginx.go | 5 +++++ rollout/trafficrouting/nginx/nginx_test.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/rollout/trafficrouting/nginx/nginx.go b/rollout/trafficrouting/nginx/nginx.go index ed9e95ac2b..85e49a421c 100644 --- a/rollout/trafficrouting/nginx/nginx.go +++ b/rollout/trafficrouting/nginx/nginx.go @@ -72,6 +72,11 @@ func (r *Reconciler) canaryIngress(stableIngress *extensionsv1beta1.Ingress, nam }, } + // Preserve ingressClassName from stable ingress + if stableIngress.Spec.IngressClassName != nil { + desiredCanaryIngress.Spec.IngressClassName = stableIngress.Spec.IngressClassName + } + // Must preserve ingress.class on canary ingress, no other annotations matter // See: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#canary if val, ok := stableIngress.Annotations["kubernetes.io/ingress.class"]; ok { diff --git a/rollout/trafficrouting/nginx/nginx_test.go b/rollout/trafficrouting/nginx/nginx_test.go index a747e34835..04349bba42 100644 --- a/rollout/trafficrouting/nginx/nginx_test.go +++ b/rollout/trafficrouting/nginx/nginx_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "k8s.io/utils/pointer" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" @@ -94,6 +96,7 @@ func TestCanaryIngressCreate(t *testing.T) { }, } stableIngress := ingress("stable-ingress", 80, "stable-service") + stableIngress.Spec.IngressClassName = pointer.StringPtr("nginx-ext") desiredCanaryIngress, err := r.canaryIngress(stableIngress, ingressutil.GetCanaryIngressName(r.cfg.Rollout), 10) assert.Nil(t, err, "No error returned when calling canaryIngress") @@ -101,6 +104,8 @@ func TestCanaryIngressCreate(t *testing.T) { checkBackendService(t, desiredCanaryIngress, "canary-service") assert.Equal(t, "true", desiredCanaryIngress.Annotations["nginx.ingress.kubernetes.io/canary"], "canary annotation set to true") assert.Equal(t, "10", desiredCanaryIngress.Annotations["nginx.ingress.kubernetes.io/canary-weight"], "canary-weight annotation set to expected value") + assert.NotNil(t, desiredCanaryIngress.Spec.IngressClassName) + assert.Equal(t, "nginx-ext", *desiredCanaryIngress.Spec.IngressClassName) } func TestCanaryIngressPatchWeight(t *testing.T) {