diff --git a/docs/pipeline-api.md b/docs/pipeline-api.md index 97065ad87a0..8e8e62ee84f 100644 --- a/docs/pipeline-api.md +++ b/docs/pipeline-api.md @@ -445,6 +445,117 @@ TaskSpec +

EmbeddedTask +

+

+(Appears on:PipelineTask) +

+
+

EmbeddedTask is used to define a Task inline within a Pipeline’s PipelineTasks.

+
+ + + + + + + + + + + + + + + + + + + + + +
FieldDescription
+spec
+ +k8s.io/apimachinery/pkg/runtime.RawExtension + +
+(Optional) +

Spec is a specification of a custom task

+
+
+ + + + + + + + + +
+-
+ +[]byte + +
+

Raw is the underlying serialization of this object.

+

TODO: Determine how to detect ContentType and ContentEncoding of ‘Raw’ data.

+
+-
+ +k8s.io/apimachinery/pkg/runtime.Object + +
+

Object can hold a representation of this extension - useful for working with versioned +structs.

+
+
+metadata
+ + +PipelineTaskMetadata + + +
+(Optional) +
+TaskSpec
+ + +TaskSpec + + +
+

+(Members of TaskSpec are embedded into this type.) +

+(Optional) +

TaskSpec is a specification of a task

+
+

OnErrorType +(string alias)

+

+(Appears on:Step) +

+
+

OnErrorType defines a list of supported exiting behavior of a container on error

+
+ + + + + + + + + + + + +
ValueDescription

"continue"

Continue indicates continue executing the rest of the steps irrespective of the container exit code

+

"stopAndFail"

StopAndFail indicates exit the taskRun if the container exits with non-zero exit code

+

Param

@@ -1359,8 +1470,8 @@ string -

Name of the container specified as a DNS_LABEL. -Each container in a pod must have a unique name (DNS_LABEL). +

Name of the Sidecar specified as a DNS_LABEL. +Each Sidecar in a Task must have a unique name (DNS_LABEL). Cannot be updated.

@@ -1373,7 +1484,7 @@ string (Optional) -

Docker image name. +

Image reference name. More info: https://kubernetes.io/docs/concepts/containers/images This field is optional to allow higher level config management to default or override container images in workload controllers like Deployments and StatefulSets.

@@ -1389,8 +1500,8 @@ container images in workload controllers like Deployments and StatefulSets.

(Optional)

Entrypoint array. Not executed within a shell. -The docker image’s ENTRYPOINT is used if this is not provided. -Variable references $(VAR_NAME) are expanded using the container’s environment. If a variable +The image’s ENTRYPOINT is used if this is not provided. +Variable references $(VAR_NAME) are expanded using the Sidecar’s environment. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. “$$(VAR_NAME)” will produce the string literal “$(VAR_NAME)”. Escaped references will never be expanded, regardless @@ -1408,8 +1519,8 @@ More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/

@@ -1513,7 +1624,7 @@ More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

@@ -1559,7 +1670,7 @@ Kubernetes core/v1.Probe (Optional) -

Periodic probe of container service readiness. +

Periodic probe of Sidecar service readiness. Container will be removed from service endpoints if the probe fails. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

@@ -1576,7 +1687,7 @@ Kubernetes core/v1.Probe (Optional) -

StartupProbe indicates that the Pod has successfully initialized. +

StartupProbe indicates that the Pod the Sidecar is running in has successfully initialized. If specified, no other probes are executed until this completes successfully. If this probe fails, the Pod will be restarted, just as if the livenessProbe failed. This can be used to provide different probe parameters at the beginning of a Pod’s lifecycle, @@ -1596,7 +1707,7 @@ Kubernetes core/v1.Lifecycle (Optional) -

Actions that the management system should take in response to container lifecycle events. +

Actions that the management system should take in response to Sidecar lifecycle events. Cannot be updated.

@@ -1609,8 +1720,8 @@ string (Optional) -

Optional: Path at which the file to which the container’s termination message -will be written is mounted into the container’s filesystem. +

Optional: Path at which the file to which the Sidecar’s termination message +will be written is mounted into the Sidecar’s filesystem. Message written is intended to be brief final status, such as an assertion failure message. Will be truncated by the node if greater than 4096 bytes. The total message length across all containers will be limited to 12kb. @@ -1630,9 +1741,9 @@ Kubernetes core/v1.TerminationMessagePolicy (Optional)

