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-0075: More flexible ways to provide values for object param keys #5427

Merged
merged 1 commit into from
Sep 12, 2022

Conversation

chuangw6
Copy link
Member

@chuangw6 chuangw6 commented Sep 2, 2022

Changes

Closes #5270.

Prior to this change, if users want to provide default value for an
object param, they have to provide values for ALL keys, but can't provide
values for a subset of required keys that are declared in properties
section. Same restriction applies to the value provided from run level.

In this PR, we relax the validation for object param keys to allow users
to provide values for an object param in a more flexible way i.e. a subset
of keys are provided in the spec's default, and the rest of the keys are
provided in run level's value.

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

More flexible ways to provide values for object param keys: a subset of keys can be provided from default, and the rest is provided at runtime.

@tekton-robot tekton-robot added 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 2, 2022
@chuangw6
Copy link
Member Author

chuangw6 commented Sep 2, 2022

/kind feature

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 2, 2022
@chuangw6
Copy link
Member Author

chuangw6 commented Sep 2, 2022

cc @lbernick @wlynch @chitrangpatel @ywluogg @Yongxuanzhang
please take a look thanks!

@chuangw6 chuangw6 changed the title TEP-0075: Relax object param key validation TEP-0075: More flexible ways to provide values for object param keys Sep 2, 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/apis/pipeline/v1beta1/task_validation.go 98.1% 98.0% -0.1
pkg/reconciler/taskrun/validate_resources.go 97.7% 98.1% 0.4

@lbernick lbernick self-assigned this Sep 5, 2022
@afrittoli
Copy link
Member

/test check-pr-has-kind-label

@tekton-robot
Copy link
Collaborator

@afrittoli: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test pull-tekton-pipeline-alpha-integration-tests
  • /test pull-tekton-pipeline-build-tests
  • /test pull-tekton-pipeline-integration-tests
  • /test tekton-pipeline-unit-tests

The following commands are available to trigger optional jobs:

  • /test pull-tekton-pipeline-go-coverage

Use /test all to run all jobs.

In response to this:

/test check-pr-has-kind-label

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.

@afrittoli
Copy link
Member

Thank you @chuangw6 - could you please provide release notes for this feature, and check the submitter checklist?

@chuangw6 chuangw6 force-pushed the relax-object-param-validation branch from 189bb11 to d850ab8 Compare September 6, 2022 11:30
@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 Sep 6, 2022
@chuangw6
Copy link
Member Author

chuangw6 commented Sep 6, 2022

Thank you @chuangw6 - could you please provide release notes for this feature, and check the submitter checklist?

Added! Thanks @afrittoli !

@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/task_validation.go 98.0% 97.8% -0.1
pkg/apis/pipeline/v1beta1/task_validation.go 98.1% 98.0% -0.1
pkg/reconciler/taskrun/validate_resources.go 97.7% 98.1% 0.4

@chuangw6
Copy link
Member Author

chuangw6 commented Sep 6, 2022

/retest

Copy link
Member

@lbernick lbernick left a comment

Choose a reason for hiding this comment

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

I think this is actually two separate changes:

  1. if default is provided for all keys, the values from the run will be merged with the defaults
  2. the default does not have to be provided for all keys

Is it clear that we want both of these features?
We might also want to update tep 75 before merging this

