Skip to content

Commit 6074fa4

Browse files
abayertekton-robot
authored andcommitted
Add cluster resolver
Relates to #4476 and https://github.com/tektoncd/community/blob/main/teps/0096-pipelines-v1-api.md This resolver replaces `ClusterTask`s going forward. Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
1 parent f919a04 commit 6074fa4

File tree

19 files changed

+1006
-24
lines changed

19 files changed

+1006
-24
lines changed

cmd/resolvers/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/tektoncd/pipeline/pkg/apis/resolution/v1alpha1"
2525
"github.com/tektoncd/pipeline/pkg/resolution/resolver/bundle"
26+
"github.com/tektoncd/pipeline/pkg/resolution/resolver/cluster"
2627
"github.com/tektoncd/pipeline/pkg/resolution/resolver/framework"
2728
"github.com/tektoncd/pipeline/pkg/resolution/resolver/git"
2829
"github.com/tektoncd/pipeline/pkg/resolution/resolver/hub"
@@ -49,5 +50,6 @@ func main() {
4950
sharedmain.MainWithContext(ctx, "controller",
5051
framework.NewController(ctx, &git.Resolver{}),
5152
framework.NewController(ctx, &hub.Resolver{HubURL: hubURL}),
52-
framework.NewController(ctx, &bundle.Resolver{}))
53+
framework.NewController(ctx, &bundle.Resolver{}),
54+
framework.NewController(ctx, &cluster.Resolver{}))
5355
}

config/config-feature-flags.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,7 @@ data:
9393
# This is an experimental feature and thus should still be considered
9494
# an alpha feature.
9595
enable-git-resolver: "false"
96+
# Setting this flag to "true" enables remote resolution of tasks and pipelines from other namespaces within the cluster.
97+
# This is an experimental feature and thus should still be considered
98+
# an alpha feature.
99+
enable-cluster-resolver: "false"

config/resolvers/200-clusterrole.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ rules:
2525
- apiGroups: ["resolution.tekton.dev"]
2626
resources: ["resolutionrequests", "resolutionrequests/status"]
2727
verbs: ["get", "list", "watch", "update", "patch"]
28+
- apiGroups: ["tekton.dev"]
29+
resources: ["tasks", "pipelines"]
30+
verbs: ["get", "list"]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2022 The Tekton Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: ConfigMap
17+
metadata:
18+
name: cluster-resolver-config
19+
namespace: tekton-pipelines
20+
labels:
21+
app.kubernetes.io/component: resolvers
22+
app.kubernetes.io/instance: default
23+
app.kubernetes.io/part-of: tekton-pipelines
24+
data:
25+
# The default kind to fetch.
26+
default-kind: "task"
27+
# The default namespace to look for resources in.
28+
default-namespace: ""
29+
# An optional comma-separated list of namespaces which the resolver is allowed to access. Defaults to empty, meaning all namespaces are allowed.
30+
allowed-namespaces: ""
31+
# An optional comma-separated list of namespaces which the resolver is blocked from accessing. Defaults to empty, meaning all namespaces are allowed.
32+
blocked-namespaces: ""

