Skip to content
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-0144] Add enum API field #7289

Merged
merged 1 commit into from
Nov 2, 2023

Conversation

QuanZhang-William
Copy link
Member

@QuanZhang-William QuanZhang-William commented Oct 26, 2023

Changes

Part of #7270. In TEP-0144 we proposed a new enum field to support built-in param input validation.

This commit adds the Enum api field, validation and conversion logic.

/kind feature

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

[WIP] Add `Enum` API field

@tekton-robot
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@tekton-robot tekton-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Oct 26, 2023
@tekton-robot tekton-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 26, 2023
@QuanZhang-William
Copy link
Member Author

/test all

@QuanZhang-William
Copy link
Member Author

QuanZhang-William commented Oct 26, 2023

/hold until #7279 is merged.

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 26, 2023
@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 26, 2023
@QuanZhang-William
Copy link
Member Author

/test all

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/config/feature_flags.go 94.1% 94.2% 0.1
pkg/apis/pipeline/v1/param_types.go 98.4% 98.5% 0.1
pkg/apis/pipeline/v1/pipeline_validation.go 99.2% 99.2% 0.0
pkg/apis/pipeline/v1/task_validation.go 97.3% 97.3% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 98.7% 98.8% 0.1
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.0% 99.0% 0.0
pkg/apis/pipeline/v1beta1/task_validation.go 97.3% 97.3% 0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/config/feature_flags.go 94.1% 94.2% 0.1
pkg/apis/pipeline/v1/param_types.go 98.4% 98.5% 0.1
pkg/apis/pipeline/v1/pipeline_validation.go 99.2% 99.2% 0.0
pkg/apis/pipeline/v1/task_validation.go 97.3% 97.3% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 98.7% 98.8% 0.1
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.0% 99.0% 0.0
pkg/apis/pipeline/v1beta1/task_validation.go 97.3% 97.3% 0.0

@QuanZhang-William
Copy link
Member Author

/test pull-tekton-pipeline-build-tests

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/config/feature_flags.go 94.1% 94.2% 0.1
pkg/apis/pipeline/v1/param_types.go 98.4% 98.5% 0.1
pkg/apis/pipeline/v1/pipeline_validation.go 99.2% 99.2% 0.0
pkg/apis/pipeline/v1/task_validation.go 97.3% 97.3% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 98.7% 98.8% 0.1
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.0% 99.0% 0.0
pkg/apis/pipeline/v1beta1/task_validation.go 97.3% 97.3% 0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/config/feature_flags.go 94.1% 94.2% 0.1
pkg/apis/pipeline/v1/param_types.go 98.4% 98.5% 0.1
pkg/apis/pipeline/v1/pipeline_validation.go 99.2% 99.2% 0.0
pkg/apis/pipeline/v1/task_validation.go 97.3% 97.3% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 98.7% 98.8% 0.1
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.0% 99.0% 0.0
pkg/apis/pipeline/v1beta1/task_validation.go 97.3% 97.3% 0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 98.4% 98.5% 0.1
pkg/apis/pipeline/v1/pipeline_validation.go 99.2% 99.2% 0.0
pkg/apis/pipeline/v1/task_validation.go 98.1% 98.2% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 98.7% 98.8% 0.1
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.0% 99.0% 0.0
pkg/apis/pipeline/v1beta1/task_validation.go 98.2% 98.2% 0.0

@QuanZhang-William QuanZhang-William marked this pull request as ready for review October 27, 2023 20:59
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 27, 2023
@QuanZhang-William
Copy link
Member Author

/hold cancel
#7279 is merged.

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 27, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 98.4% 98.5% 0.1
pkg/apis/pipeline/v1/pipeline_validation.go 99.2% 99.2% 0.0
pkg/apis/pipeline/v1/task_validation.go 98.1% 98.2% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 98.7% 98.8% 0.1
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.0% 99.0% 0.0
pkg/apis/pipeline/v1beta1/task_validation.go 98.2% 98.2% 0.0

@Yongxuanzhang
Copy link
Member

/assign