@@ -686,27 +686,6 @@ func TestTaskSpecValidateError(t *testing.T) {
Message: fmt.Sprintf("The value type specified for these keys %v is invalid", []string{"key1"}),
Paths: []string{"params.task.properties"},
},
}, {
name: "keys defined in properties are missed in default",
Copy link
Member

Choose a reason for hiding this comment

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

let's keep this test case around but just have it result in a successful 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.

Sounds great! Done. Thanks @lbernick

Copy link
Member

Choose a reason for hiding this comment

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

I think you might not have pushed these changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's under the valid test cases called valid params type explicit and the param name is myobjWithDefaultPartialKeys.

@chuangw6
Copy link
Member Author

chuangw6 commented Sep 6, 2022

> * if default is provided for all keys, the values from the run will be merged with the defaults

Can you elaborate a bit on what merge means in case default is provided for all keys? @lbernick

@chuangw6 chuangw6 force-pushed the relax-object-param-validation branch from d850ab8 to 3b7ba03 Compare September 6, 2022 22:14
@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/task_validation.go 98.0% 97.8% -0.1
pkg/apis/pipeline/v1beta1/task_validation.go 98.1% 98.0% -0.1
pkg/reconciler/taskrun/validate_resources.go 97.7% 98.1% 0.4

@chuangw6
Copy link
Member Author

chuangw6 commented Sep 7, 2022

  1. the default does not have to be provided for all keys

Not only for default but also the value provided on the taskrun level. Both of them do not have to be provided for all keys. (Prior, the validation enforces that they have to provide values for all keys if they provide value for the object param.)

  1. if default is provided for all keys, the values from the run will be merged with the defaults

This is true. But I'd think this as the implication of that both default and taskrun do not need to provide value for all keys of an object param.

Currently tep75 says "If a value is provided for the param, the default will not be used (i.e. there will be no behavior to merge the default with the provided value, if for example the provided value specified some fields but not others).". If we do not have the merge behaviour, what will happen is that the keys missed at taskrun value will have empty value even though the default provides the value for these keys, which I think probably is a bit unintuitive.

For example, and object param named foo has two keys key1 and key2. The default provides value for both keys (i.e. "default1" for key1, and "default2" for key2), but at taskrun level, only the value of key1 is provided (i.e. "value-runtime").

  • Without merging behaviour, the resolved object will have "value-runtime" as the value of key1, but empty value for key2.
  • With merging behaviour, the resolved object will have "value-runtime" as the value of key1, and "default2" as the value of key2.

Is it clear that we want both of these features? We might also want to update tep 75 before merging this

IMHO, the 2nd case might make more sense, but I am open to the discussion here. And I agree that we need to update the tep before merging this.

@lbernick
Copy link
Member

lbernick commented Sep 7, 2022

Thanks for the response @chuangw6!

Let's say we start with not requiring the default to specify all keys. In order for this to be useful, we will either need the merge behavior (so that unspecified defaults can be provided at runtime), or we will need to allow object keys to be optional. Probably both!

We could start with just the merge behavior, but still require the default to specify all keys. There's definitely some examples where this could be useful, e.g. a git object param with a default url like the example you have in this PR.

In the example you provided, without merging behavior, one of the keys would not be set, and the taskrun would fail because we don't support optional keys, correct? Merging behavior would be backwards incompatible in the sense that this would no longer fail, but because we don't support optional keys we don't need to provide a mechanism to "unset" a key at runtime.

I think we might want to start with just the merge behavior to avoid getting into optional vs required keys, WDYT?

@chuangw6
Copy link
Member Author

chuangw6 commented Sep 7, 2022

I think we might want to start with just the merge behavior to avoid getting into optional vs required keys, WDYT?

Starting with merge behaviour to avoid optional v.s. required keys SGTM!

but still require the default to specify all keys.

But it seems to me that default does not have to specify all keys, which is not related to optional/required keys. Currently, the tep proposed that all keys specified in properties are required. Therefore, in the following example, an error will be thrown because we find out that neither taskrun or default provides a value for the required key commit.

apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  generateName: object-param-test-
spec:
  params:
    - name: gitrepo
      value:
        url: "xyz.com"
  taskSpec:
    params:
      - name: gitrepo
        properties:
          url: {}
          commit: {}
        default:
          url: "default.com"

If the above example provides the value (i.e. "sha123") for key commit at taskrun, this would be valid and resolved object param gitrepo will be like {url:"xyz.com", commit:"sha123"}.

@lbernick lbernick mentioned this pull request Sep 8, 2022
7 tasks
@lbernick
Copy link
Member

lbernick commented Sep 8, 2022

ok -- I'm convinced that this doesn't require optional keys and isn't backwards incompatible (because we were previously requiring the taskrun to provide a value for all keys if it overrode the default)

@@ -686,27 +686,6 @@ func TestTaskSpecValidateError(t *testing.T) {
Message: fmt.Sprintf("The value type specified for these keys %v is invalid", []string{"key1"}),
Paths: []string{"params.task.properties"},
},
}, {
name: "keys defined in properties are missed in default",
Copy link
Member

Choose a reason for hiding this comment

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

I think you might not have pushed these changes?

pkg/reconciler/taskrun/validate_resources_test.go Outdated Show resolved Hide resolved
@chuangw6
Copy link
Member Author

chuangw6 commented Sep 8, 2022

ok -- I'm convinced that this doesn't require optional keys and isn't backwards incompatible (because we were previously requiring the taskrun to provide a value for all keys if it overrode the default)

Correct. Now taskrun can still provide a value for all keys, but they don't have to as long as default provides a value for the keys that are missed at tasrkun.

@chuangw6 chuangw6 force-pushed the relax-object-param-validation branch from 3b7ba03 to 868bd21 Compare September 9, 2022 15:56
@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/task_validation.go 98.0% 97.8% -0.1
pkg/apis/pipeline/v1beta1/task_validation.go 98.1% 98.0% -0.1
pkg/reconciler/taskrun/validate_resources.go 97.7% 98.1% 0.4

@chuangw6 chuangw6 force-pushed the relax-object-param-validation branch from 868bd21 to e83ade5 Compare September 9, 2022 16:09
Related to tektoncd#5270.

Prior to this change, if users want to provide default value for an
object param, they have to provide values for ALL keys, but can't provide
values for a subset of required keys that are declared in `properties`
section. Same restriction applies to the `value` provided from run level.

In this PR, we relax the validation for object param keys to allow users
to provide values for an object param in a more flexible way i.e. a subset
of keys are provided in the spec's default, and the rest of the keys are
provided in run level's value.

Signed-off-by: Chuang Wang <[email protected]>
@chuangw6 chuangw6 force-pushed the relax-object-param-validation branch from e83ade5 to 8e17261 Compare September 9, 2022 16:12
@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/task_validation.go 98.0% 97.8% -0.1
pkg/apis/pipeline/v1beta1/task_validation.go 98.1% 98.0% -0.1
pkg/reconciler/taskrun/validate_resources.go 97.7% 98.1% 0.4

@chuangw6 chuangw6 requested review from lbernick and removed request for pritidesai and jerop September 9, 2022 16:25
chuangw6 added a commit to chuangw6/community that referenced this pull request Sep 9, 2022
related to tektoncd/pipeline#5427.

Prior to this update, merge behaviour was not allowed between `default` and
run level value for object keys.

In that proposal and the implementation pr, we allow the merge behaviour
to happen to give users more flexible ways to provide values for object
param as long as all keys are provided with a value at runtime (combination
of the values provided from default and run level value).

Signed-off-by: Chuang Wang <[email protected]>
chuangw6 added a commit to chuangw6/community that referenced this pull request Sep 9, 2022
related to tektoncd/pipeline#5427.

Prior to this update, merge behaviour was not allowed between `default` and
run level value for object keys.

In that proposal and the implementation pr, we allow the merge behaviour
to happen to give users more flexible ways to provide values for object
param as long as all keys are provided with a value at runtime (combination
of the values provided from default and run level value).

Signed-off-by: Chuang Wang <[email protected]>
@chuangw6
Copy link
Member Author

chuangw6 commented Sep 9, 2022

I also updated the tep tektoncd/community#817. Please take a look @lbernick. Thanks!

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 9, 2022
chuangw6 added a commit to chuangw6/community that referenced this pull request Sep 9, 2022
related to tektoncd/pipeline#5427.

Prior to this update, merge behaviour was not allowed between `default` and
run level value for object keys.

In that proposal and the implementation pr, we allow the merge behaviour
to happen to give users more flexible ways to provide values for object
param as long as all keys are provided with a value at runtime (combination
of the values provided from default and run level value).

Signed-off-by: Chuang Wang <[email protected]>
chuangw6 added a commit to chuangw6/community that referenced this pull request Sep 9, 2022
related to tektoncd/pipeline#5427.

Prior to this update, merge behaviour was not allowed between `default` and
run level value for object keys.

In that proposal and the implementation pr, we allow the merge behaviour
to happen to give users more flexible ways to provide values for object
param as long as all keys are provided with a value at runtime (combination
of the values provided from default and run level value).

Signed-off-by: Chuang Wang <[email protected]>
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lbernick, vdemeester

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:
  • OWNERS [lbernick,vdemeester]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

}

