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 authored and tekton-robot committed Jul 11, 2024
1 parent 7aedaac commit 0f6c973
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1/taskrun_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,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("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(db.Breakpoints.OnFailure+" is not a valid onFailure breakpoint value, onFailure breakpoint is only allowed to be set as enabled", "breakpoints.onFailure"))
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/pipeline/v1/taskrun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,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: v1.TaskRunSpec{
TaskRef: &v1.TaskRef{
Name: "my-task",
},
Debug: &v1.TaskRunDebug{
Breakpoints: &v1.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: "stepSpecs disallowed without beta feature gate",
spec: v1.TaskRunSpec{
Expand Down
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 @@ -224,6 +224,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("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(db.Breakpoints.OnFailure+" is not a valid onFailure breakpoint value, onFailure breakpoint is only allowed to be set as enabled", "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 @@ -698,6 +698,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: "duplicate stepOverride names",
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 @@ -241,7 +241,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 0f6c973

Please sign in to comment.