Skip to content

Commit 3600fe0

Browse files
committed
Migrate PipelineResource in there own package… 📦
This is mainly done to separate the `PipelineResource` from the rest of the API *and* remove the dependency cycle that we get by keeping `PipelineResource` in alpha. This update the code generation to generate a different set of clients, informers, clientsets, … for `resource`, although it is exposed in the same apiGroup. Signed-off-by: Vincent Demeester <[email protected]>
1 parent 74bf8b8 commit 3600fe0

File tree

72 files changed

+1781
-1991
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1781
-1991
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ run:
44
skip-dirs:
55
- vendor
66
- pkg/client/clientset/(.*)/fake
7+
- pkg/client/resource/clientset/(.*)/fake
78
timeout: 5m
89
linters-settings:
910
errcheck:

cmd/webhook/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ func main() {
9898
}
9999
resourceHandlers := map[schema.GroupVersionKind]webhook.GenericCRD{
100100
v1alpha1.SchemeGroupVersion.WithKind("Pipeline"): &v1alpha1.Pipeline{},
101-
v1alpha1.SchemeGroupVersion.WithKind("PipelineResource"): &v1alpha1.PipelineResource{},
102101
v1alpha1.SchemeGroupVersion.WithKind("Task"): &v1alpha1.Task{},
103102
v1alpha1.SchemeGroupVersion.WithKind("ClusterTask"): &v1alpha1.ClusterTask{},
104103
v1alpha1.SchemeGroupVersion.WithKind("TaskRun"): &v1alpha1.TaskRun{},
105104
v1alpha1.SchemeGroupVersion.WithKind("PipelineRun"): &v1alpha1.PipelineRun{},
106105
v1alpha1.SchemeGroupVersion.WithKind("Condition"): &v1alpha1.Condition{},
106+
v1alpha1.SchemeGroupVersion.WithKind("PipelineResource"): &v1alpha1.PipelineResource{},
107107
}
108108

109109
resourceAdmissionController := webhook.NewResourceAdmissionController(resourceHandlers, options, true)

hack/update-codegen.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ set -o pipefail
2020

2121
source $(dirname $0)/../vendor/github.com/tektoncd/plumbing/scripts/library.sh
2222

23+
OLDGOFLAGS="${GOFLAGS:-}"
24+
GOFLAGS="-mod=vendor"
2325
# generate the code with:
2426
# --output-base because this script should also be able to run inside the vendor dir of
2527
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
2628
# instead of the $GOPATH directly. For normal projects this can be dropped.
27-
29+
bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" \
30+
github.com/tektoncd/pipeline/pkg/client/resource github.com/tektoncd/pipeline/pkg/apis \
31+
"resource:v1alpha1" \
32+
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
2833
bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" \
2934
github.com/tektoncd/pipeline/pkg/client github.com/tektoncd/pipeline/pkg/apis \
3035
"pipeline:v1alpha1,v1alpha2" \
@@ -37,10 +42,15 @@ ${GOPATH}/bin/deepcopy-gen \
3742
-i github.com/tektoncd/pipeline/pkg/apis/config
3843

3944
# Knative Injection
45+
bash ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \
46+
github.com/tektoncd/pipeline/pkg/client/resource github.com/tektoncd/pipeline/pkg/apis \
47+
"resource:v1alpha1" \
48+
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
4049
bash ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \
4150
github.com/tektoncd/pipeline/pkg/client github.com/tektoncd/pipeline/pkg/apis \
4251
"pipeline:v1alpha1,v1alpha2" \
4352
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
53+
GOFLAGS="${OLDGOFLAGS}"
4454

4555
# Make sure our dependencies are up-to-date
4656
${REPO_ROOT_DIR}/hack/update-deps.sh

