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

Add SetDefaults for pipelineSpec in reconciler #5176

Merged
merged 1 commit into from
Jul 26, 2022

Conversation

Yongxuanzhang
Copy link
Member

@Yongxuanzhang Yongxuanzhang commented Jul 20, 2022

Changes

This commit adds SetDefaults for pipelineSpec in reconciler
after it is fetched from cluster. This is to avoid failing the resources that
are not mutated and add default values.

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

NONE

@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. release-note-none Denotes a PR that doesnt merit a release note. labels Jul 20, 2022
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 20, 2022
@Yongxuanzhang
Copy link
Member Author

/kind bug

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 20, 2022
@Yongxuanzhang Yongxuanzhang marked this pull request as ready for review July 20, 2022 15:40
@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 20, 2022
@tekton-robot tekton-robot requested a review from abayer July 20, 2022 15:40
@Yongxuanzhang
Copy link
Member Author

#5175

@Yongxuanzhang
Copy link
Member Author

Yongxuanzhang commented Jul 20, 2022

@jerop @dibyom

@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 97.5% 97.5% 0.0

@afrittoli afrittoli added the needs-cherry-pick Indicates a PR needs to be cherry-pick to a release branch label Jul 20, 2022
@abayer
Copy link
Contributor

abayer commented Jul 20, 2022

/retest

