Skip to content

Commit 783c11a

Browse files
l-qingtekton-robot
authored andcommitted
fix: resolve panic issue in pipeline controller caused by CustomRun
fix #8561 When validating the optional workspace of the pipeline, encountering a CustomRun should not cause a panic, as this configuration will be validated again during the creation of the CustomRun.
1 parent 2b50c4c commit 783c11a

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

pkg/reconciler/pipelinerun/resources/validate_dependencies.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,10 @@ func ValidateOptionalWorkspaces(pipelineWorkspaces []v1.PipelineWorkspaceDeclara
101101

102102
for _, rpt := range state {
103103
for _, pws := range rpt.PipelineTask.Workspaces {
104-
if optionalWorkspaces.Has(pws.Workspace) {
104+
if rpt.ResolvedTask != nil && rpt.ResolvedTask.TaskSpec != nil && optionalWorkspaces.Has(pws.Workspace) {
105105
for _, tws := range rpt.ResolvedTask.TaskSpec.Workspaces {
106-
if tws.Name == pws.Name {
107-
if !tws.Optional {
108-
return fmt.Errorf("pipeline workspace %q is marked optional but pipeline task %q requires it be provided", pws.Workspace, rpt.PipelineTask.Name)
109-
}
106+
if tws.Name == pws.Name && !tws.Optional {
107+
return fmt.Errorf("pipeline workspace %q is marked optional but pipeline task %q requires it be provided", pws.Workspace, rpt.PipelineTask.Name)
110108
}
111109
}
112110
}

pkg/reconciler/pipelinerun/resources/validate_dependencies_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,23 @@ func TestValidateOptionalWorkspaces_ValidStates(t *testing.T) {
422422
},
423423
},
424424
}},
425+
}, {
426+
desc: "pipeline with optional workspace combined with customrun",
427+
workspaces: []v1.PipelineWorkspaceDeclaration{{
428+
Name: "ws1",
429+
Optional: true,
430+
}},
431+
state: prresources.PipelineRunState{{
432+
PipelineTask: &v1.PipelineTask{
433+
Name: "pt1",
434+
Workspaces: []v1.WorkspacePipelineTaskBinding{{
435+
Name: "foo",
436+
Workspace: "ws1",
437+
}},
438+
},
439+
ResolvedTask: nil,
440+
CustomTask: true,
441+
}},
425442
}} {
426443
t.Run(tc.desc, func(t *testing.T) {
427444
if err := prresources.ValidateOptionalWorkspaces(tc.workspaces, tc.state); err != nil {

0 commit comments

Comments
 (0)