Skip to content

Commit

Permalink
convert onFailure breakpoint to a bool
Browse files Browse the repository at this point in the history
based on
tektoncd/community#572 (review)
---
the onFailure breakpoint is updated to be a bool to avoid considering
"onFailure" as reserved string.
  • Loading branch information
waveywaves committed Jan 20, 2022
1 parent e752c2f commit 044e9d6
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 78 deletions.
37 changes: 26 additions & 11 deletions pkg/apis/pipeline/v1beta1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions pkg/apis/pipeline/v1beta1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2075,16 +2075,22 @@
}
}
},
"v1beta1.TaskRunBreakpoint": {
"description": "TaskRunBreakpoint defines the breakpoint config for a particular TaskRun",
"type": "object",
"properties": {
"onFailure": {
"type": "boolean",
"default": false
}
}
},
"v1beta1.TaskRunDebug": {
"description": "TaskRunDebug defines the breakpoint config for a particular TaskRun",
"description": "TaskRunDebug defines the debug config for a particular TaskRun",
"type": "object",
"properties": {
"breakpoint": {
"type": "array",
"items": {
"type": "string",
"default": ""
}
"$ref": "#/definitions/v1beta1.TaskRunBreakpoint"
}
}
},
Expand Down
10 changes: 8 additions & 2 deletions pkg/apis/pipeline/v1beta1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ const (
TaskRunSpecStatusCancelled = "TaskRunCancelled"
)

// TaskRunDebug defines the breakpoint config for a particular TaskRun
// TaskRunDebug defines the debug config for a particular TaskRun
type TaskRunDebug struct {
// +optional
Breakpoint []string `json:"breakpoint,omitempty"`
Breakpoint *TaskRunBreakpoint `json:"breakpoint,omitempty"`
}

// TaskRunBreakpoint defines the breakpoint config for a particular TaskRun
type TaskRunBreakpoint struct {
// +optional
OnFailure bool `json:"onFailure"`
}

// TaskRunInputs holds the input values that this task was invoked with.
Expand Down
13 changes: 4 additions & 9 deletions pkg/apis/pipeline/v1beta1/taskrun_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,12 @@ func (ts *TaskRunSpec) Validate(ctx context.Context) (errs *apis.FieldError) {
return errs
}

// validateDebug
// validateDebug checks if the given debug options provided for the TaskRun make sense.
func validateDebug(db *TaskRunDebug) (errs *apis.FieldError) {
breakpointOnFailure := "onFailure"
validBreakpoints := sets.NewString()
validBreakpoints.Insert(breakpointOnFailure)
// TODO: Add breakpoints validation for beforeStep and afterStep
//validBreakpoints := sets.NewString()
//validBreakpoints.Insert()

for _, b := range db.Breakpoint {
if !validBreakpoints.Has(b) {
errs = errs.Also(apis.ErrInvalidValue(fmt.Sprintf("%s is not a valid breakpoint. Available valid breakpoints include %s", b, validBreakpoints.List()), "breakpoint"))
}
}
return errs
}