docs/cluster-resolver.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Cluster Resolver
2+
3+
## Resolver Type
4+
5+
This Resolver responds to type `cluster`.
6+
7+
## Parameters
8+
9+
| Param Name | Description | Example Value |
10+
|-------------|-------------------------------------------------------|------------------------------|
11+
| `kind` | The kind of resource to fetch. | `task`, `pipeline` |
12+
| `name` | The name of the resource to fetch. | `some-pipeline`, `some-task` |
13+
| `namespace` | The namespace in the cluster containing the resource. | `default`, `other-namespace` |
14+
15+
## Requirements
16+
17+
- A cluster running Tekton Pipeline v0.40.0 or later, with the `alpha` feature gate enabled.
18+
- The [built-in remote resolvers installed](./install.md#installing-and-configuring-remote-task-and-pipeline-resolution).
19+
- The `enable-cluster-resolver` feature flag set to `true`.
20+
21+
## Configuration
22+
23+
This resolver uses a `ConfigMap` for its settings. See
24+
[`../config/resolvers/cluster-resolver-config.yaml`](../config/resolvers/cluster-resolver-config.yaml)
25+
for the name, namespace and defaults that the resolver ships with.
26+
27+
### Options
28+
29+
| Option Name | Description | Example Values |
30+
|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
31+
| `default-kind` | The default resource kind to fetch if not specified in parameters. | `task`, `pipeline` |
32+
| `default-namespace` | The default namespace to fetch resources from if not specified in parameters. | `default`, `some-namespace` |
33+
| `allowed-namespaces` | An optional comma-separated list of namespaces which the resolver is allowed to access. Defaults to empty, meaning all namespaces are allowed. | `default,some-namespace`, (empty) |
34+
| `blocked-namespaces` | An optional comma-separated list of namespaces which the resolver is blocked from accessing. Defaults to empty, meaning all namespaces are allowed. | `default,other-namespace`, (empty) |
35+
36+
## Usage
37+
38+
### Task Resolution
39+
40+
```yaml
41+
apiVersion: tekton.dev/v1beta1
42+
kind: TaskRun
43+
metadata:
44+
name: remote-task-reference
45+
spec:
46+
taskRef:
47+
resolver: cluster
48+
params:
49+
- name: kind
50+
value: task
51+
- name: name
52+
value: some-task
53+
- name: namespace
54+
value: namespace-containing-task
55+
```
56+
57+
### Pipeline resolution
58+
59+
```yaml
60+
apiVersion: tekton.dev/v1beta1
61+
kind: PipelineRun
62+
metadata:
63+
name: remote-pipeline-reference
64+
spec:
65+
pipelineRef:
66+
resolver: cluster
67+
params:
68+
- name: kind
69+
value: pipeline
70+
- name: name
71+
value: some-pipeline
72+
- name: namespace
73+
value: namespace-containing-pipeline
74+
```
75+
76+
---
77+
78+
Except as otherwise noted, the content of this page is licensed under the
79+
[Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/),
80+
and code samples are licensed under the
81+
[Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).

docs/install.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ By default, these remote resolvers are disabled. Each resolver is enabled by set
293293
feature flag to `true`.
294294
1. [The `hub` resolver](./hub-resolver.md), enabled by setting the `enable-hub-resolver`
295295
feature flag to `true`.
296+
1. [The `cluster` resolver](./cluster-resolver.md), enabled by setting the `enable-cluster-resolver`
297+
feature flag to `true`.
296298

297299
## Configuring CloudEvents notifications
298300

docs/resolution-getting-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The feature flags for the built-in resolvers are:
4040
* The `bundles` resolver: `enable-bundles-resolver`
4141
* The `git` resolver: `enable-git-resolver`
4242
* The `hub` resolver: `enable-hub-resolver`
43+
* The `cluster` resolver: `enable-cluster-resolver`
4344

4445
## Step 3: Try it out!
4546

docs/resolution.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ For new users getting started with Tekton Pipeilne remote resolution, check out
1313
feature flag to `true`.
1414
1. [The `hub` resolver](./hub-resolver.md), enabled by setting the `enable-hub-resolver`
1515
feature flag to `true`.
16+
1. [The `cluster` resolver](./cluster-resolver.md), enabled by setting the `enable-cluster-resolver`
17+
feature flag to `true`.
1618

1719
## Developer Howto: Writing a Resolver From Scratch
1820

pkg/apis/config/feature_flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const (
6666
DefaultEnableHubResolver = false
6767
// DefaultEnableBundlesResolver is the default value for "enable-bundles-resolver".
6868
DefaultEnableBundlesResolver = false
69+
// DefaultEnableClusterResolver is the default value for "enable-cluster-resolver".
70+
DefaultEnableClusterResolver = false
6971

7072
disableAffinityAssistantKey = "disable-affinity-assistant"
7173
disableCredsInitKey = "disable-creds-init"
@@ -84,6 +86,8 @@ const (
8486
EnableHubResolver = "enable-hub-resolver"
8587
// EnableBundlesResolver is the flag used to enable the bundle remote resolver
8688
EnableBundlesResolver = "enable-bundles-resolver"
89+
// EnableClusterResolver is the flag used to enable the cluster remote resolver
90+
EnableClusterResolver = "enable-cluster-resolver"
8791
)
8892

8993
// FeatureFlags holds the features configurations
@@ -103,6 +107,7 @@ type FeatureFlags struct {
103107
EnableGitResolver bool
104108
EnableHubResolver bool
105109
EnableBundleResolver bool
110+
EnableClusterResolver bool
106111
}
107112

108113
// GetFeatureFlagsConfigName returns the name of the configmap containing all
@@ -163,6 +168,9 @@ func NewFeatureFlagsFromMap(cfgMap map[string]string) (*FeatureFlags, error) {
163168
if err := setFeature(EnableBundlesResolver, DefaultEnableBundlesResolver, &tc.EnableBundleResolver); err != nil {
164169
return nil, err
165170
}
171+
if err := setFeature(EnableClusterResolver, DefaultEnableClusterResolver, &tc.EnableClusterResolver); err != nil {
172+
return nil, err
173+
}
166174

167175
// Given that they are alpha features, Tekton Bundles and Custom Tasks should be switched on if
168176
// enable-api-fields is "alpha". If enable-api-fields is not "alpha" then fall back to the value of
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright 2022 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+
18+
package cluster
19+
20+
const (
21+
// ResourceNameAnnotation is the annotation key for the fetched resource name
22+
ResourceNameAnnotation = "name"
23+
// ResourceNamespaceAnnotation is the annotation key for the fetched resource's namespace
24+
ResourceNamespaceAnnotation = "namespace"
25+
)

0 commit comments

Comments
 (0)