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-0076] Add indexing into array for taskrun params reference #5132

Merged

Conversation

Yongxuanzhang
Copy link
Member

@Yongxuanzhang Yongxuanzhang commented Jul 13, 2022

Changes

This commit provides the indexing into array for params and gated by
alpha feature flag. Before this commit we can only refer to the whole
array for taskrun params, with this feature we can refer to array's element such as
$(params.param-name[0]).

/kind feature

Submitter Checklist

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

  • Has Docs included if any changes are user facing
  • 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)
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

Indexing into array for taskrun params is now an alpha feature, element of array params can be accessed via $(params.param-name[i]).

@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. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 13, 2022
@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 13, 2022
@Yongxuanzhang
Copy link
Member Author

/kind feature

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Jul 13, 2022
@Yongxuanzhang Yongxuanzhang force-pushed the param-array-indexing-taskrun branch 2 times, most recently from 2f5fda9 to 082d60c Compare July 13, 2022 22:01
@@ -58,6 +59,12 @@ func ApplyParameters(spec *v1beta1.TaskSpec, tr *v1beta1.TaskRun, defaults ...v1
switch p.Default.Type {
case v1beta1.ParamTypeArray:
for _, pattern := range patterns {
// array indexing for param is alpha feature
Copy link
Member

Choose a reason for hiding this comment

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

out of scope for this PR, but these two for loops have a lot of duplicate code that could be consolidated.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, we can also refactor the code in pipelinerun as well

@@ -353,3 +369,200 @@ func missingKeysofObjectResults(tr *v1beta1.TaskRun, specResults []v1beta1.TaskR
}
return findMissingKeys(neededKeys, providedKeys)
}

func validateParamArrayIndex(ctx context.Context, params []v1beta1.Param, spec *v1beta1.TaskSpec) error {
Copy link
Member

Choose a reason for hiding this comment

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

this block of code looks extremely similar to what was introduced in the pipelinerun reconciler. Can any of it be moved to a common location?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes! I was thinking if we want to merge the results code from taskrun and pipelinerun into one pkg then they can share functions like this.

Right now I'm not so sure where can I put it. Maybe pkg/reconciler/resources.go ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh but this function is different, the one in pipelinerun will traverse all pipelinespec fields and this is to traverse TaskSpec, another function extractParamIndex is the same and can be merged

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if you're referring to extractParamIndex here or extractParamIndexes in the PR reconciler but either way yes they could be pulled out. I'd create a new package pkg/params and put it there in a separate PR

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, so maybe this is part of our refactoring work later?

Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with this for now, but typically I'd caution against saving refactoring work for after a feature is implemented. I don't think the changes I'm suggesting will take much time.

@Yongxuanzhang Yongxuanzhang marked this pull request as ready for review July 14, 2022 14:35
@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 Jul 14, 2022
@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/reconciler/taskrun/resources/apply.go 99.2% 99.3% 0.0
pkg/reconciler/taskrun/taskrun.go 80.9% 80.3% -0.6
pkg/reconciler/taskrun/validate_resources.go 96.2% 94.6% -1.5

@Yongxuanzhang
Copy link
Member Author

@ywluogg

@Yongxuanzhang
Copy link
Member Author

#4723

@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/reconciler/taskrun/resources/apply.go 99.2% 99.3% 0.0
pkg/reconciler/taskrun/taskrun.go 80.9% 80.3% -0.6
pkg/reconciler/taskrun/validate_resources.go 96.2% 94.6% -1.5

This commit provides the indexing into array for params and gated by
alpha feature flag. Before this commit we can only refer to the whole
array for taskrun params, with this feature we can refer to array's element such as
$(params.param-name[0]).
@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/reconciler/taskrun/resources/apply.go 99.2% 99.3% 0.0
pkg/reconciler/taskrun/taskrun.go 80.9% 80.3% -0.6
pkg/reconciler/taskrun/validate_resources.go 96.2% 97.7% 1.5

@ywluogg
Copy link
Contributor

ywluogg commented Jul 14, 2022

/assign @ywluogg

@@ -353,3 +369,200 @@ func missingKeysofObjectResults(tr *v1beta1.TaskRun, specResults []v1beta1.TaskR
}
return findMissingKeys(neededKeys, providedKeys)
}

func validateParamArrayIndex(ctx context.Context, params []v1beta1.Param, spec *v1beta1.TaskSpec) error {
Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with this for now, but typically I'd caution against saving refactoring work for after a feature is implemented. I don't think the changes I'm suggesting will take much time.

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lbernick

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 Jul 14, 2022
@ywluogg
Copy link
Contributor

ywluogg commented Jul 14, 2022

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 14, 2022
@Yongxuanzhang
Copy link
Member Author

/retest

2 similar comments
@Yongxuanzhang
Copy link
Member Author

/retest

@Yongxuanzhang
Copy link
Member Author

/retest

@Yongxuanzhang
Copy link
Member Author

/retest-required

3 similar comments
@Yongxuanzhang
Copy link
Member Author

/retest-required

@Yongxuanzhang
Copy link
Member Author

/retest-required

@Yongxuanzhang
Copy link
Member Author

/retest-required

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.

5 participants