-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TEP-0050] Convert Step OnError from string to "OnErrorType" type #5322
[TEP-0050] Convert Step OnError from string to "OnErrorType" type #5322
Conversation
Skipping CI for Draft Pull Request. |
d76c726
to
15b4e2a
Compare
/kind cleanup |
/test all |
15b4e2a
to
b2c75e2
Compare
/test all |
b2c75e2
to
52b0712
Compare
/retest |
52b0712
to
24e9d96
Compare
/retest |
78afa44
to
cba79bf
Compare
/retest |
/retest pull-tekton-pipeline-unit-tests |
@QuanZhang-William: The
The following commands are available to trigger optional jobs:
Use In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/retest |
1 similar comment
/retest |
41fd8eb
to
ca8e5b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM! Just one change I think we should make.
Prior to this commit, the step onError field is defined as normal string and the 2 supported string values "continue" and "stopAndFail" are directly used across the codebase. This is error-prone and it introduces maintenance difficulty. This commit updates the onError field to be typed string "OnErrorType", with constants defined for the 2 supported values, and updates all the related references
92386df
to
7ba5090
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Maybe adding a release note?
My understanding of a Release Note is to notify users about a behaviour change. There is actually no change from the user's perspective and there is nothing to "notify" (since we already have the OnError input validation before this PR). This is more like a "clean up " work. I don't think a Release Note is necessary in this case? |
Good catch @Yongxuanzhang! - This should be called out as a breaking change to the API - this will cause build failures for clients if they were previously using the string based type, i.e. s := "asdf"
v1beta1.Step{
OnError: s,
} |
// 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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we added support for variables in addition to the two constants - #5307
steps[].onError: $(params.CONTINUE)
steps[].onError: continue
steps[].onError: stopAndFail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @pritidesai, thanks for letting me know. Was wondering if there is any concern when using variables with "OnErrorType". We will eventually parse the variable to a real value here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How?
I haven't reviewed the code changes in this PR. I am not sure how can it be restricted to the type of enum
(continue
and stopAndFail
) when it can have a parameter of type string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also what I found interesting that enum
is not that restricted in Go, even with a Typed string OnErrorType
you can still do something like
// the value is properly set to step.OnError even if it is not defined in enum
step.OnError = "this is undefined value in enum OnErrorType"
So there is essentially no difference between a regular string or a typed string OnErrorType
when calling ApplyReplacement function other than some type casting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you @QuanZhang-William for all the efforts but declaring onError
to as enum
but allowing it to specify variables sounds very confusing. If we are declaring a field as enum, it will be simpler and easier to follow if it's restricted to the specified enum values.
I suggest keeping the type to string
, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pritidesai I am not sure I follow here ? The type
is still string
, as OnErrorType
is still just an alias to a string. There is no concept of enum
in Go anyway 🙃. Also, this is the exact same thing with a lot of other types we are using (in status, …), it is mainly useful for developer and consumer of the go library to use a predefined set of values, it doesn't do much more than this.
Ohh, got what you mean. I didn't think about that Tekton can be used in this way programmatically. Will update the Release Note in this case |
Mainly the |
// 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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pritidesai I am not sure I follow here ? The type
is still string
, as OnErrorType
is still just an alias to a string. There is no concept of enum
in Go anyway 🙃. Also, this is the exact same thing with a lot of other types we are using (in status, …), it is mainly useful for developer and consumer of the go library to use a predefined set of values, it doesn't do much more than this.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vdemeester, wlynch The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
I was a little surprised to discover this was merged while going over the release notes for 0.39 🤔
|
From a API consumer point of view, nothing changes, it's still "just a string" nothing else. 99% of users of Tekton won't read code, just docs, and |
thank you @vdemeester for being patient here, appreciate it 🙏 I don't know how are these interpreted - https://tekton.dev/docs/pipelines/pipeline-api/#tekton.dev/v1.Step This API doc has listed The source for this doc is here - https://github.com/tektoncd/pipeline/blob/main/docs/pipeline-api.md#tekton.dev/v1.Step |
Thanks for your feedback @pritidesai! The The string value "continue" and "stopAndFail" are being directly used across the codebase and it is in general not a good practice. We can also benefit a better compile time check from such typed string, for example, I think we can keep the |
https://tekton.dev/docs/pipelines/variables/#fields-that-accept-variable-substitutions already lists |
Yeah, I agree it should be sufficient in this case :) |
Changes
Prior to this commit, the
step.OnError
field is defined as string and the 2 supported string values "continue" and "stopAndFail" are directly used across the codebase. This is error-prone and it introduces maintenance difficulty. This commit updates theOnError
field to be typed stringOnErrorType
, with constants defined for the 2 supported values, and updates all the related referencesSubmitter Checklist
As the author of this PR, please check off the items in this checklist:
functionality, content, code)
/kind <type>
. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tepRelease Notes