Skip to content

Commit 4d231f8

Browse files
committed
restore community tasks as openshift addons
1 parent 7340583 commit 4d231f8

File tree

14 files changed

+222
-101
lines changed

14 files changed

+222
-101
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: 65 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -24,87 +24,85 @@ import (
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
)
2626

27-
func Test_AddonSetDefaults_DefaultParamsWithValues(t *testing.T) {
28-
29-
ta := &TektonAddon{
30-
ObjectMeta: metav1.ObjectMeta{
31-
Name: "name",
32-
Namespace: "namespace",
27+
func Test_AddonSetDefaults(t *testing.T) {
28+
tests := []struct {
29+
name string
30+
initialParams []Param
31+
expectedParams map[string]string
32+
}{
33+
{
34+
name: "Default Params with Values",
35+
initialParams: []Param{
36+
{Name: PipelineTemplatesParam, Value: "true"},
37+
},
38+
expectedParams: map[string]string{
39+
PipelineTemplatesParam: "true",
40+
},
3341
},
34-
Spec: TektonAddonSpec{
35-
CommonSpec: CommonSpec{
36-
TargetNamespace: "namespace",
42+
{
43+
name: "Resolver Task is False",
44+
initialParams: []Param{
45+
{Name: ResolverTasks, Value: "false"},
46+
},
47+
expectedParams: map[string]string{
48+
ResolverTasks: "false",
3749
},
3850
},
39-
}
40-
41-
ta.SetDefaults(context.TODO())
42-
assert.Equal(t, 3, len(ta.Spec.Params))
43-
44-
params := ParseParams(ta.Spec.Params)
45-
value, ok := params[PipelineTemplatesParam]
46-
assert.Equal(t, true, ok)
47-
assert.Equal(t, "true", value)
48-
}
49-
50-
func Test_AddonSetDefaults_ResolverTaskIsFalse(t *testing.T) {
51-
52-
ta := &TektonAddon{
53-
ObjectMeta: metav1.ObjectMeta{
54-
Name: "name",
55-
Namespace: "namespace",
51+
{
52+
name: "Resolver Step Actions",
53+
initialParams: []Param{
54+
{Name: ResolverStepActions, Value: "false"},
55+
},
56+
expectedParams: map[string]string{
57+
ResolverStepActions: "false",
58+
},
5659
},
57-
Spec: TektonAddonSpec{
58-
CommonSpec: CommonSpec{
59-
TargetNamespace: "namespace",
60+
{
61+
name: "Community Resolver Tasks",
62+
initialParams: []Param{
63+
{Name: CommunityResolverTasks, Value: "false"},
6064
},
61-
Addon: Addon{
62-
Params: []Param{
63-
{
64-
Name: "resolverTasks",
65-
Value: "false",
66-
},
67-
},
65+
expectedParams: map[string]string{
66+
CommunityResolverTasks: "false",
6867
},
6968
},
7069
}
7170

72-
ta.SetDefaults(context.TODO())
73-
assert.Equal(t, 3, len(ta.Spec.Params))
71+
for _, tt := range tests {
72+
t.Run(tt.name, func(t *testing.T) {
73+
ta := &TektonAddon{
74+
ObjectMeta: metav1.ObjectMeta{
75+
Name: "name",
76+
Namespace: "namespace",
77+
},
78+
Spec: TektonAddonSpec{
79+
CommonSpec: CommonSpec{
80+
TargetNamespace: "namespace",
81+
},
82+
Addon: Addon{
83+
Params: tt.initialParams,
84+
},
85+
},
86+
}
7487

75-
params := ParseParams(ta.Spec.Params)
76-
value, ok := params[ResolverTasks]
77-
assert.Equal(t, true, ok)
78-
assert.Equal(t, "false", value)
88+
ta.SetDefaults(context.TODO())
89+
checkAddonParams(t, ta.Spec.Addon.Params, tt.expectedParams)
90+
})
91+
}
7992
}
8093

81-
func Test_AddonSetDefaults_ResolverStepActions(t *testing.T) {
94+
func checkAddonParams(t *testing.T, actualParams []Param, expectedParams map[string]string) {
95+
t.Helper()
8296

83-
ta := &TektonAddon{
84-
ObjectMeta: metav1.ObjectMeta{
85-
Name: "name",
86-
Namespace: "namespace",
87-
},
88-
Spec: TektonAddonSpec{
89-
CommonSpec: CommonSpec{
90-
TargetNamespace: "namespace",
91-
},
92-
Addon: Addon{
93-
Params: []Param{
94-
{
95-
Name: "resolverStepActions",
96-
Value: "false",
97-
},
98-
},
99-
},
100-
},
97+
if len(actualParams) != len(AddonParams) {
98+
t.Fatalf("Expected %d addon params, got %d", len(AddonParams), len(actualParams))
10199
}
102100

103-
ta.SetDefaults(context.TODO())
104-
assert.Equal(t, 3, len(ta.Spec.Params))
101+
paramsMap := ParseParams(actualParams)
105102

106-
params := ParseParams(ta.Spec.Params)
107-
value, ok := params[ResolverStepActions]
108-
assert.Equal(t, true, ok)
109-
assert.Equal(t, "false", value)
103+
for key, expectedValue := range expectedParams {
104+
value, exists := paramsMap[key]
105+
assert.Equal(t, true, exists, "Param %q is missing in Spec.Addon.Params", key)
106+
assert.Equal(t, expectedValue, value, "Param %q has incorrect value", key)
107+
}
110108
}

pkg/apis/operator/v1alpha1/tektonconfig_default_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,16 @@ 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+
if len(tc.Spec.Addon.Params) != len(AddonParams) {
94+
t.Fatalf("Expected %d addon params, got %d", len(AddonParams), len(tc.Spec.Addon.Params))
95+
}
96+
paramsMap := ParseParams(tc.Spec.Addon.Params)
97+
98+
for key, expectedValue := range AddonParams {
99+
value, exists := paramsMap[key]
100+
assert.Equal(t, true, exists, "Param %q is missing in Spec.Addon.Params", key)
101+
assert.Equal(t, expectedValue.Default, value, "Param %q has incorrect value", key)
94102
}
95103
}
96104

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)