Indicate how the termination message should be populated. File will use the contents of -terminationMessagePath to populate the container status message on both success and failure. -FallbackToLogsOnError will use the last chunk of container log output if the termination -message file is empty and the container exited with an error. +terminationMessagePath to populate the Sidecar status message on both success and failure. +FallbackToLogsOnError will use the last chunk of Sidecar log output if the termination +message file is empty and the Sidecar exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated.

@@ -1667,7 +1778,7 @@ Kubernetes core/v1.SecurityContext (Optional) -

SecurityContext defines the security options the container should be run with. +

SecurityContext defines the security options the Sidecar 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/

@@ -1681,8 +1792,8 @@ bool (Optional) -

Whether this container should allocate a buffer for stdin in the container runtime. If this -is not set, reads from stdin in the container will always result in EOF. +

Whether this Sidecar should allocate a buffer for stdin in the container runtime. If this +is not set, reads from stdin in the Sidecar will always result in EOF. Default is false.

@@ -1697,9 +1808,9 @@ bool (Optional)

Whether the container runtime should close the stdin channel after it has been opened by a single attach. When stdin is true the stdin stream will remain open across multiple attach -sessions. If stdinOnce is set to true, stdin is opened on container start, is empty until the +sessions. If stdinOnce is set to true, stdin is opened on Sidecar start, is empty until the first client attaches to stdin, and then remains open and accepts data until the client disconnects, -at which time stdin is closed and remains closed until the container is restarted. If this +at which time stdin is closed and remains closed until the Sidecar is restarted. If this flag is false, a container processes that reads from stdin will never receive an EOF. Default is false

@@ -1713,7 +1824,7 @@ bool (Optional) -

Whether this container should allocate a TTY for itself, also requires ‘stdin’ to be true. +

Whether this Sidecar should allocate a TTY for itself, also requires ‘stdin’ to be true. Default is false.

@@ -1775,9 +1886,8 @@ string -

Name of the container specified as a DNS_LABEL. -Each container in a pod must have a unique name (DNS_LABEL). -Cannot be updated.

+

Name of the Step specified as a DNS_LABEL. +Each Step in a Task must have a unique name.

@@ -1790,9 +1900,7 @@ string (Optional)

Docker image name. -More info: https://kubernetes.io/docs/concepts/containers/images -This field is optional to allow higher level config management to default or override -container images in workload controllers like Deployments and StatefulSets.

+More info: https://kubernetes.io/docs/concepts/containers/images

@@ -1805,7 +1913,7 @@ container images in workload controllers like Deployments and StatefulSets.

(Optional)

Entrypoint array. Not executed within a shell. -The docker image’s ENTRYPOINT is used if this is not provided. +The image’s ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container’s environment. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. “$$(VAR_NAME)” will @@ -1824,7 +1932,7 @@ More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/

@@ -1909,7 +2017,7 @@ More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/

@@ -2012,14 +2120,14 @@ not have access to it.

onError
-string + +OnErrorType +

OnError defines the exiting behavior of a container on error -can be set to [ continue | stopAndFail ] -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

+can be set to [ continue | stopAndFail ]

@@ -2107,7 +2215,7 @@ string (Optional) -

Docker image name. +

Image reference name. More info: https://kubernetes.io/docs/concepts/containers/images This field is optional to allow higher level config management to default or override container images in workload controllers like Deployments and StatefulSets.

@@ -2123,8 +2231,8 @@ container images in workload controllers like Deployments and StatefulSets.

(Optional)

Entrypoint array. Not executed within a shell. -The docker image’s ENTRYPOINT is used if this is not provided. -Variable references $(VAR_NAME) are expanded using the container’s environment. If a variable +The image’s ENTRYPOINT is used if this is not provided. +Variable references $(VAR_NAME) are expanded using the Step’s environment. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. “$$(VAR_NAME)” will produce the string literal “$(VAR_NAME)”. Escaped references will never be expanded, regardless @@ -2142,8 +2250,8 @@ More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/

@@ -2227,7 +2335,7 @@ More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/

