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

Task, ClusterTask and Pipeline auto-conversion from v1alpha1 to v1alpha2 🎋 #2002

Merged
merged 4 commits into from
Feb 11, 2020

Conversation

vdemeester
Copy link
Member

@vdemeester vdemeester commented Feb 5, 2020

Changes

This adds:

  • auto-conversion methods and tests for Task types in v1alpha1
    and v1alpha2. In order to reduce the number of duplicated fields, we
    are using v1alpha2.TaskSpec embedded in v1alpha1.TaskSpec so that both
    types are compatible.
  • auto-conversion methods and tests for ClusterTask
  • auto-conversion methods and tests for Pipeline

/cc @sbwsg @bobcatfish @afrittoli

Signed-off-by: Vincent Demeester [email protected]

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

@tekton-robot tekton-robot requested review from afrittoli, bobcatfish and a user February 5, 2020 11:19
@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Feb 5, 2020
@tekton-robot tekton-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Feb 5, 2020
switch sink := obj.(type) {
case *v1alpha2.Pipeline:
sink.ObjectMeta = source.ObjectMeta
return nil // source.Spec.ConvertUp(ctx, &sink.Spec)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a placeholder 👼 I needed to define at least 2 Convertible types to some tests 😝

@@ -46,6 +45,8 @@ func (t *Task) Copy() TaskInterface {

// TaskSpec defines the desired state of Task.
type TaskSpec struct {
v1alpha2.TaskSpec `json:",inline"`
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not required per-se, it just simplify the conversion using embedded struct and it doesn't change on the api side (except user of the go library)

Copy link
Member Author

Choose a reason for hiding this comment

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

If you look at Pipeline, it is not using embedding as we can't really do that (same task field targeting different type)

Copy link

Choose a reason for hiding this comment

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

aha, so this is how TaskSpec.ConvertDown is able to copy into the v1alpha1.Params and Resources fields?

👍

@vdemeester vdemeester force-pushed the v1alpha2-auto-conversion branch from 15a7bd5 to f71d174 Compare February 5, 2020 11:26
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/pipeline_conversion.go Do not exist 0.0%
pkg/apis/pipeline/v1alpha2/task_conversion.go Do not exist 100.0%

@vdemeester vdemeester force-pushed the v1alpha2-auto-conversion branch from f71d174 to eb8a6f2 Compare February 5, 2020 11:55
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/pipeline_conversion.go Do not exist 0.0%
pkg/apis/pipeline/v1alpha2/task_conversion.go Do not exist 100.0%

@vdemeester vdemeester force-pushed the v1alpha2-auto-conversion branch from eb8a6f2 to 5371f99 Compare February 5, 2020 14:08
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/pipeline_conversion.go Do not exist 0.0%
pkg/apis/pipeline/v1alpha2/task_conversion.go Do not exist 100.0%

@vdemeester vdemeester force-pushed the v1alpha2-auto-conversion branch from 90e16b2 to 71fc0d5 Compare February 5, 2020 15:21
@vdemeester vdemeester changed the title Task auto-conversion from v1alpha1 to v1alpha2 🎋 Task and Pipeline auto-conversion from v1alpha1 to v1alpha2 🎋 Feb 5, 2020
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/pipeline_conversion.go Do not exist 0.0%
pkg/apis/pipeline/v1alpha2/task_conversion.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/pipeline_conversion.go Do not exist 0.0%
pkg/apis/pipeline/v1alpha2/task_conversion.go Do not exist 100.0%

sink.Resources = &v1alpha2.TaskResources{}
}
if len(source.Inputs.Resources) > 0 && source.Resources != nil && len(source.Resources.Inputs) > 0 {
// This shouldn't happen as it shouldn't pass validation but just in case
Copy link

Choose a reason for hiding this comment

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

👍

// This shouldn't happen as it shouldn't pass validation but just in case
return apis.ErrMultipleOneOf("inputs.resources", "resources.inputs")
}
sink.Resources.Inputs = make([]v1alpha2.TaskResource, len(source.Inputs.Resources))
Copy link

Choose a reason for hiding this comment

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

🎉

@@ -46,6 +45,8 @@ func (t *Task) Copy() TaskInterface {

// TaskSpec defines the desired state of Task.
type TaskSpec struct {
v1alpha2.TaskSpec `json:",inline"`
Copy link

Choose a reason for hiding this comment

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

aha, so this is how TaskSpec.ConvertDown is able to copy into the v1alpha1.Params and Resources fields?

👍

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbwsg

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 Feb 5, 2020
@ghost
Copy link

ghost commented Feb 5, 2020

I don't totally understand the need for v1alpha1 ConvertDown funcs. What is their use?

@vdemeester
Copy link
Member Author

I don't totally understand the need for v1alpha1 ConvertDown funcs. What is their use?

I did write about this in the initial pull request #1529 :

  • Only one version of the CRD can be stored, so v1alpha1 is the one
    stored
  • All the version of the CRD must be schema compatible (before 1.16)
    • v1alpha1 gets all the fields, meaning :
      • the new ones (from v1alpha2, …)
      • the old deprecated ones (that will be removed from v1alpha2)
    • we may only document the "frozen" v1alpha1 field (and not the
      new one that are coming from the other api versions)

The main reason to ConvertDown is because we do store it in v1alpha1. So if a user send a v1alpha1 struct, it will convert it up and down, to be v1alpha2 but still stored as a v1alpha1 struct (kinda).

@vdemeester vdemeester force-pushed the v1alpha2-auto-conversion branch from 71fc0d5 to dbe103c Compare February 6, 2020 09:01
@vdemeester vdemeester changed the title Task and Pipeline auto-conversion from v1alpha1 to v1alpha2 🎋 Task, ClusterTask and Pipeline auto-conversion from v1alpha1 to v1alpha2 🎋 Feb 6, 2020
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/cluster_task_conversion.go Do not exist 100.0%
pkg/apis/pipeline/v1alpha2/pipeline_conversion.go Do not exist 100.0%
pkg/apis/pipeline/v1alpha2/task_conversion.go Do not exist 100.0%

@vdemeester vdemeester force-pushed the v1alpha2-auto-conversion branch from dbe103c to 01901bd Compare February 6, 2020 09:42
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/cluster_task_conversion.go Do not exist 100.0%
pkg/apis/pipeline/v1alpha2/pipeline_conversion.go Do not exist 100.0%
pkg/apis/pipeline/v1alpha2/task_conversion.go Do not exist 100.0%

@ghost
Copy link

ghost commented Feb 6, 2020

I did write about this in the initial pull request #1529 :

👼

The main reason to ConvertDown is because we do store it in v1alpha1. So if a user send a v1alpha1 struct, it will convert it up and down, to be v1alpha2 but still stored as a v1alpha1 struct (kinda).

🤯 Brilliant. Thanks!

@chmouel
Copy link
Member

chmouel commented Feb 6, 2020

the golang ci test is fallaciously green since it is actually failing but exit 0

0206 09:56:42.536] ===============================
I0206 09:56:42.536] ==== RUNNING GOLANGCI-LINT ====
I0206 09:56:42.536] ===============================
I0206 09:57:44.392] level=warning msg="[runner] Can't run linter goanalysis_metalinter: ctrlflow: failed prerequisites: [email protected]/tektoncd/pipeline/pkg/artifacts [github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1.test]"

