From 20ec1c7a88dc98fb2edea1f5cce9dd6e185906be Mon Sep 17 00:00:00 2001 From: Zach Aller Date: Tue, 27 Sep 2022 13:24:38 -0500 Subject: [PATCH] fix: nil pointer while linting with basic canary and ingresses (#2256) * fix: nil pointer while linting basic canary with Ingress resources Signed-off-by: zachaller * Add test case Signed-off-by: zachaller Signed-off-by: zachaller --- pkg/kubectl-argo-rollouts/cmd/lint/lint.go | 5 ++ .../cmd/lint/lint_test.go | 1 + .../testdata/valid-nginx-basic-canary.yml | 58 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 pkg/kubectl-argo-rollouts/cmd/lint/testdata/valid-nginx-basic-canary.yml diff --git a/pkg/kubectl-argo-rollouts/cmd/lint/lint.go b/pkg/kubectl-argo-rollouts/cmd/lint/lint.go index 2969b53034..66e28318eb 100644 --- a/pkg/kubectl-argo-rollouts/cmd/lint/lint.go +++ b/pkg/kubectl-argo-rollouts/cmd/lint/lint.go @@ -261,6 +261,11 @@ func setIngressManagedAnnotation(rollouts []v1alpha1.Rollout, refResource valida for _, rollout := range rollouts { for i := range refResource.Ingresses { var serviceName string + + // Basic Canary so ingress is only pointing a single service and so no linting is needed for this case. + if rollout.Spec.Strategy.Canary == nil || rollout.Spec.Strategy.Canary.TrafficRouting == nil { + return + } if rollout.Spec.Strategy.Canary.TrafficRouting.Nginx != nil { serviceName = rollout.Spec.Strategy.Canary.StableService } else if rollout.Spec.Strategy.Canary.TrafficRouting.ALB != nil { diff --git a/pkg/kubectl-argo-rollouts/cmd/lint/lint_test.go b/pkg/kubectl-argo-rollouts/cmd/lint/lint_test.go index 554c4820db..29fce3afe3 100644 --- a/pkg/kubectl-argo-rollouts/cmd/lint/lint_test.go +++ b/pkg/kubectl-argo-rollouts/cmd/lint/lint_test.go @@ -27,6 +27,7 @@ func TestLintValidRollout(t *testing.T) { "testdata/valid-ingress-smi-multi.yml", "testdata/valid-alb-canary.yml", "testdata/valid-nginx-canary.yml", + "testdata/valid-nginx-basic-canary.yml", "testdata/valid-istio-v1beta1-mulitiple-virtualsvcs.yml", } diff --git a/pkg/kubectl-argo-rollouts/cmd/lint/testdata/valid-nginx-basic-canary.yml b/pkg/kubectl-argo-rollouts/cmd/lint/testdata/valid-nginx-basic-canary.yml new file mode 100644 index 0000000000..4d295c6c86 --- /dev/null +++ b/pkg/kubectl-argo-rollouts/cmd/lint/testdata/valid-nginx-basic-canary.yml @@ -0,0 +1,58 @@ +apiVersion: v1 +kind: Service +metadata: + name: nginx-rollout-stable +spec: + type: NodePort + ports: + - port: 80 + targetPort: http + protocol: TCP + name: http + selector: + app: nginx-rollout +--- +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + name: nginx-rollout-ingress +spec: + rules: + - http: + paths: + - path: /* + backend: + serviceName: nginx-rollout-root + servicePort: use-annotation +--- +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +metadata: + name: nginx-rollout +spec: + selector: + matchLabels: + app: nginx-rollout + template: + metadata: + labels: + app: nginx-rollout + spec: + containers: + - name: nginx-rollout + image: argoproj/rollouts-demo:blue + ports: + - name: http + containerPort: 80 + protocol: TCP + resources: + requests: + memory: 16Mi + cpu: 5m + strategy: + canary: + steps: + - setWeight: 10 + - pause: {} + - setWeight: 50 + - pause: {}