@@ -5406,6 +5514,29 @@ TaskSpec +

OnErrorType +(string alias)

+

+(Appears on:Step) +

+
+

OnErrorType defines a list of supported exiting behavior of a container on error

+
+ + + + + + + + + + + + +
ValueDescription

"continue"

Continue indicates continue executing the rest of the steps irrespective of the container exit code

+

"stopAndFail"

StopAndFail indicates exit the taskRun if the container exits with non-zero exit code

+

Param

@@ -7511,8 +7642,8 @@ string -

Name of the container specified as a DNS_LABEL. -Each container in a pod must have a unique name (DNS_LABEL). +

Name of the Sidecar specified as a DNS_LABEL. +Each Sidecar in a Task must have a unique name (DNS_LABEL). Cannot be updated.

@@ -7525,10 +7656,8 @@ string (Optional) -

Docker image name. -More info: https://kubernetes.io/docs/concepts/containers/images -This field is optional to allow higher level config management to default or override -container images in workload controllers like Deployments and StatefulSets.

+

Image name to be used by the Sidecar. +More info: https://kubernetes.io/docs/concepts/containers/images

@@ -7541,8 +7670,8 @@ container images in workload controllers like Deployments and StatefulSets.

(Optional)

Entrypoint array. Not executed within a shell. -The docker image’s ENTRYPOINT is used if this is not provided. -Variable references $(VAR_NAME) are expanded using the container’s environment. If a variable +The image’s ENTRYPOINT is used if this is not provided. +Variable references $(VAR_NAME) are expanded using the Sidecar’s environment. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. “$$(VAR_NAME)” will produce the string literal “$(VAR_NAME)”. Escaped references will never be expanded, regardless @@ -7560,7 +7689,7 @@ More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/

@@ -7665,7 +7794,7 @@ More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

@@ -7711,7 +7840,7 @@ Kubernetes core/v1.Probe (Optional) -

Periodic probe of container service readiness. +

Periodic probe of Sidecar service readiness. Container will be removed from service endpoints if the probe fails. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

@@ -7728,7 +7857,7 @@ Kubernetes core/v1.Probe (Optional) -

StartupProbe indicates that the Pod has successfully initialized. +

StartupProbe indicates that the Pod the Sidecar is running in has successfully initialized. If specified, no other probes are executed until this completes successfully. If this probe fails, the Pod will be restarted, just as if the livenessProbe failed. This can be used to provide different probe parameters at the beginning of a Pod’s lifecycle, @@ -7748,7 +7877,7 @@ Kubernetes core/v1.Lifecycle (Optional) -

Actions that the management system should take in response to container lifecycle events. +

Actions that the management system should take in response to Sidecar lifecycle events. Cannot be updated.

@@ -7761,8 +7890,8 @@ string (Optional) -

Optional: Path at which the file to which the container’s termination message -will be written is mounted into the container’s filesystem. +

Optional: Path at which the file to which the Sidecar’s termination message +will be written is mounted into the Sidecar’s filesystem. Message written is intended to be brief final status, such as an assertion failure message. Will be truncated by the node if greater than 4096 bytes. The total message length across all containers will be limited to 12kb. @@ -7782,9 +7911,9 @@ Kubernetes core/v1.TerminationMessagePolicy (Optional)

Indicate how the termination message should be populated. File will use the contents of -terminationMessagePath to populate the container status message on both success and failure. -FallbackToLogsOnError will use the last chunk of container log output if the termination -message file is empty and the container exited with an error. +terminationMessagePath to populate the Sidecar status message on both success and failure. +FallbackToLogsOnError will use the last chunk of Sidecar log output if the termination +message file is empty and the Sidecar exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated.

@@ -7819,7 +7948,7 @@ Kubernetes core/v1.SecurityContext (Optional) -

SecurityContext defines the security options the container should be run with. +

SecurityContext defines the security options the Sidecar 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/

@@ -7833,8 +7962,8 @@ bool (Optional) -

Whether this container should allocate a buffer for stdin in the container runtime. If this -is not set, reads from stdin in the container will always result in EOF. +

Whether this Sidecar should allocate a buffer for stdin in the container runtime. If this +is not set, reads from stdin in the Sidecar will always result in EOF. Default is false.

@@ -7849,9 +7978,9 @@ bool (Optional)