This seems a recurring errors in golang-ci which i have updated the bug with our issue in here :

golangci/golangci-lint#827 (comment)

@vdemeester vdemeester force-pushed the v1alpha2-auto-conversion branch from 01901bd to 50cf5e7 Compare February 6, 2020 13:59
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/cluster_task_conversion.go Do not exist 100.0%
pkg/apis/pipeline/v1alpha2/pipeline_conversion.go Do not exist 100.0%
pkg/apis/pipeline/v1alpha2/task_conversion.go Do not exist 100.0%

@vdemeester vdemeester force-pushed the v1alpha2-auto-conversion branch from 50cf5e7 to 1c2273e Compare February 7, 2020 14:24
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/cluster_task_conversion.go Do not exist 100.0%
pkg/apis/pipeline/v1alpha2/pipeline_conversion.go Do not exist 100.0%
pkg/apis/pipeline/v1alpha2/task_conversion.go Do not exist 100.0%

@vdemeester
Copy link
Member Author

/test pull-tekton-pipeline-integration-tests

@ernado
Copy link

ernado commented Feb 8, 2020

Hey, can you please check what actual golangci version are you using?
I suspect that is something like v1.21, but there is already v1.23.3 with important fixes.

@vdemeester
Copy link
Member Author

Hey, can you please check what actual golangci version are you using?
I suspect that is something like v1.21, but there is already v1.23.3 with important fixes.

See tektoncd/plumbing#216 👼

@chmouel
Copy link
Member

chmouel commented Feb 11, 2020

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 11, 2020
This adds auto-conversion methods and tests for Task types in v1alpha1
and v1alpha2. In order to reduce the number of duplicated fields, we
are using v1alpha2.TaskSpec embedded in v1alpha1.TaskSpec so that both
types are compatible.

Signed-off-by: Vincent Demeester <[email protected]>
This adds auto-conversion methods and tests for Pipeline types in v1alpha1
and v1alpha2.

Signed-off-by: Vincent Demeester <[email protected]>
This adds auto-conversion methods and tests for ClusterTask types in
v1alpha1 and v1alpha2.

Signed-off-by: Vincent Demeester <[email protected]>
The main reason is to not run into error forcing us to use the same
receiver name for all function. The receiver name are different for a
good reason.

Signed-off-by: Vincent Demeester <[email protected]>
@vdemeester vdemeester force-pushed the v1alpha2-auto-conversion branch from 1c2273e to 620c476 Compare February 11, 2020 09:53
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Feb 11, 2020
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha2/cluster_task_conversion.go Do not exist 100.0%
pkg/apis/pipeline/v1alpha2/pipeline_conversion.go Do not exist 100.0%
pkg/apis/pipeline/v1alpha2/task_conversion.go Do not exist 100.0%

@chmouel
Copy link
Member

chmouel commented Feb 11, 2020

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 11, 2020
@tekton-robot tekton-robot merged commit 94d18e6 into tektoncd:master Feb 11, 2020
@vdemeester vdemeester deleted the v1alpha2-auto-conversion branch February 11, 2020 10:23
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. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants