Skip to content

Commit 4eb7b01

Browse files
authored
fix: linting pointer error when template name is invalid (argoproj#14896)
Signed-off-by: jmeridth <jmeridth@gmail.com>
1 parent 1d9d037 commit 4eb7b01

4 files changed

Lines changed: 80 additions & 3 deletions

File tree

test/e2e/cli_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,12 @@ func (s *CLISuite) TestWorkflowLint() {
706706
assert.Contains(t, output, "no linting errors found")
707707
})
708708
})
709+
s.Run("LintFileEmptyTemplateSteps", func() {
710+
s.Given().RunCli([]string{"lint", "smoke/empty-template-steps.yaml"}, func(t *testing.T, output string, err error) {
711+
require.NoError(t, err)
712+
assert.Contains(t, output, "no linting errors found")
713+
})
714+
})
709715
s.Run("LintFileEmptyParamDAG", func() {
710716
s.Given().RunCli([]string{"lint", "expectedfailures/empty-parameter-dag.yaml"}, func(t *testing.T, output string, err error) {
711717
require.EqualError(t, err, "exit status 1")
@@ -718,6 +724,12 @@ func (s *CLISuite) TestWorkflowLint() {
718724
assert.Contains(t, output, "templates.abc.steps[0].a templates.whalesay inputs.parameters.message was not supplied")
719725
})
720726
})
727+
s.Run("LintFileMisreferenceTemplate", func() {
728+
s.Given().RunCli([]string{"lint", "expectedfailures/misreference-template-name.yaml"}, func(t *testing.T, output string, err error) {
729+
require.EqualError(t, err, "exit status 1")
730+
assert.Contains(t, output, "templates.steps-with-misreference.steps[1].hello2 template name 'hell0' undefined")
731+
})
732+
})
721733
s.Run("LintFileWithTemplate", func() {
722734
s.Given().
723735
WorkflowTemplate("@smoke/workflow-template-whalesay-template.yaml").
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Workflow
3+
metadata:
4+
generateName: steps-with-misreference-
5+
spec:
6+
podMetadata:
7+
labels:
8+
test: steps-with-misreference
9+
podPriorityClassName: lowest
10+
entrypoint: steps-with-misreference
11+
templates:
12+
- name: steps-with-misreference
13+
steps:
14+
- - name: hello1
15+
template: hello
16+
arguments:
17+
parameters:
18+
- name: message
19+
value: "hello1"
20+
- - name: hello2
21+
template: hell0
22+
arguments:
23+
parameters:
24+
- name: message
25+
value: "hello2"
26+
- name: hello
27+
inputs:
28+
parameters:
29+
- name: message
30+
container:
31+
image: argoproj/argosay:v2
32+
args: ["echo", "{{inputs.parameters.message}}"]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Workflow
3+
metadata:
4+
generateName: empty-array-in-steps
5+
spec:
6+
podMetadata:
7+
labels:
8+
test: empty-array-in-steps
9+
podPriorityClassName: lowest
10+
entrypoint: steps-with-empty-array
11+
templates:
12+
- name: steps-with-empty-array
13+
steps:
14+
- - name: hello1
15+
template: hello
16+
arguments:
17+
parameters:
18+
- name: message
19+
value: "hello1"
20+
- []
21+
- - name: hello2
22+
template: hello
23+
arguments:
24+
parameters:
25+
- name: message
26+
value: "hello2"
27+
- name: hello
28+
inputs:
29+
parameters:
30+
- name: message
31+
container:
32+
image: argoproj/argosay:v2
33+
args: ["echo", "{{inputs.parameters.message}}"]

workflow/templateresolution/context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ func (tplCtx *TemplateContext) GetTemplateByName(ctx context.Context, name strin
110110
tplCtx.log.WithField("name", name).Debug(ctx, "Getting the template by name")
111111

112112
tmpl := tplCtx.tmplBase.GetTemplateByName(name)
113+
if tmpl == nil {
114+
return nil, errors.Errorf(errors.CodeNotFound, "template %s not found", name)
115+
}
113116

114117
podMetadata := tplCtx.tmplBase.GetPodMetadata()
115118
tplCtx.addPodMetadata(podMetadata, tmpl)
116119

117-
if tmpl == nil {
118-
return nil, errors.Errorf(errors.CodeNotFound, "template %s not found", name)
119-
}
120120
return tmpl.DeepCopy(), nil
121121
}
122122

0 commit comments

Comments
 (0)