Skip to content

Commit

Permalink
fix: resolve panic issue in pipeline controller caused by CustomRun
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
l-qing committed Feb 11, 2025
1 parent e34b540 commit ba28357
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pkg/reconciler/pipelinerun/resources/validate_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ func ValidateOptionalWorkspaces(pipelineWorkspaces []v1.PipelineWorkspaceDeclara

for _, rpt := range state {
for _, pws := range rpt.PipelineTask.Workspaces {
if optionalWorkspaces.Has(pws.Workspace) {
if rpt.ResolvedTask != nil && rpt.ResolvedTask.TaskSpec != nil && optionalWorkspaces.Has(pws.Workspace) {
for _, tws := range rpt.ResolvedTask.TaskSpec.Workspaces {
if tws.Name == pws.Name {
if !tws.Optional {
return fmt.Errorf("pipeline workspace %q is marked optional but pipeline task %q requires it be provided", pws.Workspace, rpt.PipelineTask.Name)
}
if tws.Name == pws.Name && !tws.Optional {
return fmt.Errorf("pipeline workspace %q is marked optional but pipeline task %q requires it be provided", pws.Workspace, rpt.PipelineTask.Name)
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/reconciler/pipelinerun/resources/validate_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,23 @@ func TestValidateOptionalWorkspaces_ValidStates(t *testing.T) {
},
},
}},
}, {
desc: "pipeline with optional workspace combined with customrun",
workspaces: []v1.PipelineWorkspaceDeclaration{{
Name: "ws1",
Optional: true,
}},
state: prresources.PipelineRunState{{
PipelineTask: &v1.PipelineTask{
Name: "pt1",
Workspaces: []v1.WorkspacePipelineTaskBinding{{
Name: "foo",
Workspace: "ws1",
}},
},
ResolvedTask: nil,
CustomTask: true,
}},
}} {
t.Run(tc.desc, func(t *testing.T) {
if err := prresources.ValidateOptionalWorkspaces(tc.workspaces, tc.state); err != nil {
Expand Down

0 comments on commit ba28357

Please sign in to comment.