Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nil pointer while linting with basic canary and ingresses #2256

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The valid-nginx-basic-canary.yml manifest you added has no Spec.Strategy.Canary.TrafficRouting field, which tests the second part of this clause, but it does have a Spec.Strategy.Canary field.

Should we add another test Rollout manifest with no Spec.Strategy.Canary field to test the former part of this clause? Apologies if I'm misunderstanding the original bug

Copy link
Collaborator Author

@zachaller zachaller Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea the bug was really only ever for the missing TrafficRoutering field which is for basic canary. There are already test cases such as blue green https://github.com/argoproj/argo-rollouts/blob/754a5c7d0f1e7d4a26f26f8ff594a64dede82886/pkg/kubectl-argo-rollouts/cmd/lint/testdata/valid-blue-green.yml where we do not check for referenced resources that do not have Spec.Strategy.Canary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying!

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: {}