Whether the container runtime should close the stdin channel after it has been opened by a single attach. When stdin is true the stdin stream will remain open across multiple attach -sessions. If stdinOnce is set to true, stdin is opened on container start, is empty until the +sessions. If stdinOnce is set to true, stdin is opened on Sidecar start, is empty until the first client attaches to stdin, and then remains open and accepts data until the client disconnects, -at which time stdin is closed and remains closed until the container is restarted. If this +at which time stdin is closed and remains closed until the Sidecar is restarted. If this flag is false, a container processes that reads from stdin will never receive an EOF. Default is false

@@ -7865,7 +7994,7 @@ bool (Optional) -

Whether this container should allocate a TTY for itself, also requires ‘stdin’ to be true. +

Whether this Sidecar should allocate a TTY for itself, also requires ‘stdin’ to be true. Default is false.

@@ -8086,9 +8215,8 @@ string -

Name of the container specified as a DNS_LABEL. -Each container in a pod must have a unique name (DNS_LABEL). -Cannot be updated.

+

Name of the Step specified as a DNS_LABEL. +Each Step in a Task must have a unique name.

@@ -8100,10 +8228,8 @@ string (Optional) -

Docker image name. -More info: https://kubernetes.io/docs/concepts/containers/images -This field is optional to allow higher level config management to default or override -container images in workload controllers like Deployments and StatefulSets.

+

Image reference name to run for this Step. +More info: https://kubernetes.io/docs/concepts/containers/images

@@ -8116,7 +8242,7 @@ container images in workload controllers like Deployments and StatefulSets.

(Optional)

Entrypoint array. Not executed within a shell. -The docker image’s ENTRYPOINT is used if this is not provided. +The image’s ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container’s environment. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. “$$(VAR_NAME)” will @@ -8135,7 +8261,7 @@ More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/

@@ -8241,7 +8367,7 @@ More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

@@ -8290,7 +8416,7 @@ Kubernetes core/v1.Probe (Optional)

Deprecated. This field will be removed in a future release. Periodic probe of container service readiness. -Container will be removed from service endpoints if the probe fails. +Step will be removed from service endpoints if the probe fails. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

@@ -8307,7 +8433,7 @@ Kubernetes core/v1.Probe (Optional)

Deprecated. This field will be removed in a future release. -DeprecatedStartupProbe indicates that the Pod has successfully initialized. +DeprecatedStartupProbe indicates that the Pod this Step runs in has successfully initialized. If specified, no other probes are executed until this completes successfully. If this probe fails, the Pod will be restarted, just as if the livenessProbe failed. This can be used to provide different probe parameters at the beginning of a Pod’s lifecycle, @@ -8341,14 +8467,7 @@ string (Optional) -

Deprecated. This field will be removed in a future release. -Optional: Path at which the file to which the container’s termination message -will be written is mounted into the container’s filesystem. -Message written is intended to be brief final status, such as an assertion failure message. -Will be truncated by the node if greater than 4096 bytes. The total message length across -all containers will be limited to 12kb. -Defaults to /dev/termination-log. -Cannot be updated.

+

Deprecated. This field will be removed in a future release and can’t be meaningfully used.

@@ -8362,14 +8481,7 @@ Kubernetes core/v1.TerminationMessagePolicy (Optional) -

Deprecated. This field will be removed in a future release. -Indicate how the termination message should be populated. File will use the contents of -terminationMessagePath to populate the container status message on both success and failure. -FallbackToLogsOnError will use the last chunk of container log output if the termination -message file is empty and the container exited with an error. -The log output is limited to 2048 bytes or 80 lines, whichever is smaller. -Defaults to File. -Cannot be updated.

+

Deprecated. This field will be removed in a future release and can’t be meaningfully used.

@@ -8401,7 +8513,7 @@ Kubernetes core/v1.SecurityContext (Optional) -

SecurityContext defines the security options the container should be run with. +

SecurityContext defines the security options the Step 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/

@@ -8505,14 +8617,14 @@ not have access to it.

onError
-string + +OnErrorType +

OnError defines the exiting behavior of a container on error -can be set to [ continue | stopAndFail ] -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

+can be set to [ continue | stopAndFail ]

@@ -8663,8 +8775,8 @@ string

