Skip to content

Commit

Permalink
Add types and client for Resolution
Browse files Browse the repository at this point in the history
Part of #4710

In order to get remote resolution functionality to beta, we're moving it from a separate repository/release to be part of Pipeline. This is the first PR in a sequence moving the code from the Resolution repository into Pipeline.

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
  • Loading branch information
abayer committed Jul 26, 2022
1 parent 10a5ae6 commit 0109d1a
Show file tree
Hide file tree
Showing 58 changed files with 3,642 additions and 164 deletions.
9 changes: 3 additions & 6 deletions docs/pipelineruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,9 @@ spec:
pipelineRef:
resolver: git
resource:
- name: url
value: https://github.com/tektoncd/catalog.git
- name: commit
value: abc123
- name: path
value: /pipeline/buildpacks/0.1/buildpacks.yaml
url: https://github.com/tektoncd/catalog.git
commit: abc123
path: /pipeline/buildpacks/0.1/buildpacks.yaml
```

### Specifying `Resources`
Expand Down
9 changes: 3 additions & 6 deletions docs/taskruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,9 @@ spec:
taskRef:
resolver: git
resource:
- name: url
value: https://github.com/tektoncd/catalog.git
- name: commit
value: abc123
- name: path
value: /task/golang-build/0.3/golang-build.yaml
url: https://github.com/tektoncd/catalog.git
commit: abc123
path: /task/golang-build/0.3/golang-build.yaml
```

### Specifying `Parameters`
Expand Down
11 changes: 11 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister"
github.com/tektoncd/pipeline/pkg/client github.com/tektoncd/pipeline/pkg/apis \
"pipeline:v1alpha1,v1beta1,v1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
# This generates deepcopy,client,informer and lister for the resolution package (v1alpha1)
bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/tektoncd/pipeline/pkg/client/resolution github.com/tektoncd/pipeline/pkg/apis \
"resolution:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt

# Depends on generate-groups.sh to install bin/deepcopy-gen
${PREFIX}/deepcopy-gen \
Expand Down Expand Up @@ -80,6 +85,12 @@ bash ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \
"pipeline:v1alpha1,v1beta1,v1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
GOFLAGS="${OLDGOFLAGS}"
# This generates the knative inject packages for the resolution package (v1alpha1).
bash ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \
github.com/tektoncd/pipeline/pkg/client/resolution github.com/tektoncd/pipeline/pkg/apis \
"resolution:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
GOFLAGS="${OLDGOFLAGS}"

