From e926486b0fc6e34f1a7caa2c8125618312d3a07b Mon Sep 17 00:00:00 2001 From: Iaroslav Vorozhko Date: Thu, 13 May 2021 14:27:32 +0200 Subject: [PATCH 1/3] Stop canary traffic after canary promotion Signed-off-by: Iaroslav Vorozhko --- pkg/router/ingress.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/router/ingress.go b/pkg/router/ingress.go index d53594d1..c6f4047a 100644 --- a/pkg/router/ingress.go +++ b/pkg/router/ingress.go @@ -213,12 +213,18 @@ func (i *IngressRouter) makeAnnotations(annotations map[string]string) map[strin res := make(map[string]string) for k, v := range annotations { if !strings.Contains(k, i.GetAnnotationWithPrefix("canary")) && - !strings.Contains(k, "kubectl.kubernetes.io/last-applied-configuration") { + !strings.Contains(k, "kubectl.kubernetes.io/last-applied-configuration") && + !strings.Contains(k, i.GetAnnotationWithPrefix("canary-weight")) && + !strings.Contains(k, i.GetAnnotationWithPrefix("canary-by-cookie")) && + !strings.Contains(k, i.GetAnnotationWithPrefix("canary-by-header")) && + !strings.Contains(k, i.GetAnnotationWithPrefix("canary-by-header-value")) && + !strings.Contains(k, i.GetAnnotationWithPrefix("canary-by-header-pattern")) { res[k] = v } } - res[i.GetAnnotationWithPrefix("canary")] = "false" + res[i.GetAnnotationWithPrefix("canary")] = "true" + res[i.GetAnnotationWithPrefix("canary-weight")] = "0" return res } From 41481c1ca8b58cbe29710c1fc4858543c6784e3f Mon Sep 17 00:00:00 2001 From: Iaroslav Vorozhko Date: Thu, 13 May 2021 14:38:41 +0200 Subject: [PATCH 2/3] Adjusted tests to new behaviour on init and promotion Signed-off-by: Iaroslav Vorozhko --- pkg/router/ingress_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/router/ingress_test.go b/pkg/router/ingress_test.go index 81d24d27..f327406a 100644 --- a/pkg/router/ingress_test.go +++ b/pkg/router/ingress_test.go @@ -42,13 +42,15 @@ func TestIngressRouter_Reconcile(t *testing.T) { require.NoError(t, err) canaryAn := "custom.ingress.kubernetes.io/canary" + canaryWeightAn := "custom.ingress.kubernetes.io/canary-weight" canaryName := fmt.Sprintf("%s-canary", mocks.ingressCanary.Spec.IngressRef.Name) inCanary, err := router.kubeClient.NetworkingV1beta1().Ingresses("default").Get(context.TODO(), canaryName, metav1.GetOptions{}) require.NoError(t, err) // test initialisation - assert.Equal(t, "false", inCanary.Annotations[canaryAn]) + assert.Equal(t, "true", inCanary.Annotations[canaryAn]) + assert.Equal(t, "0", inCanary.Annotations[canaryWeightAn]) } func TestIngressRouter_GetSetRoutes(t *testing.T) { @@ -94,7 +96,8 @@ func TestIngressRouter_GetSetRoutes(t *testing.T) { require.NoError(t, err) // test promotion - assert.Equal(t, "false", inCanary.Annotations[canaryAn]) + assert.Equal(t, "true", inCanary.Annotations[canaryAn]) + assert.Equal(t, "0", inCanary.Annotations[canaryWeightAn]) } func TestIngressRouter_ABTest(t *testing.T) { From d7999e662742c963f69ec4f3dacf5668bdb957ed Mon Sep 17 00:00:00 2001 From: Iaroslav Vorozhko Date: Fri, 14 May 2021 12:23:32 +0200 Subject: [PATCH 3/3] Added e2e test to check nginx update pass witth nginx validation webhook after canary promotion Signed-off-by: Iaroslav Vorozhko --- test/nginx/install.sh | 1 + test/nginx/test-canary.sh | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/test/nginx/install.sh b/test/nginx/install.sh index 5c3cbbbd..672b11af 100755 --- a/test/nginx/install.sh +++ b/test/nginx/install.sh @@ -14,6 +14,7 @@ helm upgrade -i ingress-nginx ingress-nginx/ingress-nginx --version=${NGINX_HELM --wait \ --namespace ingress-nginx \ --set controller.metrics.enabled=true \ +--set controller.admissionWebhooks.enabled=true \ --set controller.podAnnotations."prometheus\.io/scrape"=true \ --set controller.podAnnotations."prometheus\.io/port"=10254 \ --set controller.service.type=NodePort diff --git a/test/nginx/test-canary.sh b/test/nginx/test-canary.sh index baaccf28..b2a166ed 100755 --- a/test/nginx/test-canary.sh +++ b/test/nginx/test-canary.sh @@ -195,6 +195,30 @@ done echo '✔ Canary promotion test passed' +echo 'Testing original ingress update after canary promotion to pass validation webhook' + +cat <