Deprecated. This field will be removed in a future release. -DeprecatedName of the container specified as a DNS_LABEL. -Each container in a pod must have a unique name (DNS_LABEL). +Default name for each Step specified as a DNS_LABEL. +Each Step in a Task must have a unique name. Cannot be updated.

@@ -8677,7 +8789,7 @@ string (Optional) -

Docker image name. +

Default image name to use for each Step. More info: https://kubernetes.io/docs/concepts/containers/images This field is optional to allow higher level config management to default or override container images in workload controllers like Deployments and StatefulSets.

@@ -8694,7 +8806,7 @@ container images in workload controllers like Deployments and StatefulSets.

(Optional)

Entrypoint array. Not executed within a shell. The docker image’s ENTRYPOINT is used if this is not provided. -Variable references $(VAR_NAME) are expanded using the container’s environment. If a variable +Variable references $(VAR_NAME) are expanded using the Step’s environment. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. “$$(VAR_NAME)” will produce the string literal “$(VAR_NAME)”. Escaped references will never be expanded, regardless @@ -8712,8 +8824,8 @@ More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/

@@ -8818,7 +8930,7 @@ More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/

@@ -8993,8 +9091,8 @@ bool (Optional)

Deprecated. This field will be removed in a future release. -Whether this container should allocate a buffer for stdin in the container runtime. If this -is not set, reads from stdin in the container will always result in EOF. +Whether this Step should allocate a buffer for stdin in the container runtime. If this +is not set, reads from stdin in the Step will always result in EOF. Default is false.

@@ -9027,7 +9125,7 @@ bool (Optional)

Deprecated. This field will be removed in a future release. -Whether this container should allocate a DeprecatedTTY for itself, also requires ‘stdin’ to be true. +Whether this Step should allocate a DeprecatedTTY for itself, also requires ‘stdin’ to be true. Default is false.