// ValidateObjectKeys validates if object keys defined in properties are all provided in its value provider iff the provider is not nil.
func ValidateObjectKeys(properties map[string]PropertySpec, propertiesProvider *ParamValue) (errs *apis.FieldError) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah can you leave this function as is? I'm planning to use it in Chains. I think initially you are making this function public because I need to do keys comparisons in Chains, is it?

Copy link
Contributor

@ywluogg ywluogg Sep 12, 2022

Choose a reason for hiding this comment

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

Oh NVM because you are not using this function anymore in Pipeline, I will create this one in Chains then. Please ignore the previous commnent

Copy link
Contributor

@ywluogg ywluogg left a comment

Choose a reason for hiding this comment

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

/lgtm

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

/test pull-tekton-pipeline-integration-tests

@tekton-robot tekton-robot merged commit 80fc393 into tektoncd:main Sep 12, 2022
@chuangw6
Copy link
Member Author

Tep 75 was updated to reflect the change as well. tektoncd/community#817

tekton-robot pushed a commit to tektoncd/community that referenced this pull request Sep 15, 2022
related to tektoncd/pipeline#5427.

Prior to this update, merge behaviour was not allowed between `default` and
run level value for object keys.

In that proposal and the implementation pr, we allow the merge behaviour
to happen to give users more flexible ways to provide values for object
param as long as all keys are provided with a value at runtime (combination
of the values provided from default and run level value).

Signed-off-by: Chuang Wang <[email protected]>
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More flexible way to provide value for object keys
6 participants