Skip to content

Commit

Permalink
Add StdoutConfig and StderrorConfig to v1 Step
Browse files Browse the repository at this point in the history
These fields were previously added to v1beta1 Step, and should be present
in the v1 API as well. This commit adds these fields to the v1 package.
  • Loading branch information
lbernick authored and tekton-robot committed Jul 25, 2022
1 parent 3f53972 commit b8e244a
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 3 deletions.
13 changes: 13 additions & 0 deletions pkg/apis/pipeline/v1/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ type Step struct {
// stopAndFail indicates exit the taskRun if the container exits with non-zero exit code
// continue indicates continue executing the rest of the steps irrespective of the container exit code
OnError string `json:"onError,omitempty"`
// Stores configuration for the stdout stream of the step.
// +optional
StdoutConfig *StepOutputConfig `json:"stdoutConfig,omitempty"`
// Stores configuration for the stderr stream of the step.
// +optional
StderrConfig *StepOutputConfig `json:"stderrConfig,omitempty"`
}

// StepOutputConfig stores configuration for a step output stream.
type StepOutputConfig struct {
// Path to duplicate stdout stream to on container's local filesystem.
// +optional
Path string `json:"path,omitempty"`
}

// ToK8sContainer converts the Step to a Kubernetes Container struct
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func MergeStepsWithStepTemplate(template *StepTemplate, steps []Step) ([]Step, e
}

// Pass through original step Script, for later conversion.
newStep := Step{Script: s.Script, OnError: s.OnError, Timeout: s.Timeout}
newStep := Step{Script: s.Script, OnError: s.OnError, Timeout: s.Timeout, StdoutConfig: s.StdoutConfig, StderrConfig: s.StderrConfig}
newStep.SetContainerFields(merged)
steps[i] = newStep
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/apis/pipeline/v1/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ func TestMergeStepsWithStepTemplate(t *testing.T) {
Value: "NEW_VALUE",
}},
}},
}, {
name: "workspace-and-output-config",
template: &v1.StepTemplate{
VolumeMounts: []corev1.VolumeMount{{
Name: "data",
MountPath: "/workspace/data",
}},
},
steps: []v1.Step{{
Image: "some-image",
StdoutConfig: &v1.StepOutputConfig{Path: "stdout.txt"},
StderrConfig: &v1.StepOutputConfig{Path: "stderr.txt"},
}},
expected: []v1.Step{{
Image: "some-image",
StdoutConfig: &v1.StepOutputConfig{Path: "stdout.txt"},
StderrConfig: &v1.StepOutputConfig{Path: "stderr.txt"},
VolumeMounts: []corev1.VolumeMount{{
Name: "data",
MountPath: "/workspace/data",
}},
}},
}} {
t.Run(tc.name, func(t *testing.T) {
result, err := v1.MergeStepsWithStepTemplate(tc.template, tc.steps)
Expand Down
35 changes: 34 additions & 1 deletion pkg/apis/pipeline/v1/openapi_generated.go

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

18 changes: 18 additions & 0 deletions pkg/apis/pipeline/v1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,14 @@
"description": "SecurityContext defines the security options the container should be run with. If set, the fields of SecurityContext override the equivalent fields of PodSecurityContext. More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/",
"$ref": "#/definitions/v1.SecurityContext"
},
"stderrConfig": {
"description": "Stores configuration for the stderr stream of the step.",
"$ref": "#/definitions/v1.StepOutputConfig"
},
"stdoutConfig": {
"description": "Stores configuration for the stdout stream of the step.",
"$ref": "#/definitions/v1.StepOutputConfig"
},
"timeout": {
"description": "Timeout is the time after which the step times out. Defaults to never. Refer to Go's ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration",
"$ref": "#/definitions/v1.Duration"
Expand Down Expand Up @@ -564,6 +572,16 @@
}
}
},
"v1.StepOutputConfig": {
"description": "StepOutputConfig stores configuration for a step output stream.",
"type": "object",
"properties": {
"path": {
"description": "Path to duplicate stdout stream to on container's local filesystem.",
"type": "string"
}
}
},
"v1.StepTemplate": {
"description": "StepTemplate is a template for a Step",
"type": "object",
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/pipeline/v1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.Fi
errs = errs.Also(version.ValidateEnabledAPIFields(ctx, "windows script support", config.AlphaAPIFields).ViaField("script"))
}
}
// StdoutConfig is an alpha feature and will fail validation if it's used in a task spec
// when the enable-api-fields feature gate is not "alpha".
if s.StdoutConfig != nil {
errs = errs.Also(version.ValidateEnabledAPIFields(ctx, "step stdout stream support", config.AlphaAPIFields).ViaField("stdoutconfig"))
}
// StderrConfig is an alpha feature and will fail validation if it's used in a task spec
// when the enable-api-fields feature gate is not "alpha".
if s.StderrConfig != nil {
errs = errs.Also(version.ValidateEnabledAPIFields(ctx, "step stderr stream support", config.AlphaAPIFields).ViaField("stderrconfig"))
}
return errs
}

Expand Down
24 changes: 23 additions & 1 deletion pkg/apis/pipeline/v1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,29 @@ func TestIncompatibleAPIVersions(t *testing.T) {
script-1`,
}},
},
}}
}, {
name: "stdout stream support requires alpha",
requiredVersion: "alpha",
spec: v1.TaskSpec{
Steps: []v1.Step{{
Image: "foo",
StdoutConfig: &v1.StepOutputConfig{
Path: "/tmp/stdout.txt",
},
}},
},
}, {
name: "stderr stream support requires alpha",
requiredVersion: "alpha",
spec: v1.TaskSpec{
Steps: []v1.Step{{
Image: "foo",
StderrConfig: &v1.StepOutputConfig{
Path: "/tmp/stderr.txt",
},
}},
}},
}
versions := []string{"alpha", "stable"}
for _, tt := range tests {
for _, version := range versions {
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/pipeline/v1/zz_generated.deepcopy.go

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

0 comments on commit b8e244a

Please sign in to comment.