pkg/apis/pipeline/v1alpha1/param_types.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ import (
2525
// or PipelineRun.
2626
type ParamSpec = v1alpha2.ParamSpec
2727

28-
// ResourceParam declares a string value to use for the parameter called Name, and is used in
29-
// the specific context of PipelineResources.
30-
type ResourceParam = v1alpha2.ResourceParam
31-
3228
// Param declares an ArrayOrString to use for the parameter called name.
3329
type Param = v1alpha2.Param
3430

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Copyright 2019 The Tekton Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
21+
)
22+
23+
// PipelineResourceType represents the type of endpoint the pipelineResource is, so that the
24+
// controller will know this pipelineResource should be fetched and optionally what
25+
// additional metatdata should be provided for it.
26+
type PipelineResourceType = resource.PipelineResourceType
27+
28+
var (
29+
AllowedOutputResources = resource.AllowedOutputResources
30+
)
31+
32+
const (
33+
// PipelineResourceTypeGit indicates that this source is a GitHub repo.
34+
PipelineResourceTypeGit PipelineResourceType = resource.PipelineResourceTypeGit
35+
36+
// PipelineResourceTypeStorage indicates that this source is a storage blob resource.
37+
PipelineResourceTypeStorage PipelineResourceType = resource.PipelineResourceTypeStorage
38+
39+
// PipelineResourceTypeImage indicates that this source is a docker Image.
40+
PipelineResourceTypeImage PipelineResourceType = resource.PipelineResourceTypeImage
41+
42+
// PipelineResourceTypeCluster indicates that this source is a k8s cluster Image.
43+
PipelineResourceTypeCluster PipelineResourceType = resource.PipelineResourceTypeCluster
44+
45+
// PipelineResourceTypePullRequest indicates that this source is a SCM Pull Request.
46+
PipelineResourceTypePullRequest PipelineResourceType = resource.PipelineResourceTypePullRequest
47+
48+
// PipelineResourceTypeCloudEvent indicates that this source is a cloud event URI
49+
PipelineResourceTypeCloudEvent PipelineResourceType = resource.PipelineResourceTypeCloudEvent
50+
)
51+
52+
// AllResourceTypes can be used for validation to check if a provided Resource type is one of the known types.
53+
var AllResourceTypes = resource.AllResourceTypes
54+
55+
// PipelineResource describes a resource that is an input to or output from a
56+
// Task.
57+
//
58+
type PipelineResource = resource.PipelineResource
59+
60+
// PipelineResourceSpec defines an individual resources used in the pipeline.
61+
type PipelineResourceSpec = resource.PipelineResourceSpec
62+
63+
// SecretParam indicates which secret can be used to populate a field of the resource
64+
type SecretParam = resource.SecretParam
65+
66+
// ResourceParam declares a string value to use for the parameter called Name, and is used in
67+
// the specific context of PipelineResources.
68+
type ResourceParam = resource.ResourceParam
69+
70+
// ResourceDeclaration defines an input or output PipelineResource declared as a requirement
71+
// by another type such as a Task or Condition. The Name field will be used to refer to these
72+
// PipelineResources within the type's definition, and when provided as an Input, the Name will be the
73+
// path to the volume mounted containing this PipelineResource as an input (e.g.
74+
// an input Resource named `workspace` will be mounted at `/workspace`).
75+
type ResourceDeclaration = resource.ResourceDeclaration
76+
77+
// PipelineResourceList contains a list of PipelineResources
78+
type PipelineResourceList = resource.PipelineResourceList

pkg/apis/pipeline/v1alpha1/resource_types.go

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,8 @@ import (
2222
"github.com/google/go-cmp/cmp"
2323
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
2424
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha2"
25-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2625
)
2726

