Skip to content

Commit 7287d12

Browse files
committed
restore community tasks as openshift addons
1 parent 7340583 commit 7287d12

File tree

14 files changed

+204
-34
lines changed

14 files changed

+204
-34
lines changed

config/crs/openshift/config/all/operator_v1alpha1_config_cr.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ spec:
2727
value: "true"
2828
- name: resolverStepActions
2929
value: "true"
30+
- name: communityResolverTasks
31+
value: "true"
3032
params:
3133
- name: createRbacResource
3234
value: "true"

docs/TektonAddon.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ weight: 6
66
-->
77
# Tekton Addon
88

9-
TektonAddon custom resource allows user to install resource like resolverTasks, resolverStepActions and pipelineTemplate along with Pipelines.
9+
TektonAddon custom resource allows user to install resource like resolverTasks, resolverStepActions, communityResolverTasks and pipelineTemplate along with Pipelines.
1010
It also allows user to install various Tasks in openshift-pipelines namespace.
1111

1212
**NOTE:** TektonAddon is currently available only for OpenShift Platform. This is roadmap to enable it for Kubernetes platform.
@@ -28,6 +28,8 @@ spec:
2828
value: "true"
2929
- name: resolverStepActions
3030
value: "true"
31+
- name: communityResolverTasks
32+
value: "true"
3133
```
3234
You can install this component using [TektonConfig](./TektonConfig.md) by choosing appropriate `profile`.
3335

@@ -38,7 +40,8 @@ Available params are
3840
- `pipelineTemplates` (Default: `true`)
3941
- `resolverTasks` (Default: `true`)
4042
- `resolverStepActions` (Default: `true`)
43+
- `communityResolverTasks` (Default: `true`)
4144

4245
User can disable the installation of resources by changing the value to `false`.
4346

44-
- Pipelines templates uses tasks from `openshift-pipelines` in them so to install pipelineTemplates, resolverTasks must be `true`
47+
- Pipelines templates uses tasks from `openshift-pipelines`. Therefore, to install pipelineTemplates, resolverTasks must be set to `true`

docs/TektonConfig.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ By default pruner job will be created from the global pruner config (`spec.prune
329329
> `keep: 100` <br>
330330
### Addon
331331

332-
TektonAddon install some resources along with Tekton Pipelines on the cluster. This provides few PipelineTemplates, ResolverTasks and ResolverStepActions.
332+
TektonAddon install some resources along with Tekton Pipelines on the cluster. This provides few PipelineTemplates, ResolverTasks, ResolverStepActions and CommunityResolverTasks.
333333

334334
This section allows to customize installation of those resources through params. You can read more about the supported params [here](./TektonAddon.md).
335335