@@ -274,6 +274,10 @@ func ValidateParameterTypes(ctx context.Context, params []ParamSpec) (errs *apis

// ValidateType checks that the type of a ParamSpec is allowed and its default value matches that type
func (p ParamSpec) ValidateType() *apis.FieldError {
// For resources not call SetDefaults(), empty type should be valid.
Copy link
Member

Choose a reason for hiding this comment

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

NIT - suggested comment

A resource may have been created before type was available in paramSpec and thus have no type set

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!

Copy link
Member

Choose a reason for hiding this comment

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

couldn't we call SetDefaults() before calling validation instead of just skipping validation?

Copy link
Member Author

@Yongxuanzhang Yongxuanzhang Jul 20, 2022

Choose a reason for hiding this comment

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

couldn't we call SetDefaults() before calling validation instead of just skipping validation?

yeah I would prefer this way! I'm testing if that can work

Copy link
Member

Choose a reason for hiding this comment

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

(or at least in this function, we should assume no type == defaultType)

@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 97.5% 97.5% 0.0
pkg/apis/pipeline/v1beta1/task_validation.go 97.7% 97.7% 0.0

@abayer
Copy link
Contributor

abayer commented Jul 20, 2022

/retest

@@ -274,6 +274,10 @@ func ValidateParameterTypes(ctx context.Context, params []ParamSpec) (errs *apis

// ValidateType checks that the type of a ParamSpec is allowed and its default value matches that type
func (p ParamSpec) ValidateType() *apis.FieldError {
// For resources not call SetDefaults(), empty type should be valid.
if p.Type == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a unit test in pipeline reconciler that the param type is null, to make sure this wouldn't introduce any new bugs? Thanks

Comment on lines 474 to 477
if err := ts.Validate(context.Background()); err != nil {
t.Errorf("TaskSpec.Validate() = %v", err)
}
})
Copy link
Member

Choose a reason for hiding this comment

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

In the test, can we compare the returned v.s. expected error like this example rather than just check if err is nil?

@Yongxuanzhang
Copy link
Member Author

/hold

@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 Jul 20, 2022
@abayer
Copy link
Contributor

abayer commented Jul 20, 2022

It's worth mentioning that when I deleted a problem Pipeline and recreated it, with any of kubectl replace, kubectl apply, or kubectl create, params without types specified still had no types specified. This is with Pipeline v0.37.2. So if the current behavior, before this PR, is supposed to be defaulting newly created Pipelines and Tasks to have default types on their params, well, that's not working either.

@chuangw6
Copy link
Member

It's worth mentioning that when I deleted a problem Pipeline and recreated it, with any of kubectl replace, kubectl apply, or kubectl create, params without types specified still had no types specified. This is with Pipeline v0.37.2. So if the current behavior, before this PR, is supposed to be defaulting newly created Pipelines and Tasks to have default types on their params, well, that's not working either.

Hi @abayer,
I tried the following yaml (the type of param arg and mystring is not specified) with v0.37.2 and it works fine. Can you also try that? If this example works, let's find what are the missing/different part in the problem pipeline.

kind: Task
apiVersion: tekton.dev/v1beta1
metadata:
  name: test-task
spec:
  params:
    - name: arg
  steps:
    - name: echo
      image: bash:latest
      args: ["echo", "$(params.arg)"]
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: test-pipeline
spec:
  params:
    - name: mystring
  tasks:
    - name: echo-test
      params:
        - name: arg
          value: $(params.mystring)
      taskRef:
        name: test-task
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  generateName: test-pipeline-run
spec:
  params:
    - name: mystring
      value: abc.com
  pipelineRef:
    name: test-pipeline

@abayer
Copy link
Contributor

abayer commented Jul 20, 2022

Ok, turns out the problem was incredibly stupid and specific - in the default namespace on the dogfooding cluster, we had webhooks.knative.dev/exclude: "true" in the labels, so it was skipping defaulting entirely. 🤦

@ywluogg
Copy link
Contributor

ywluogg commented Jul 20, 2022

Ok, turns out the problem was incredibly stupid and specific - in the default namespace on the dogfooding cluster, we had webhooks.knative.dev/exclude: "true" in the labels, so it was skipping defaulting entirely. 🤦

🤦🤦🤦

@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/pipelinerun/pipelinerun.go 85.8% 85.9% 0.0
pkg/reconciler/taskrun/taskrun.go 80.3% 80.4% 0.1

@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/pipelinerun/pipelinerun.go 85.8% 85.9% 0.0
pkg/reconciler/taskrun/taskrun.go 80.3% 80.4% 0.1

@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/pipelinerun/pipelinerun.go 85.8% 85.9% 0.0
pkg/reconciler/taskrun/taskrun.go 80.3% 80.4% 0.1

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 21, 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/pipelinerun/pipelinerun.go 85.8% 85.9% 0.0
pkg/reconciler/taskrun/taskrun.go 80.3% 80.4% 0.1

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'm a bit confused about what this PR is doing given the original PR message and the conversation that's happened. It looks like this sets defaults in the reconciler to ensure that defaults are applied to resources that were created before these code changes were applied to the server. Is this still an issue with params without types, disregarding the annotations that were mistakenly kept around on our dogfooding cluster?

@@ -565,6 +565,7 @@ spec:
serviceAccountName: test-sa
taskRef:
name: unit-test-task
kind: Task
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason to add kind: Task to all of these taskRefs?

Copy link
Member Author

Choose a reason for hiding this comment

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

setdefaults will add kind for task as well, if not adding them the current tests will fail

@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/pipelinerun/pipelinerun.go 85.8% 85.9% 0.0
pkg/reconciler/taskrun/taskrun.go 80.3% 80.4% 0.1

@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/pipelinerun/pipelinerun.go 85.8% 85.9% 0.0

@Yongxuanzhang
Copy link
Member Author

Yongxuanzhang commented Jul 21, 2022

I'm a bit confused about what this PR is doing given the original PR message and the conversation that's happened. It looks like this sets defaults in the reconciler to ensure that defaults are applied to resources that were created before these code changes were applied to the server.

Yes, that's the goal

Is this still an issue with params without types, disregarding the annotations that were mistakenly kept around on our dogfooding cluster?

There are some other discussions in this issue #5175. And for taskrun when we get the taskspec, it will call taskSpec.SetDefaults(ctx),

case taskRun.Spec.TaskRef != nil && taskRun.Spec.TaskRef.Name != "":
// Get related task for taskrun
t, err := getTask(ctx, taskRun.Spec.TaskRef.Name)
if err != nil {
return nil, nil, fmt.Errorf("error when listing tasks for taskRun %s: %w", taskRun.Name, err)
}
taskMeta = t.TaskMetadata()
taskSpec = t.TaskSpec()
taskSpec.SetDefaults(ctx)
case taskRun.Spec.TaskSpec != nil:

but for pipelinerun we don't have it. It may make sense to add for pipelinerun as well
case pipelineRun.Spec.PipelineRef != nil && pipelineRun.Spec.PipelineRef.Name != "":
// Get related pipeline for pipelinerun
t, err := getPipeline(ctx, pipelineRun.Spec.PipelineRef.Name)
if err != nil {
return nil, nil, fmt.Errorf("error when listing pipelines for pipelineRun %s: %w", pipelineRun.Name, err)
}
pipelineMeta = t.PipelineMetadata()
pipelineSpec = t.PipelineSpec()
case pipelineRun.Spec.PipelineSpec != nil:

@Yongxuanzhang Yongxuanzhang changed the title Param without types should not fail validation Add SetDefaults for pipelineSpec in reconciler Jul 21, 2022
This commit adds SetDefaults for pipelineSpec in reconciler
after they are fetched. This is to avoid failing the resources that
are not mutated to add default values.
@Yongxuanzhang
Copy link
Member Author

/retest

@vdemeester
Copy link
Member

but for pipelinerun we don't have it. It may make sense to add for pipelinerun as well

indeed that's probably a mistake, it should be there for pipelinerun as well.

@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 22, 2022
@Yongxuanzhang
Copy link
Member Author

/hold cancel

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

ywluogg commented Jul 26, 2022

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 26, 2022
@tekton-robot tekton-robot merged commit 475a562 into tektoncd:main Jul 26, 2022
abayer pushed a commit to abayer/tektoncd-pipeline that referenced this pull request Jul 26, 2022
Cherry-picked from tektoncd#5176

This commit adds SetDefaults for pipelineSpec in reconciler
after they are fetched. This is to avoid failing the resources that
are not mutated to add default values.

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
tekton-robot pushed a commit that referenced this pull request Jul 26, 2022
Cherry-picked from #5176

This commit adds SetDefaults for pipelineSpec in reconciler
after they are fetched. This is to avoid failing the resources that
are not mutated to add default values.

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
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/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. needs-cherry-pick Indicates a PR needs to be cherry-pick to a release branch release-note-none Denotes a PR that doesnt merit a release note. 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.

9 participants