Expand Down
23 changes: 0 additions & 23 deletions pkg/apis/pipeline/v1beta1/taskrun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,29 +238,6 @@ func TestTaskRunSpec_Invalidate(t *testing.T) {
},
wantErr: apis.ErrInvalidValue("invalid bundle reference", "taskRef.bundle", "could not parse reference: invalid reference"),
wc: enableTektonOCIBundles(t),
}, {
name: "using debug when apifields stable",
spec: v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{
Name: "my-task",
},
Debug: &v1beta1.TaskRunDebug{
Breakpoint: []string{"bReaKdAnCe"},
},
},
wantErr: apis.ErrDisallowedFields("debug"),
}, {
name: "invalid breakpoint",
spec: v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{
Name: "my-task",
},
Debug: &v1beta1.TaskRunDebug{
Breakpoint: []string{"breakito"},
},
},
wantErr: apis.ErrInvalidValue("breakito is not a valid breakpoint. Available valid breakpoints include [onFailure]", "debug.breakpoint"),
wc: enableAlphaAPIFields,
}}
for _, ts := range tests {
t.Run(ts.name, func(t *testing.T) {
Expand Down
20 changes: 18 additions & 2 deletions pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions pkg/pod/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const (

stepPrefix = "step-"
sidecarPrefix = "sidecar-"

breakpointOnFailure = "onFailure"
)

var (
Expand Down Expand Up @@ -144,14 +142,8 @@ func orderContainers(commonExtraEntrypointArgs []string, steps []corev1.Containe
argsForEntrypoint = append(argsForEntrypoint, resultArgument(steps, taskSpec.Results)...)
}

if breakpointConfig != nil && len(breakpointConfig.Breakpoint) > 0 {
breakpoints := breakpointConfig.Breakpoint
for _, b := range breakpoints {
// TODO(TEP #0042): Add other breakpoints
if b == breakpointOnFailure {
argsForEntrypoint = append(argsForEntrypoint, "-breakpoint_on_failure")
}
}
if breakpointConfig != nil && breakpointConfig.Breakpoint.OnFailure {
argsForEntrypoint = append(argsForEntrypoint, "-breakpoint_on_failure")
}

cmd, args := s.Command, s.Args
Expand Down
2 changes: 1 addition & 1 deletion pkg/pod/entrypoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestOrderContainersWithDebugOnFailure(t *testing.T) {
TerminationMessagePath: "/tekton/termination",
}}
taskRunDebugConfig := &v1beta1.TaskRunDebug{
Breakpoint: []string{"onFailure"},
Breakpoint: &v1beta1.TaskRunBreakpoint{OnFailure: true},
}
got, err := orderContainers([]string{}, steps, nil, taskRunDebugConfig)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestPodBuild(t *testing.T) {
desc: "simple with breakpoint onFailure enabled, alpha api fields disabled",
trs: v1beta1.TaskRunSpec{
Debug: &v1beta1.TaskRunDebug{
Breakpoint: []string{breakpointOnFailure},
Breakpoint: &v1beta1.TaskRunBreakpoint{OnFailure: true},
},
},
ts: v1beta1.TaskSpec{
Expand Down Expand Up @@ -1660,7 +1660,7 @@ func TestPodBuildwithAlphaAPIEnabled(t *testing.T) {
desc: "simple with debug breakpoint onFailure",
trs: v1beta1.TaskRunSpec{
Debug: &v1beta1.TaskRunDebug{
Breakpoint: []string{breakpointOnFailure},
Breakpoint: &v1beta1.TaskRunBreakpoint{OnFailure: true},
},
},
ts: v1beta1.TaskSpec{
Expand Down
25 changes: 14 additions & 11 deletions pkg/pod/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ func convertScripts(shellImageLinux string, shellImageWin string, steps []v1beta
VolumeMounts: []corev1.VolumeMount{writeScriptsVolumeMount, binMount},
}

breakpoints := []string{}
breakpointOnFailure := false
// TODO: init before and after breakpoints here
sideCarSteps := []v1beta1.Step{}
for _, step := range sidecars {
sidecarStep := v1beta1.Step{
Expand All @@ -107,15 +108,16 @@ func convertScripts(shellImageLinux string, shellImageWin string, steps []v1beta
}

// Add mounts for debug
if debugConfig != nil && len(debugConfig.Breakpoint) > 0 {
breakpoints = debugConfig.Breakpoint
if debugConfig != nil && debugConfig.Breakpoint != nil {
breakpointOnFailure = debugConfig.Breakpoint.OnFailure
// TODO: set before and after breakpoints here
placeScriptsInit.VolumeMounts = append(placeScriptsInit.VolumeMounts, debugScriptsVolumeMount)
}

convertedStepContainers := convertListOfSteps(steps, &placeScriptsInit, &placeScripts, breakpoints, "script")
convertedStepContainers := convertListOfSteps(steps, &placeScriptsInit, &placeScripts, breakpointOnFailure, "script")

// Pass empty breakpoint list in "sidecar step to container" converter to not rewrite the scripts and add breakpoints to sidecar
sidecarContainers := convertListOfSteps(sideCarSteps, &placeScriptsInit, &placeScripts, []string{}, "sidecar-script")
// Pass false value for breakpointOnFailure in "sidecar step to container" converter to not rewrite the scripts and add breakpoints to sidecar
sidecarContainers := convertListOfSteps(sideCarSteps, &placeScriptsInit, &placeScripts, false, "sidecar-script")
if placeScripts {
return &placeScriptsInit, convertedStepContainers, sidecarContainers
}
Expand All @@ -126,7 +128,7 @@ func convertScripts(shellImageLinux string, shellImageWin string, steps []v1beta
//
// It iterates through the list of steps (or sidecars), generates the script file name and heredoc termination string,
// adds an entry to the init container args, sets up the step container to run the script, and sets the volume mounts.
func convertListOfSteps(steps []v1beta1.Step, initContainer *corev1.Container, placeScripts *bool, breakpoints []string, namePrefix string) []corev1.Container {
func convertListOfSteps(steps []v1beta1.Step, initContainer *corev1.Container, placeScripts *bool, breakpointOnFailure bool, namePrefix string) []corev1.Container {
containers := []corev1.Container{}
for i, s := range steps {
if s.Script == "" {
Expand Down Expand Up @@ -186,8 +188,9 @@ cat > ${scriptfile} << '%s'
}
steps[i].VolumeMounts = append(steps[i].VolumeMounts, scriptsVolumeMount)

// Add debug mounts if breakpoints are present
if len(breakpoints) > 0 {
// Add debug mounts if breakpointOnFailure is present
// TODO: change this to factor in changes to
if breakpointOnFailure {
debugInfoVolumeMount := corev1.VolumeMount{
Name: debugInfoVolumeName,
MountPath: filepath.Join(debugInfoDir, fmt.Sprintf("%d", i)),
Expand All @@ -197,8 +200,8 @@ cat > ${scriptfile} << '%s'
containers = append(containers, steps[i].Container)
}

// Place debug scripts if breakpoints are enabled
if len(breakpoints) > 0 {
// Place debug scripts if breakpointOnFailure are enabled
if breakpointOnFailure {
type script struct {
name string
content string
Expand Down
2 changes: 1 addition & 1 deletion pkg/pod/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ script-3`,
Args: []string{"my", "args"},
},
}}, []v1beta1.Sidecar{}, &v1beta1.TaskRunDebug{
Breakpoint: []string{breakpointOnFailure},
Breakpoint: &v1beta1.TaskRunBreakpoint{OnFailure: true},
})
wantInit := &corev1.Container{
Name: "place-scripts",
Expand Down

0 comments on commit 044e9d6

Please sign in to comment.