@@ -343,6 +343,8 @@ addon:
343343
value: "true"
344344
- name: "resolverStepActions"
345345
value: "true"
346+
- name: "communityResolverTasks"
347+
value: "true"
346348
```
347349

348350
**NOTE**: TektonAddon is currently available for OpenShift Platform only. Enabling this for Kubernetes platform is in roadmap

operatorhub/openshift/release-artifacts/bundle/manifests/openshift-pipelines-operator-rh.clusterserviceversion.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ metadata:
1414
\ {\n \"name\": \"clusterTasks\",\n \"value\": \"\
1515
true\"\n },\n {\n \"name\": \"pipelineTemplates\"\
1616
,\n \"value\": \"true\"\n },\n {\n \"\
17-
name\": \"communityClusterTasks\",\n \"value\": \"true\"\n \
17+
name\": \"communityResolverTasks\",\n \"value\": \"true\"\n \
1818
\ }\n ]\n },\n \"params\": [\n {\n \"name\"\
1919
: \"createRbacResource\",\n \"value\": \"true\"\n }\n ],\n\
2020
\ \"profile\": \"all\",\n \"pruner\": {\n \"keep\": 100,\n\

pkg/apis/operator/v1alpha1/const.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const (
3333
ProfileLite = "lite"
3434

3535
// Addon Params
36+
CommunityResolverTasks = "communityResolverTasks"
3637
PipelineTemplatesParam = "pipelineTemplates"
3738
ResolverTasks = "resolverTasks"
3839
ResolverStepActions = "resolverStepActions"
@@ -109,6 +110,7 @@ var (
109110
}
110111

111112
AddonParams = map[string]ParamValue{
113+
CommunityResolverTasks: defaultParamValue,
112114
PipelineTemplatesParam: defaultParamValue,
113115
ResolverTasks: defaultParamValue,
114116
ResolverStepActions: defaultParamValue,

pkg/apis/operator/v1alpha1/tektonaddon_default_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,34 @@ func Test_AddonSetDefaults_ResolverStepActions(t *testing.T) {
108108
assert.Equal(t, true, ok)
109109
assert.Equal(t, "false", value)
110110
}
111+
112+
func Test_AddonSetDefaults_CommunityResolverTasks(t *testing.T) {
113+
114+
ta := &TektonAddon{
115+
ObjectMeta: metav1.ObjectMeta{
116+
Name: "name",
117+
Namespace: "namespace",
118+
},
119+
Spec: TektonAddonSpec{
120+
CommonSpec: CommonSpec{
121+
TargetNamespace: "namespace",
122+
},
123+
Addon: Addon{
124+
Params: []Param{
125+
{
126+
Name: "communityResolverTasks",
127+
Value: "false",
128+
},
129+
},
130+
},
131+
},
132+
}
133+
134+
ta.SetDefaults(context.TODO())
135+
assert.Equal(t, 5, len(ta.Spec.Params))
136+
137+
params := ParseParams(ta.Spec.Params)
138+
value, ok := params[CommunityResolverTasks]
139+
assert.Equal(t, true, ok)
140+
assert.Equal(t, "false", value)
141+
}

pkg/apis/operator/v1alpha1/tektonconfig_default_test.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,32 @@ func Test_SetDefaults_Addon_Params(t *testing.T) {
8989
t.Setenv("PLATFORM", "openshift")
9090

9191
tc.SetDefaults(context.TODO())
92-
if len(tc.Spec.Addon.Params) != 3 {
93-
t.Error("Setting default failed for TektonConfig (spec.addon.params)")
92+
93+
expectedParams := map[string]ParamValue{
94+
CommunityResolverTasks: defaultParamValue,
95+
PipelineTemplatesParam: defaultParamValue,
96+
ResolverTasks: defaultParamValue,
97+
ResolverStepActions: defaultParamValue,
98+
}
99+
100+
if len(tc.Spec.Addon.Params) != len(expectedParams) {
101+
t.Fatalf("Expected %d addon params, got %d", len(expectedParams), len(tc.Spec.Addon.Params))
102+
}
103+
104+
for k, v := range expectedParams {
105+
found := false
106+
for _, param := range tc.Spec.Addon.Params {
107+
if param.Name == k {
108+
found = true
109+
if param.Value != v.Default {
110+
t.Errorf("Param %q has incorrect value. Expected %q, got %q", k, v.Default, param.Value)
111+
}
112+
break
113+
}
114+
}
115+
if !found {
116+
t.Errorf("Param %q is missing in Spec.Addon.Params", k)
117+
}
94118
}
95119
}
96120

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
Copyright 2024 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 tektonaddon
18+
19+
import (
20+
"context"
21+
"strings"
22+
23+
mf "github.com/manifestival/manifestival"
24+
"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
25+
"github.com/tektoncd/operator/pkg/reconciler/common"
26+
"github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset/client"
27+
)
28+
29+
var communityResourceURLs = []string{
30+
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/jib-maven/0.5/jib-maven.yaml",
31+
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/helm-upgrade-from-source/0.3/helm-upgrade-from-source.yaml",
32+
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/helm-upgrade-from-repo/0.2/helm-upgrade-from-repo.yaml",
33+
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/trigger-jenkins-job/0.1/trigger-jenkins-job.yaml",
34+
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/pull-request/0.1/pull-request.yaml",
35+
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/kubeconfig-creator/0.1/kubeconfig-creator.yaml",
36+
"https://raw.githubusercontent.com/tektoncd/catalog/main/task/argocd-task-sync-and-wait/0.2/argocd-task-sync-and-wait.yaml",
37+
}
38+
39+
func (r *Reconciler) EnsureCommunityResolverTask(ctx context.Context, enable string, ta *v1alpha1.TektonAddon) error {
40+
if len(r.communityResolverTaskManifest.Resources()) == 0 {
41+
return nil
42+
}
43+
manifest := *r.communityResolverTaskManifest
44+
if enable == "true" {
45+
if err := r.installerSetClient.CustomSet(ctx, ta, CommunityResolverTaskInstallerSet, &manifest, filterAndTransformCommunityResolverTask(), nil); err != nil {
46+
return err
47+
}
48+
} else {
49+
if err := r.installerSetClient.CleanupCustomSet(ctx, CommunityResolverTaskInstallerSet); err != nil {
50+
return err
51+
}
52+
}
53+
return nil
54+
}
55+
56+
func filterAndTransformCommunityResolverTask() client.FilterAndTransform {
57+
return func(ctx context.Context, manifest *mf.Manifest, comp v1alpha1.TektonComponent) (*mf.Manifest, error) {
58+
instance := comp.(*v1alpha1.TektonAddon)
59+
addonImages := common.ToLowerCaseKeys(common.ImagesFromEnv(common.AddonsImagePrefix))
60+
61+
extra := []mf.Transformer{
62+
injectLabel(labelProviderType, providerTypeCommunity, overwrite, "Task"),
63+
common.TaskImages(ctx, addonImages),
64+
}
65+
if err := common.Transform(ctx, manifest, instance, extra...); err != nil {
66+
return nil, err
67+
}
68+
return manifest, nil
69+
}
70+
}
71+
72+
func appendCommunityResolverTasks(manifest *mf.Manifest) error {
73+
urls := strings.Join(communityResourceURLs, ",")
74+
m, err := mf.ManifestFrom(mf.Path(urls))
75+
if err != nil {
76+
return err
77+
}
78+
*manifest = manifest.Append(m)
79+
return nil
80+
}
81+
82+
func fetchCommunityResolverTasks(manifest *mf.Manifest) error {
83+
if err := appendCommunityResolverTasks(manifest); err != nil {
84+
return err
85+
}
86+
return nil
87+
}

pkg/reconciler/openshift/tektonaddon/const.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
OpenShiftConsoleInstallerSet = "OpenShiftConsole"
2323
VersionedResolverTaskInstallerSet = "VersionedResolverTask"
2424
VersionedResolverStepActionInstallerSet = "VersionedResolverStepAction"
25+
CommunityResolverTaskInstallerSet = "CommunityResolverTask"
2526
versionedClusterTaskPatchChar = "0"
2627
PipelinesTemplateInstallerSet = "PipelinesTemplate"
2728
TriggersResourcesInstallerSet = "TriggersResources"

pkg/reconciler/openshift/tektonaddon/controller.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,28 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro
114114
logger.Fatalf("failed to read console cli from kodata: %v", err)
115115
}
116116

117+
communityResolverTaskManifest := &mf.Manifest{}
118+
if err := fetchCommunityResolverTasks(communityResolverTaskManifest); err != nil {
119+
// if unable to fetch community task, don't fail
120+
logger.Errorf("failed to read community resolver task: %v", err)
121+
}
122+
117123
c := &Reconciler{
118-
crdClientSet: crdClient,
119-
installerSetClient: client.NewInstallerSetClient(tisClient, version, "addon", v1alpha1.KindTektonAddon, metrics),
120-
operatorClientSet: operatorclient.Get(ctx),
121-
extension: generator(ctx),
122-
pipelineInformer: tektonPipelineinformer.Get(ctx),
123-
triggerInformer: tektonTriggerinformer.Get(ctx),
124-
manifest: manifest,
125-
operatorVersion: version,
126-
resolverTaskManifest: resolverTaskManifest,
127-
resolverStepActionManifest: resolverStepActionManifest,
128-
triggersResourcesManifest: triggersResourcesManifest,
129-
pipelineTemplateManifest: pipelineTemplateManifest,
130-
openShiftConsoleManifest: openShiftConsoleManifest,
131-
consoleCLIManifest: consoleCLIManifest,
124+
crdClientSet: crdClient,
125+
installerSetClient: client.NewInstallerSetClient(tisClient, version, "addon", v1alpha1.KindTektonAddon, metrics),
126+
operatorClientSet: operatorclient.Get(ctx),
127+
extension: generator(ctx),
128+
pipelineInformer: tektonPipelineinformer.Get(ctx),
129+
triggerInformer: tektonTriggerinformer.Get(ctx),
130+
manifest: manifest,
131+
operatorVersion: version,
132+
resolverTaskManifest: resolverTaskManifest,
133+
resolverStepActionManifest: resolverStepActionManifest,
134+
triggersResourcesManifest: triggersResourcesManifest,
135+
pipelineTemplateManifest: pipelineTemplateManifest,
136+
openShiftConsoleManifest: openShiftConsoleManifest,
137+
consoleCLIManifest: consoleCLIManifest,
138+
communityResolverTaskManifest: communityResolverTaskManifest,
132139
}
133140
impl := tektonAddonreconciler.NewImpl(ctx, c)
134141

0 commit comments

Comments
 (0)