# Make sure our dependencies are up-to-date
${REPO_ROOT_DIR}/hack/update-deps.sh
Expand Down
48 changes: 6 additions & 42 deletions pkg/apis/pipeline/v1beta1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/pipeline_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func TestPipelineTask_ValidateRegularTask_Success(t *testing.T) {
}, {
name: "pipeline task - use of resource with the feature flag set",
tasks: PipelineTask{
TaskRef: &TaskRef{Name: "boo", ResolverRef: ResolverRef{Resource: []ResolverParam{{}}}},
TaskRef: &TaskRef{Name: "boo", ResolverRef: ResolverRef{Resource: map[string]string{}}},
},
enableAPIFields: true,
}, {
Expand Down Expand Up @@ -338,7 +338,7 @@ func TestPipelineTask_ValidateRegularTask_Failure(t *testing.T) {
}, {
name: "pipeline task - use of resource without the feature flag set",
task: PipelineTask{
TaskRef: &TaskRef{Name: "boo", ResolverRef: ResolverRef{Resource: []ResolverParam{{}}}},
TaskRef: &TaskRef{Name: "boo", ResolverRef: ResolverRef{Resource: map[string]string{"bar": "baz"}}},
},
expectedError: *apis.ErrDisallowedFields("taskref.resource"),
}}
Expand Down
29 changes: 12 additions & 17 deletions pkg/apis/pipeline/v1beta1/pipelineref_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ func TestPipelineRef_Invalid(t *testing.T) {
name: "pipelineref resource disallowed without alpha feature gate",
ref: &v1beta1.PipelineRef{
ResolverRef: v1beta1.ResolverRef{
Resource: []v1beta1.ResolverParam{},
Resource: map[string]string{},
},
},
wantErr: apis.ErrMissingField("resolver").Also(apis.ErrGeneric("resource requires \"enable-api-fields\" feature gate to be \"alpha\" but it is \"stable\"")),
}, {
name: "pipelineref resource disallowed without resolver",
ref: &v1beta1.PipelineRef{
ResolverRef: v1beta1.ResolverRef{
Resource: []v1beta1.ResolverParam{},
Resource: map[string]string{},
},
},
wantErr: apis.ErrMissingField("resolver"),
Expand Down Expand Up @@ -112,10 +112,9 @@ func TestPipelineRef_Invalid(t *testing.T) {
ref: &v1beta1.PipelineRef{
Name: "bar",
ResolverRef: v1beta1.ResolverRef{
Resource: []v1beta1.ResolverParam{{
Name: "foo",
Value: "bar",
}},
Resource: map[string]string{
"foo": "bar",
},
},
},
wantErr: apis.ErrMultipleOneOf("name", "resource").Also(apis.ErrMissingField("resolver")),
Expand All @@ -125,10 +124,9 @@ func TestPipelineRef_Invalid(t *testing.T) {
ref: &v1beta1.PipelineRef{
Bundle: "bar",
ResolverRef: v1beta1.ResolverRef{
Resource: []v1beta1.ResolverParam{{
Name: "foo",
Value: "bar",
}},
Resource: map[string]string{
"foo": "bar",
},
},
},
wantErr: apis.ErrMultipleOneOf("bundle", "resource").Also(apis.ErrMissingField("resolver")),
Expand Down Expand Up @@ -163,13 +161,10 @@ func TestPipelineRef_Valid(t *testing.T) {
wc: config.EnableAlphaAPIFields,
}, {
name: "alpha feature: valid resolver with resource parameters",
ref: &v1beta1.PipelineRef{ResolverRef: v1beta1.ResolverRef{Resolver: "git", Resource: []v1beta1.ResolverParam{{
Name: "repo",
Value: "https://github.com/tektoncd/pipeline.git",
}, {
Name: "branch",
Value: "baz",
}}}},
ref: &v1beta1.PipelineRef{ResolverRef: v1beta1.ResolverRef{Resolver: "git", Resource: map[string]string{
"repo": "https://github.com/tektoncd/pipeline.git",
"branch": "baz",
}}},
wc: config.EnableAlphaAPIFields,
}}

Expand Down
13 changes: 1 addition & 12 deletions pkg/apis/pipeline/v1beta1/resolver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,5 @@ type ResolverRef struct {
// "repo" or "path" but the set of params ultimately depends on
// the chosen resolver.
// +optional
// +listType=atomic
Resource []ResolverParam `json:"resource,omitempty"`
}

// ResolverParam is a single parameter passed to a resolver.
type ResolverParam struct {
// Name is the name of the parameter that will be passed to the
// resolver.
Name string `json:"name"`
// Value is the string value of the parameter that will be
// passed to the resolver.
Value string `json:"value"`
Resource map[string]string `json:"resource,omitempty"`
}
31 changes: 5 additions & 26 deletions pkg/apis/pipeline/v1beta1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1463,26 +1463,6 @@
}
}
},
"v1beta1.ResolverParam": {
"description": "ResolverParam is a single parameter passed to a resolver.",
"type": "object",
"required": [
"name",
"value"
],
"properties": {
"name": {
"description": "Name is the name of the parameter that will be passed to the resolver.",
"type": "string",
"default": ""
},
"value": {
"description": "Value is the string value of the parameter that will be passed to the resolver.",
"type": "string",
"default": ""
}
}
},
"v1beta1.ResolverRef": {
"description": "ResolverRef can be used to refer to a Pipeline or Task in a remote location like a git repo. This feature is in alpha and these fields are only available when the alpha feature gate is enabled.",
"type": "object",
Expand All @@ -1493,12 +1473,11 @@
},
"resource": {
"description": "Resource contains the parameters used to identify the referenced Tekton resource. Example entries might include \"repo\" or \"path\" but the set of params ultimately depends on the chosen resolver.",
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/v1beta1.ResolverParam"
},
"x-kubernetes-list-type": "atomic"
"type": "object",
"additionalProperties": {
"type": "string",
"default": ""
}
}
}
},
Expand Down
25 changes: 8 additions & 17 deletions pkg/apis/pipeline/v1beta1/taskref_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ func TestTaskRef_Valid(t *testing.T) {
wc: config.EnableAlphaAPIFields,
}, {
name: "alpha feature: valid resolver with resource parameters",
taskRef: &v1beta1.TaskRef{ResolverRef: v1beta1.ResolverRef{Resolver: "git", Resource: []v1beta1.ResolverParam{{
Name: "repo",
Value: "https://github.com/tektoncd/pipeline.git",
}, {
Name: "branch",
Value: "baz",
}}}},
taskRef: &v1beta1.TaskRef{ResolverRef: v1beta1.ResolverRef{Resolver: "git", Resource: map[string]string{
"repo": "https://github.com/tektoncd/pipeline.git",
"branch": "baz",
}}},
wc: config.EnableAlphaAPIFields,
}, {
name: "valid bundle",
Expand Down Expand Up @@ -115,15 +112,15 @@ func TestTaskRef_Invalid(t *testing.T) {
name: "taskref resource disallowed without alpha feature gate",
taskRef: &v1beta1.TaskRef{
ResolverRef: v1beta1.ResolverRef{
Resource: []v1beta1.ResolverParam{},
Resource: map[string]string{},
},
},
wantErr: apis.ErrMissingField("resolver").Also(apis.ErrGeneric("resource requires \"enable-api-fields\" feature gate to be \"alpha\" but it is \"stable\"")),
}, {
name: "taskref resource disallowed without resolver",
taskRef: &v1beta1.TaskRef{
ResolverRef: v1beta1.ResolverRef{
Resource: []v1beta1.ResolverParam{},
Resource: map[string]string{},
},
},
wantErr: apis.ErrMissingField("resolver"),
Expand Down Expand Up @@ -153,10 +150,7 @@ func TestTaskRef_Invalid(t *testing.T) {
taskRef: &v1beta1.TaskRef{
Name: "bar",
ResolverRef: v1beta1.ResolverRef{
Resource: []v1beta1.ResolverParam{{
Name: "foo",
Value: "bar",
}},
Resource: map[string]string{"foo": "bar"},
},
},
wantErr: apis.ErrMultipleOneOf("name", "resource").Also(apis.ErrMissingField("resolver")),
Expand All @@ -166,10 +160,7 @@ func TestTaskRef_Invalid(t *testing.T) {
taskRef: &v1beta1.TaskRef{
Bundle: "bar",
ResolverRef: v1beta1.ResolverRef{
Resource: []v1beta1.ResolverParam{{
Name: "foo",
Value: "bar",
}},
Resource: map[string]string{"foo": "bar"},
},
},
wantErr: apis.ErrMultipleOneOf("bundle", "resource").Also(apis.ErrMissingField("resolver")),
Expand Down
22 changes: 4 additions & 18 deletions pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions pkg/apis/resolution/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2022 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package resolution

const (
// GroupName is the name of the API group.
GroupName = "resolution.tekton.dev"
)
Loading

0 comments on commit 0109d1a

Please sign in to comment.