Skip to content

Commit

Permalink
fix: Nginx ingressClassName passed to canary ingress (#1448)
Browse files Browse the repository at this point in the history
* fix: nginx ingressClassName passed to canary ingress

Signed-off-by: khhirani <kareena.hirani@gmail.com>
  • Loading branch information
khhirani authored and alexmt committed Aug 26, 2021
1 parent 58994c9 commit 980a56d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rollout/trafficrouting/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions rollout/trafficrouting/nginx/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -94,13 +96,16 @@ 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")

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) {
Expand Down

0 comments on commit 980a56d

Please sign in to comment.