Skip to content

Commit dc9939d

Browse files
committed
put back community tasks as openshift addons
1 parent 5951f64 commit dc9939d

File tree

10 files changed

+114
-9
lines changed

10 files changed

+114
-9
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: communityTasks
31+
value: "true"
3032
params:
3133
- name: createRbacResource
3234
value: "true"

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\": \"communityTasks\",\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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ const (
3333
ProfileLite = "lite"
3434

3535
// Addon Params
36-
// Keeping ClusterTasksParams and CommunityClusterTasks params for backward compatibility
37-
// will be removed from next operator api release
36+
// Keeping ClusterTasksParams params for backward compatibility will be removed from next operator api release
3837
ClusterTasksParam = "clusterTasks"
39-
CommunityClusterTasks = "communityClusterTasks"
38+
CommunityTasks = "communityTasks"
4039
PipelineTemplatesParam = "pipelineTemplates"
4140
ResolverTasks = "resolverTasks"
4241
ResolverStepActions = "resolverStepActions"
@@ -113,10 +112,9 @@ var (
113112
}
114113

115114
AddonParams = map[string]ParamValue{
116-
// Keeping ClusterTasks and CommunityClusterTasks params
117-
// for backward compatibility and will be removed in next operator api release
115+
// Keeping ClusterTasks params for backward compatibility and will be removed in next operator api release
118116
ClusterTasksParam: defaultParamValue,
119-
CommunityClusterTasks: defaultParamValue,
117+
CommunityTasks: defaultParamValue,
120118
PipelineTemplatesParam: defaultParamValue,
121119
ResolverTasks: defaultParamValue,
122120
ResolverStepActions: defaultParamValue,
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
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) EnsureCommunityTask(ctx context.Context, enable string, ta *v1alpha1.TektonAddon) error {
40+
if len(r.communityTaskManifest.Resources()) == 0 {
41+
return nil
42+
}
43+
manifest := *r.communityTaskManifest
44+
if enable == "true" {
45+
if err := r.installerSetClient.CustomSet(ctx, ta, CommunityTaskInstallerSet, &manifest, filterAndTransformCommunityTask(), nil); err != nil {
46+
return err
47+
}
48+
} else {
49+
if err := r.installerSetClient.CleanupCustomSet(ctx, CommunityTaskInstallerSet); err != nil {
50+
return err
51+
}
52+
}
53+
return nil
54+
}
55+
56+
func filterAndTransformCommunityTask() 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 appendCommunityTasks(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 fetchCommunityTasks(manifest *mf.Manifest) error {
83+
if err := appendCommunityTasks(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+
CommunityTaskInstallerSet = "CommunityTask"
2526
versionedClusterTaskPatchChar = "0"
2627
PipelinesTemplateInstallerSet = "PipelinesTemplate"
2728
TriggersResourcesInstallerSet = "TriggersResources"

pkg/reconciler/openshift/tektonaddon/controller.go

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

117+
communityTaskManifest := &mf.Manifest{}
118+
if err := fetchCommunityTasks(communityTaskManifest); err != nil {
119+
// if unable to fetch community task, don't fail
120+
logger.Errorf("failed to read community task: %v", err)
121+
}
122+
117123
c := &Reconciler{
118124
crdClientSet: crdClient,
119125
installerSetClient: client.NewInstallerSetClient(tisClient, version, "addon", v1alpha1.KindTektonAddon, metrics),
@@ -129,6 +135,7 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro
129135
pipelineTemplateManifest: pipelineTemplateManifest,
130136
openShiftConsoleManifest: openShiftConsoleManifest,
131137
consoleCLIManifest: consoleCLIManifest,
138+
communityTaskManifest: communityTaskManifest,
132139
}
133140
impl := tektonAddonreconciler.NewImpl(ctx, c)
134141

pkg/reconciler/openshift/tektonaddon/tektonaddon.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type Reconciler struct {
5454
pipelineTemplateManifest *mf.Manifest
5555
openShiftConsoleManifest *mf.Manifest
5656
consoleCLIManifest *mf.Manifest
57+
communityTaskManifest *mf.Manifest
5758
}
5859

5960
const (
@@ -64,6 +65,7 @@ const (
6465
providerTypeRedHat = "redhat"
6566
installerSetNameForResolverTasks = "addon-versioned-resolvertasks"
6667
installerSetNameForResolverStepAction = "addon-versioned-resolverstepactions"
68+
providerTypeCommunity = "community"
6769
)
6870

6971
// Check that our Reconciler implements controller.Reconciler
@@ -131,6 +133,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon
131133
ptVal, _ := findValue(ta.Spec.Params, v1alpha1.PipelineTemplatesParam)
132134
rtVal, _ := findValue(ta.Spec.Params, v1alpha1.ResolverTasks)
133135
rsaVal, _ := findValue(ta.Spec.Params, v1alpha1.ResolverStepActions)
136+
ctVal, _ := findValue(ta.Spec.Params, v1alpha1.CommunityTasks)
134137

135138
if ptVal == "true" && rtVal == "false" {
136139
ta.Status.MarkNotReady("pipelineTemplates cannot be true if ResolverTask is false")
@@ -203,6 +206,12 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon
203206
}
204207
}
205208

209+
if err := r.EnsureCommunityTask(ctx, ctVal, ta); err != nil {
210+
ready = false
211+
errorMsg = fmt.Sprintf("community tasks not yet ready: %v", err)
212+
logger.Error(errorMsg)
213+
}
214+
206215
if !ready {
207216
ta.Status.MarkInstallerSetNotReady(errorMsg)
208217
return nil

test/e2e/common/00_tektonconfigdeployment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func (s *TektonConfigTestSuite) Test05_DisableAndEnableAddons() {
350350
tc := s.getCurrentConfig(timeout)
351351
tc.Spec.Addon.Params = []v1alpha1.Param{
352352
{Name: v1alpha1.ClusterTasksParam, Value: "false"},
353-
{Name: v1alpha1.CommunityClusterTasks, Value: "false"},
353+
{Name: v1alpha1.CommunityTasks, Value: "false"},
354354
{Name: v1alpha1.PipelineTemplatesParam, Value: "false"},
355355
}
356356
_, err := s.clients.TektonConfig().Update(context.TODO(), tc, metav1.UpdateOptions{})

test/resources/tektonaddons.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func AssertTektonInstallerSets(t *testing.T, clients *utils.Clients) {
102102
assertInstallerSets(t, clients, tektonaddon.TriggersResourcesInstallerSet)
103103
assertInstallerSets(t, clients, tektonaddon.ConsoleCLIInstallerSet)
104104
assertInstallerSets(t, clients, tektonaddon.MiscellaneousResourcesInstallerSet)
105+
assertInstallerSets(t, clients, tektonaddon.CommunityTaskInstallerSet)
105106
}
106107

107108
func assertInstallerSets(t *testing.T, clients *utils.Clients, component string) {

test/resources/tektonconfigs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func EnsureTektonConfigExists(kubeClientSet *kubernetes.Clientset, clients opera
7979
Value: "true",
8080
},
8181
{
82-
Name: "communityClusterTasks",
82+
Name: "communityTasks",
8383
Value: "true",
8484
},
8585
},

0 commit comments

Comments
 (0)