Skip to content

Commit

Permalink
fix: nil pointer while linting with basic canary and ingresses (#2256)
Browse files Browse the repository at this point in the history
* fix: nil pointer while linting basic canary with Ingress resources

Signed-off-by: zachaller <[email protected]>

* Add test case

Signed-off-by: zachaller <[email protected]>

Signed-off-by: zachaller <[email protected]>
  • Loading branch information
zachaller authored and leoluz committed Sep 27, 2022
1 parent 60944c2 commit 20ec1c7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/kubectl-argo-rollouts/cmd/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/kubectl-argo-rollouts/cmd/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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: {}

0 comments on commit 20ec1c7

Please sign in to comment.