28-
// PipelineResourceType represents the type of endpoint the pipelineResource is, so that the
29-
// controller will know this pipelineResource should be fetched and optionally what
30-
// additional metatdata should be provided for it.
31-
type PipelineResourceType = v1alpha2.PipelineResourceType
32-
33-
var (
34-
AllowedOutputResources = v1alpha2.AllowedOutputResources
35-
)
36-
37-
const (
38-
// PipelineResourceTypeGit indicates that this source is a GitHub repo.
39-
PipelineResourceTypeGit PipelineResourceType = v1alpha2.PipelineResourceTypeGit
40-
41-
// PipelineResourceTypeStorage indicates that this source is a storage blob resource.
42-
PipelineResourceTypeStorage PipelineResourceType = v1alpha2.PipelineResourceTypeStorage
43-
44-
// PipelineResourceTypeImage indicates that this source is a docker Image.
45-
PipelineResourceTypeImage PipelineResourceType = v1alpha2.PipelineResourceTypeImage
46-
47-
// PipelineResourceTypeCluster indicates that this source is a k8s cluster Image.
48-
PipelineResourceTypeCluster PipelineResourceType = v1alpha2.PipelineResourceTypeCluster
49-
50-
// PipelineResourceTypePullRequest indicates that this source is a SCM Pull Request.
51-
PipelineResourceTypePullRequest PipelineResourceType = v1alpha2.PipelineResourceTypePullRequest
52-
53-
// PipelineResourceTypeCloudEvent indicates that this source is a cloud event URI
54-
PipelineResourceTypeCloudEvent PipelineResourceType = v1alpha2.PipelineResourceTypeCloudEvent
55-
)
56-
57-
// AllResourceTypes can be used for validation to check if a provided Resource type is one of the known types.
58-
var AllResourceTypes = v1alpha2.AllResourceTypes
59-
6027
// PipelineResourceInterface interface to be implemented by different PipelineResource types
6128
type PipelineResourceInterface interface {
6229
// GetName returns the name of this PipelineResource instance.
@@ -132,51 +99,6 @@ func ApplyTaskModifier(ts *TaskSpec, tm TaskModifier) error {
13299
return nil
133100
}
134101

135-
// SecretParam indicates which secret can be used to populate a field of the resource
136-
type SecretParam struct {
137-
FieldName string `json:"fieldName"`
138-
SecretKey string `json:"secretKey"`
139-
SecretName string `json:"secretName"`
140-
}
141-
142-
// PipelineResourceSpec defines an individual resources used in the pipeline.
143-
type PipelineResourceSpec struct {
144-
Type PipelineResourceType `json:"type"`
145-
Params []ResourceParam `json:"params"`
146-
// Secrets to fetch to populate some of resource fields
147-
// +optional
148-
SecretParams []SecretParam `json:"secrets,omitempty"`
149-
}
150-
151-
// +genclient
152-
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
153-
// +genclient:noStatus
154-
155-
// PipelineResource describes a resource that is an input to or output from a
156-
// Task.
157-
//
158-
// +k8s:openapi-gen=true
159-
type PipelineResource struct {
160-
metav1.TypeMeta `json:",inline"`
161-
// +optional
162-
metav1.ObjectMeta `json:"metadata,omitempty"`
163-
164-
// Spec holds the desired state of the PipelineResource from the client
165-
Spec PipelineResourceSpec `json:"spec,omitempty"`
166-
167-
// Status is deprecated.
168-
// It usually is used to communicate the observed state of the PipelineResource from
169-
// the controller, but was unused as there is no controller for PipelineResource.
170-
// +optional
171-
Status *PipelineResourceStatus `json:"status,omitempty"`
172-
}
173-
174-
// PipelineResourceStatus does not contain anything because PipelineResources on their own
175-
// do not have a status
176-
// Deprecated
177-
type PipelineResourceStatus struct {
178-
}
179-
180102
// PipelineResourceBinding connects a reference to an instance of a PipelineResource
181103
// with a PipelineResource dependency that the Pipeline has declared
182104
type PipelineResourceBinding struct {
@@ -203,23 +125,6 @@ type PipelineResourceResult struct {
203125
ResourceRef PipelineResourceRef `json:"resourceRef,omitempty"`
204126
}
205127

206-
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
207-
208-
// PipelineResourceList contains a list of PipelineResources
209-
type PipelineResourceList struct {
210-
metav1.TypeMeta `json:",inline"`
211-
// +optional
212-
metav1.ListMeta `json:"metadata,omitempty"`
213-
Items []PipelineResource `json:"items"`
214-
}
215-
216-
// ResourceDeclaration defines an input or output PipelineResource declared as a requirement
217-
// by another type such as a Task or Condition. The Name field will be used to refer to these
218-
// PipelineResources within the type's definition, and when provided as an Input, the Name will be the
219-
// path to the volume mounted containing this PipelineResource as an input (e.g.
220-
// an input Resource named `workspace` will be mounted at `/workspace`).
221-
type ResourceDeclaration = v1alpha2.ResourceDeclaration
222-
223128
// ResourceFromType returns an instance of the correct PipelineResource object type which can be
224129
// used to add input and output containers as well as volumes to a TaskRun's pod in order to realize
225130
// a PipelineResource in a pod.

pkg/apis/pipeline/v1alpha1/storage_resource.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ import (
2121
"strings"
2222

2323
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
24+
resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
2425
corev1 "k8s.io/api/core/v1"
2526
)
2627

2728
type PipelineResourceStorageType string
2829

2930
const (
3031
// PipelineResourceTypeGCS is the subtype for the GCSResources, which is backed by a GCS blob/directory.
31-
PipelineResourceTypeGCS PipelineResourceType = "gcs"
32+
PipelineResourceTypeGCS PipelineResourceType = resource.PipelineResourceTypeGCS
3233

3334
// PipelineResourceTypeBuildGCS is the subtype for the BuildGCSResources, which is simialr to the GCSResource but
3435
// with additional functionality that was added to be compatible with knative build.
35-
PipelineResourceTypeBuildGCS PipelineResourceType = "build-gcs"
36+
PipelineResourceTypeBuildGCS PipelineResourceType = resource.PipelineResourceTypeBuildGCS
3637
)
3738

3839
// PipelineStorageResourceInterface is the interface for subtypes of the storage type.

pkg/apis/pipeline/v1alpha1/task_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ type Inputs struct {
109109
// the Task definition, and when provided as an Input, the Name will be the
110110
// path to the volume mounted containing this Resource as an input (e.g.
111111
// an input Resource named `workspace` will be mounted at `/workspace`).
112-
type TaskResource = v1alpha2.TaskResource
112+
type TaskResource struct {
113+
ResourceDeclaration `json:",inline"`
114+
}
113115

114116
// Outputs allow a task to declare what data the Build/Task will be producing,
115117
// i.e. results such as logs and artifacts such as images.

0 commit comments

Comments
 (0)