continue
}
if !config.FromContextOrDefaults(ctx).FeatureFlags.EnableParamEnum {
errs = errs.Also(errs, apis.ErrGeneric(fmt.Sprintf("feature flag `%s` should be set to true to use Enum", config.EnableParamEnum), "").ViaFieldKey("params", p.Name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding ViaFieldKey("params", ...) for every check here, why not just do

ViaFieldKey(p.Name) and where you call validateParamEnums call
errs = errs.Also(params.validateParamEnums(ctx).ViaField("params"))?

func ValidatePipelineParameterVariables(ctx context.Context, tasks []PipelineTask, params ParamSpecs) (errs *apis.FieldError) {
// validates all the types within a slice of ParamSpecs
errs = errs.Also(ValidateParameterTypes(ctx, params).ViaField("params"))
errs = errs.Also(params.validateNoDuplicateNames())
errs = errs.Also(params.validateParamEnums(ctx))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errs = errs.Also(params.validateParamEnums(ctx).ViaField("params"))? And in the checks there, call ViaFieldKey(p.Name)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated (and for all comments below), PTAL!

@@ -435,6 +435,7 @@ func (p ParamSpec) ValidateObjectType(ctx context.Context) *apis.FieldError {
func ValidateParameterVariables(ctx context.Context, steps []Step, params ParamSpecs) *apis.FieldError {
var errs *apis.FieldError
errs = errs.Also(params.validateNoDuplicateNames())
errs = errs.Also(params.validateParamEnums(ctx))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above related to ViaField.

}
if !config.FromContextOrDefaults(ctx).FeatureFlags.EnableParamEnum {
errs = errs.Also(errs, apis.ErrGeneric(fmt.Sprintf("feature flag `%s` should be set to true to use Enum", config.EnableParamEnum), "").ViaFieldKey("params", p.Name))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment related to ViaFieldKey

func ValidatePipelineParameterVariables(ctx context.Context, tasks []PipelineTask, params ParamSpecs) (errs *apis.FieldError) {
// validates all the types within a slice of ParamSpecs
errs = errs.Also(ValidateParameterTypes(ctx, params).ViaField("params"))
errs = errs.Also(params.validateNoDuplicateNames())
errs = errs.Also(params.validateParamEnums(ctx))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment related to ViaField

@@ -441,6 +441,7 @@ func (p ParamSpec) ValidateObjectType(ctx context.Context) *apis.FieldError {
func ValidateParameterVariables(ctx context.Context, steps []Step, params ParamSpecs) *apis.FieldError {
var errs *apis.FieldError
errs = errs.Also(params.validateNoDuplicateNames())
errs = errs.Also(params.validateParamEnums(ctx))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment related to ViaField

Copy link
Member

@chitrangpatel chitrangpatel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments. Otherwise lgtm!

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 98.4% 98.5% 0.1
pkg/apis/pipeline/v1/pipeline_validation.go 99.2% 99.2% 0.0
pkg/apis/pipeline/v1/task_validation.go 98.1% 98.2% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 98.7% 98.8% 0.1
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.0% 99.0% 0.0
pkg/apis/pipeline/v1beta1/task_validation.go 98.2% 98.2% 0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 98.4% 98.5% 0.1
pkg/apis/pipeline/v1/pipeline_validation.go 99.2% 99.2% 0.0
pkg/apis/pipeline/v1/task_validation.go 98.1% 98.2% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 98.7% 98.8% 0.1
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.0% 99.0% 0.0
pkg/apis/pipeline/v1beta1/task_validation.go 98.2% 98.2% 0.0

@QuanZhang-William
Copy link
Member Author

/assign

Thanks @Yongxuanzhang! Could you please take a look when you get a chance 🙏 ?

Copy link
Member

@Yongxuanzhang Yongxuanzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks the test cases are duplicate in pipeline and task, could be a followup cleanup to merge the tests? I'm not sure 😄

@@ -2254,3 +2254,86 @@ func TestGetArrayIndexParamRefs(t *testing.T) {
})
}
}

func TestParamEnum(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better separate this to success and failure like tests in pipeline validation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've splitted the tests, PTAL!

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Yongxuanzhang

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 1, 2023
@QuanZhang-William
Copy link
Member Author

looks the test cases are duplicate in pipeline and task, could be a followup cleanup to merge the tests? I'm not sure 😄

Yeah I see the confusion. I think it "looks like a duplicate" is because pipeline_validaiton.go and task_validation.go have their own exported ValidatePipelineParameterVariables() function (and they look similar, but they are testing different things). And accordingly to our policy, I think I do need to cover changes in both exported functions.

Part of [tektoncd#7270][tektoncd#7270]. In [TEP-0144][tep-0144] we proposed a new `enum` field to support built-in param input validation.

This commit adds the `Enum` api field, validation and conversion logic.

/kind feature

[tektoncd#7270]: tektoncd#7270
[tep-0144]: https://github.com/tektoncd/community/blob/main/teps/0144-param-enum.md
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 98.4% 98.5% 0.1
pkg/apis/pipeline/v1/pipeline_validation.go 99.2% 99.2% 0.0
pkg/apis/pipeline/v1/task_validation.go 98.1% 98.2% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 98.7% 98.8% 0.1
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.0% 99.0% 0.0
pkg/apis/pipeline/v1beta1/task_validation.go 98.2% 98.2% 0.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1/param_types.go 98.4% 98.5% 0.1
pkg/apis/pipeline/v1/pipeline_validation.go 99.2% 99.2% 0.0
pkg/apis/pipeline/v1/task_validation.go 98.1% 98.2% 0.0
pkg/apis/pipeline/v1beta1/param_types.go 98.7% 98.8% 0.1
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.0% 99.0% 0.0
pkg/apis/pipeline/v1beta1/task_validation.go 98.2% 98.2% 0.0

@QuanZhang-William
Copy link
Member Author

/retest

@chitrangpatel
Copy link
Member

Thanks @QuanZhang-William
/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 2, 2023
@tekton-robot tekton-robot merged commit 8fd372f into tektoncd:main Nov 2, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants