Skip to content

Commit

Permalink
fix:when debug.breakpoints.onFailure is an empty string, redundant vo…
Browse files Browse the repository at this point in the history
…lumes appear
  • Loading branch information
cugykw committed Mar 21, 2024
1 parent d1d689f commit 3dea31e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1beta1/taskrun_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ func validateDebug(db *TaskRunDebug) (errs *apis.FieldError) {
if db == nil || db.Breakpoints == nil {
return errs
}

if db.Breakpoints.OnFailure == "" {
errs = errs.Also(apis.ErrInvalidValue(fmt.Sprintf("onFailure breakpoint is empty, it is only allowed to be set as enabled"), "breakpoints.onFailure"))
}

if db.Breakpoints.OnFailure != "" && db.Breakpoints.OnFailure != EnabledOnFailureBreakpoint {
errs = errs.Also(apis.ErrInvalidValue(fmt.Sprintf("%s is not a valid onFailure breakpoint value, onFailure breakpoint is only allowed to be set as enabled", db.Breakpoints.OnFailure), "breakpoints.onFailure"))
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/pipeline/v1beta1/taskrun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,20 @@ func TestTaskRunSpec_Invalidate(t *testing.T) {
},
wantErr: apis.ErrInvalidValue("turnOn is not a valid onFailure breakpoint value, onFailure breakpoint is only allowed to be set as enabled", "debug.breakpoints.onFailure"),
wc: cfgtesting.EnableAlphaAPIFields,
}, {
name: "empty onFailure breakpoint",
spec: v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{
Name: "my-task",
},
Debug: &v1beta1.TaskRunDebug{
Breakpoints: &v1beta1.TaskBreakpoints{
OnFailure: "",
},
},
},
wantErr: apis.ErrInvalidValue("onFailure breakpoint is empty, it is only allowed to be set as enabled", "debug.breakpoints.onFailure"),
wc: cfgtesting.EnableAlphaAPIFields,
}, {
name: "stepOverride disallowed without alpha feature gate",
spec: v1beta1.TaskRunSpec{
Expand Down
2 changes: 1 addition & 1 deletion pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1.TaskRun, taskSpec v1.Ta
initContainers = append(initContainers, *scriptsInit)
volumes = append(volumes, scriptsVolume)
}
if alphaAPIEnabled && taskRun.Spec.Debug != nil {
if alphaAPIEnabled && taskRun.Spec.Debug != nil && taskRun.Spec.Debug.NeedsDebug() {
volumes = append(volumes, debugScriptsVolume, debugInfoVolume)
}
// Initialize any workingDirs under /workspace.
Expand Down

0 comments on commit 3dea31e

Please sign in to comment.