diff --git a/pkg/apis/pipeline/v1/container_types.go b/pkg/apis/pipeline/v1/container_types.go index c2e041faa04..9293aae9e3a 100644 --- a/pkg/apis/pipeline/v1/container_types.go +++ b/pkg/apis/pipeline/v1/container_types.go @@ -129,9 +129,7 @@ type Step struct { // OnError defines the exiting behavior of a container on error // can be set to [ continue | stopAndFail ] - // 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"` + OnError OnErrorType `json:"onError,omitempty"` // Stores configuration for the stdout stream of the step. // +optional StdoutConfig *StepOutputConfig `json:"stdoutConfig,omitempty"` @@ -140,6 +138,16 @@ type Step struct { StderrConfig *StepOutputConfig `json:"stderrConfig,omitempty"` } +// OnErrorType defines a list of supported exiting behavior of a container on error +type OnErrorType string + +const ( + // StopAndFail indicates exit the taskRun if the container exits with non-zero exit code + StopAndFail OnErrorType = "stopAndFail" + // Continue indicates continue executing the rest of the steps irrespective of the container exit code + Continue OnErrorType = "continue" +) + // StepOutputConfig stores configuration for a step output stream. type StepOutputConfig struct { // Path to duplicate stdout stream to on container's local filesystem. diff --git a/pkg/apis/pipeline/v1/openapi_generated.go b/pkg/apis/pipeline/v1/openapi_generated.go index 68ff2fbfadc..bd457b8eded 100644 --- a/pkg/apis/pipeline/v1/openapi_generated.go +++ b/pkg/apis/pipeline/v1/openapi_generated.go @@ -1774,7 +1774,7 @@ func schema_pkg_apis_pipeline_v1_Step(ref common.ReferenceCallback) common.OpenA }, "onError": { SchemaProps: spec.SchemaProps{ - Description: "OnError defines the exiting behavior of a container on error can be set to [ continue | stopAndFail ] 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", + Description: "OnError defines the exiting behavior of a container on error can be set to [ continue | stopAndFail ]", Type: []string{"string"}, Format: "", }, diff --git a/pkg/apis/pipeline/v1/swagger.json b/pkg/apis/pipeline/v1/swagger.json index c8b07a721fa..4180dc28a33 100644 --- a/pkg/apis/pipeline/v1/swagger.json +++ b/pkg/apis/pipeline/v1/swagger.json @@ -872,7 +872,7 @@ "default": "" }, "onError": { - "description": "OnError defines the exiting behavior of a container on error can be set to [ continue | stopAndFail ] 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", + "description": "OnError defines the exiting behavior of a container on error can be set to [ continue | stopAndFail ]", "type": "string" }, "resources": { diff --git a/pkg/apis/pipeline/v1/task_validation.go b/pkg/apis/pipeline/v1/task_validation.go index 532f0db606f..96dafd32b37 100644 --- a/pkg/apis/pipeline/v1/task_validation.go +++ b/pkg/apis/pipeline/v1/task_validation.go @@ -242,7 +242,7 @@ func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.Fi } if s.OnError != "" { - if s.OnError != "continue" && s.OnError != "stopAndFail" { + if s.OnError != Continue && s.OnError != StopAndFail { errs = errs.Also(&apis.FieldError{ Message: fmt.Sprintf("invalid value: %v", s.OnError), Paths: []string{"onError"}, diff --git a/pkg/apis/pipeline/v1/task_validation_test.go b/pkg/apis/pipeline/v1/task_validation_test.go index 3895b520bc8..a830e52b860 100644 --- a/pkg/apis/pipeline/v1/task_validation_test.go +++ b/pkg/apis/pipeline/v1/task_validation_test.go @@ -1389,14 +1389,14 @@ func TestStepOnError(t *testing.T) { }{{ name: "valid step - valid onError usage - set to continue - alpha API", steps: []v1.Step{{ - OnError: "continue", + OnError: v1.Continue, Image: "image", Args: []string{"arg"}, }}, }, { name: "valid step - valid onError usage - set to stopAndFail - alpha API", steps: []v1.Step{{ - OnError: "stopAndFail", + OnError: v1.StopAndFail, Image: "image", Args: []string{"arg"}, }}, diff --git a/pkg/apis/pipeline/v1beta1/container_conversion.go b/pkg/apis/pipeline/v1beta1/container_conversion.go index d6ed1f60cb4..51826057c54 100644 --- a/pkg/apis/pipeline/v1beta1/container_conversion.go +++ b/pkg/apis/pipeline/v1beta1/container_conversion.go @@ -28,7 +28,7 @@ func (s Step) convertTo(ctx context.Context, sink *v1.Step) { w.convertTo(ctx, &new) sink.Workspaces = append(sink.Workspaces, new) } - sink.OnError = s.OnError + sink.OnError = (v1.OnErrorType)(s.OnError) sink.StdoutConfig = (*v1.StepOutputConfig)(s.StdoutConfig) sink.StderrConfig = (*v1.StepOutputConfig)(s.StderrConfig) @@ -59,7 +59,7 @@ func (s *Step) convertFrom(ctx context.Context, source v1.Step) { new.convertFrom(ctx, w) s.Workspaces = append(s.Workspaces, new) } - s.OnError = source.OnError + s.OnError = (OnErrorType)(source.OnError) s.StdoutConfig = (*StepOutputConfig)(source.StdoutConfig) s.StderrConfig = (*StepOutputConfig)(source.StderrConfig) } diff --git a/pkg/apis/pipeline/v1beta1/container_types.go b/pkg/apis/pipeline/v1beta1/container_types.go index a01a2a9abee..624a1c373f5 100644 --- a/pkg/apis/pipeline/v1beta1/container_types.go +++ b/pkg/apis/pipeline/v1beta1/container_types.go @@ -188,9 +188,7 @@ type Step struct { // OnError defines the exiting behavior of a container on error // can be set to [ continue | stopAndFail ] - // 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"` + OnError OnErrorType `json:"onError,omitempty"` // Stores configuration for the stdout stream of the step. // +optional @@ -200,6 +198,16 @@ type Step struct { StderrConfig *StepOutputConfig `json:"stderrConfig,omitempty"` } +// OnErrorType defines a list of supported exiting behavior of a container on error +type OnErrorType string + +const ( + // StopAndFail indicates exit the taskRun if the container exits with non-zero exit code + StopAndFail OnErrorType = "stopAndFail" + // Continue indicates continue executing the rest of the steps irrespective of the container exit code + Continue OnErrorType = "continue" +) + // StepOutputConfig stores configuration for a step output stream. type StepOutputConfig struct { // Path to duplicate stdout stream to on container's local filesystem. diff --git a/pkg/apis/pipeline/v1beta1/openapi_generated.go b/pkg/apis/pipeline/v1beta1/openapi_generated.go index b3a3b67f2f2..091553ab276 100644 --- a/pkg/apis/pipeline/v1beta1/openapi_generated.go +++ b/pkg/apis/pipeline/v1beta1/openapi_generated.go @@ -3368,7 +3368,7 @@ func schema_pkg_apis_pipeline_v1beta1_Step(ref common.ReferenceCallback) common. }, "onError": { SchemaProps: spec.SchemaProps{ - Description: "OnError defines the exiting behavior of a container on error can be set to [ continue | stopAndFail ] 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", + Description: "OnError defines the exiting behavior of a container on error can be set to [ continue | stopAndFail ]", Type: []string{"string"}, Format: "", }, diff --git a/pkg/apis/pipeline/v1beta1/swagger.json b/pkg/apis/pipeline/v1beta1/swagger.json index b1d3c3c0acf..25109ac371d 100644 --- a/pkg/apis/pipeline/v1beta1/swagger.json +++ b/pkg/apis/pipeline/v1beta1/swagger.json @@ -1822,7 +1822,7 @@ "default": "" }, "onError": { - "description": "OnError defines the exiting behavior of a container on error can be set to [ continue | stopAndFail ] 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", + "description": "OnError defines the exiting behavior of a container on error can be set to [ continue | stopAndFail ]", "type": "string" }, "ports": { diff --git a/pkg/apis/pipeline/v1beta1/task_conversion_test.go b/pkg/apis/pipeline/v1beta1/task_conversion_test.go index fa0816d3740..de0ce94e925 100644 --- a/pkg/apis/pipeline/v1beta1/task_conversion_test.go +++ b/pkg/apis/pipeline/v1beta1/task_conversion_test.go @@ -95,7 +95,7 @@ func TestTaskConversion(t *testing.T) { Script: "echo hello", Timeout: &metav1.Duration{Duration: time.Hour}, Workspaces: []v1beta1.WorkspaceUsage{{Name: "workspace"}}, - OnError: "continue", + OnError: v1beta1.Continue, StdoutConfig: &v1beta1.StepOutputConfig{Path: "/path"}, StderrConfig: &v1beta1.StepOutputConfig{Path: "/another-path"}, }}, diff --git a/pkg/apis/pipeline/v1beta1/task_validation.go b/pkg/apis/pipeline/v1beta1/task_validation.go index 35edc70f3e0..aa2c2387ed5 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation.go +++ b/pkg/apis/pipeline/v1beta1/task_validation.go @@ -243,9 +243,8 @@ func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.Fi } } - // validate static values in onError if specified - onError can only be set to continue or stopAndFail if s.OnError != "" { - if !isParamRefs(s.OnError) && s.OnError != "continue" && s.OnError != "stopAndFail" { + if !isParamRefs(string(s.OnError)) && s.OnError != Continue && s.OnError != StopAndFail { errs = errs.Also(&apis.FieldError{ Message: fmt.Sprintf("invalid value: %v", s.OnError), Paths: []string{"onError"}, @@ -603,7 +602,7 @@ func validateStepVariables(ctx context.Context, step Step, prefix string, vars s errs = errs.Also(validateTaskVariable(v.MountPath, prefix, vars).ViaField("MountPath").ViaFieldIndex("volumeMount", i)) errs = errs.Also(validateTaskVariable(v.SubPath, prefix, vars).ViaField("SubPath").ViaFieldIndex("volumeMount", i)) } - errs = errs.Also(validateTaskVariable(step.OnError, prefix, vars).ViaField("onError")) + errs = errs.Also(validateTaskVariable(string(step.OnError), prefix, vars).ViaField("onError")) return errs } diff --git a/pkg/apis/pipeline/v1beta1/task_validation_test.go b/pkg/apis/pipeline/v1beta1/task_validation_test.go index 5114b5cdfaa..835f0c3d3a2 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/task_validation_test.go @@ -1501,14 +1501,14 @@ func TestStepOnError(t *testing.T) { }{{ name: "valid step - valid onError usage - set to continue", steps: []v1beta1.Step{{ - OnError: "continue", + OnError: v1beta1.Continue, Image: "image", Args: []string{"arg"}, }}, }, { name: "valid step - valid onError usage - set to stopAndFail", steps: []v1beta1.Step{{ - OnError: "stopAndFail", + OnError: v1beta1.StopAndFail, Image: "image", Args: []string{"arg"}, }}, @@ -1516,7 +1516,7 @@ func TestStepOnError(t *testing.T) { name: "valid step - valid onError usage - set to a task parameter", params: []v1beta1.ParamSpec{{ Name: "CONTINUE", - Default: &v1beta1.ArrayOrString{Type: v1beta1.ParamTypeString, StringVal: "continue"}, + Default: &v1beta1.ArrayOrString{Type: v1beta1.ParamTypeString, StringVal: string(v1beta1.Continue)}, }}, steps: []v1beta1.Step{{ OnError: "$(params.CONTINUE)", diff --git a/pkg/container/step_replacements.go b/pkg/container/step_replacements.go index 846b12b00fe..1640e749ce9 100644 --- a/pkg/container/step_replacements.go +++ b/pkg/container/step_replacements.go @@ -24,7 +24,7 @@ import ( // ApplyStepReplacements applies variable interpolation on a Step. func ApplyStepReplacements(step *v1beta1.Step, stringReplacements map[string]string, arrayReplacements map[string][]string) { step.Script = substitution.ApplyReplacements(step.Script, stringReplacements) - step.OnError = substitution.ApplyReplacements(step.OnError, stringReplacements) + step.OnError = (v1beta1.OnErrorType)(substitution.ApplyReplacements(string(step.OnError), stringReplacements)) if step.StdoutConfig != nil { step.StdoutConfig.Path = substitution.ApplyReplacements(step.StdoutConfig.Path, stringReplacements) } diff --git a/pkg/pod/entrypoint.go b/pkg/pod/entrypoint.go index e1e57d4ad98..7be9863f54e 100644 --- a/pkg/pod/entrypoint.go +++ b/pkg/pod/entrypoint.go @@ -28,7 +28,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/entrypoint" "gomodules.xyz/jsonpatch/v2" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -138,11 +137,11 @@ func orderContainers(commonExtraEntrypointArgs []string, steps []corev1.Containe if taskSpec != nil { if taskSpec.Steps != nil && len(taskSpec.Steps) >= i+1 { if taskSpec.Steps[i].OnError != "" { - if taskSpec.Steps[i].OnError != entrypoint.ContinueOnError && taskSpec.Steps[i].OnError != entrypoint.FailOnError { + if taskSpec.Steps[i].OnError != v1beta1.Continue && taskSpec.Steps[i].OnError != v1beta1.StopAndFail { return nil, fmt.Errorf("task step onError must be either %s or %s but it is set to an invalid value %s", - entrypoint.ContinueOnError, entrypoint.FailOnError, taskSpec.Steps[i].OnError) + v1beta1.Continue, v1beta1.StopAndFail, taskSpec.Steps[i].OnError) } - argsForEntrypoint = append(argsForEntrypoint, "-on_error", taskSpec.Steps[i].OnError) + argsForEntrypoint = append(argsForEntrypoint, "-on_error", string(taskSpec.Steps[i].OnError)) } if taskSpec.Steps[i].Timeout != nil { argsForEntrypoint = append(argsForEntrypoint, "-timeout", taskSpec.Steps[i].Timeout.Duration.String()) diff --git a/pkg/pod/entrypoint_test.go b/pkg/pod/entrypoint_test.go index fd6a8370287..c1309f637d8 100644 --- a/pkg/pod/entrypoint_test.go +++ b/pkg/pod/entrypoint_test.go @@ -24,7 +24,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/entrypoint" "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -358,9 +357,9 @@ func TestEntryPointOnError(t *testing.T) { }{{ taskSpec: v1beta1.TaskSpec{ Steps: []v1beta1.Step{{ - OnError: entrypoint.ContinueOnError, + OnError: v1beta1.Continue, }, { - OnError: entrypoint.FailOnError, + OnError: v1beta1.StopAndFail, }}, }, wantContainers: []corev1.Container{{