Skip to content

Commit

Permalink
put back community tasks as openshift addons
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhelil committed Nov 28, 2024
1 parent 5951f64 commit dc9939d
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ spec:
value: "true"
- name: resolverStepActions
value: "true"
- name: communityTasks
value: "true"
params:
- name: createRbacResource
value: "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ metadata:
\ {\n \"name\": \"clusterTasks\",\n \"value\": \"\
true\"\n },\n {\n \"name\": \"pipelineTemplates\"\
,\n \"value\": \"true\"\n },\n {\n \"\
name\": \"communityClusterTasks\",\n \"value\": \"true\"\n \
name\": \"communityTasks\",\n \"value\": \"true\"\n \
\ }\n ]\n },\n \"params\": [\n {\n \"name\"\
: \"createRbacResource\",\n \"value\": \"true\"\n }\n ],\n\
\ \"profile\": \"all\",\n \"pruner\": {\n \"keep\": 100,\n\
Expand Down
10 changes: 4 additions & 6 deletions pkg/apis/operator/v1alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ const (
ProfileLite = "lite"

// Addon Params
// Keeping ClusterTasksParams and CommunityClusterTasks params for backward compatibility
// will be removed from next operator api release
// Keeping ClusterTasksParams params for backward compatibility will be removed from next operator api release
ClusterTasksParam = "clusterTasks"
CommunityClusterTasks = "communityClusterTasks"
CommunityTasks = "communityTasks"
PipelineTemplatesParam = "pipelineTemplates"
ResolverTasks = "resolverTasks"
ResolverStepActions = "resolverStepActions"
Expand Down Expand Up @@ -113,10 +112,9 @@ var (
}

AddonParams = map[string]ParamValue{
// Keeping ClusterTasks and CommunityClusterTasks params
// for backward compatibility and will be removed in next operator api release
// Keeping ClusterTasks params for backward compatibility and will be removed in next operator api release
ClusterTasksParam: defaultParamValue,
CommunityClusterTasks: defaultParamValue,
CommunityTasks: defaultParamValue,
PipelineTemplatesParam: defaultParamValue,
ResolverTasks: defaultParamValue,
ResolverStepActions: defaultParamValue,
Expand Down
87 changes: 87 additions & 0 deletions pkg/reconciler/openshift/tektonaddon/community_tasks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
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 tektonaddon

import (
"context"
"strings"

mf "github.com/manifestival/manifestival"
"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
"github.com/tektoncd/operator/pkg/reconciler/common"
"github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset/client"
)

var communityResourceURLs = []string{
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/jib-maven/0.5/jib-maven.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/helm-upgrade-from-source/0.3/helm-upgrade-from-source.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/helm-upgrade-from-repo/0.2/helm-upgrade-from-repo.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/trigger-jenkins-job/0.1/trigger-jenkins-job.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/pull-request/0.1/pull-request.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/kubeconfig-creator/0.1/kubeconfig-creator.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/main/task/argocd-task-sync-and-wait/0.2/argocd-task-sync-and-wait.yaml",
}

func (r *Reconciler) EnsureCommunityTask(ctx context.Context, enable string, ta *v1alpha1.TektonAddon) error {
if len(r.communityTaskManifest.Resources()) == 0 {
return nil
}
manifest := *r.communityTaskManifest
if enable == "true" {
if err := r.installerSetClient.CustomSet(ctx, ta, CommunityTaskInstallerSet, &manifest, filterAndTransformCommunityTask(), nil); err != nil {
return err
}
} else {
if err := r.installerSetClient.CleanupCustomSet(ctx, CommunityTaskInstallerSet); err != nil {
return err
}
}
return nil
}

func filterAndTransformCommunityTask() client.FilterAndTransform {
return func(ctx context.Context, manifest *mf.Manifest, comp v1alpha1.TektonComponent) (*mf.Manifest, error) {
instance := comp.(*v1alpha1.TektonAddon)
addonImages := common.ToLowerCaseKeys(common.ImagesFromEnv(common.AddonsImagePrefix))

extra := []mf.Transformer{
injectLabel(labelProviderType, providerTypeCommunity, overwrite, "Task"),
common.TaskImages(ctx, addonImages),
}
if err := common.Transform(ctx, manifest, instance, extra...); err != nil {
return nil, err
}
return manifest, nil
}
}

func appendCommunityTasks(manifest *mf.Manifest) error {
urls := strings.Join(communityResourceURLs, ",")
m, err := mf.ManifestFrom(mf.Path(urls))
if err != nil {
return err
}
*manifest = manifest.Append(m)
return nil
}

func fetchCommunityTasks(manifest *mf.Manifest) error {
if err := appendCommunityTasks(manifest); err != nil {
return err
}
return nil
}
1 change: 1 addition & 0 deletions pkg/reconciler/openshift/tektonaddon/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
OpenShiftConsoleInstallerSet = "OpenShiftConsole"
VersionedResolverTaskInstallerSet = "VersionedResolverTask"
VersionedResolverStepActionInstallerSet = "VersionedResolverStepAction"
CommunityTaskInstallerSet = "CommunityTask"
versionedClusterTaskPatchChar = "0"
PipelinesTemplateInstallerSet = "PipelinesTemplate"
TriggersResourcesInstallerSet = "TriggersResources"
Expand Down
7 changes: 7 additions & 0 deletions pkg/reconciler/openshift/tektonaddon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro
logger.Fatalf("failed to read console cli from kodata: %v", err)
}

communityTaskManifest := &mf.Manifest{}
if err := fetchCommunityTasks(communityTaskManifest); err != nil {
// if unable to fetch community task, don't fail
logger.Errorf("failed to read community task: %v", err)
}

c := &Reconciler{
crdClientSet: crdClient,
installerSetClient: client.NewInstallerSetClient(tisClient, version, "addon", v1alpha1.KindTektonAddon, metrics),
Expand All @@ -129,6 +135,7 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro
pipelineTemplateManifest: pipelineTemplateManifest,
openShiftConsoleManifest: openShiftConsoleManifest,
consoleCLIManifest: consoleCLIManifest,
communityTaskManifest: communityTaskManifest,
}
impl := tektonAddonreconciler.NewImpl(ctx, c)

Expand Down
9 changes: 9 additions & 0 deletions pkg/reconciler/openshift/tektonaddon/tektonaddon.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Reconciler struct {
pipelineTemplateManifest *mf.Manifest
openShiftConsoleManifest *mf.Manifest
consoleCLIManifest *mf.Manifest
communityTaskManifest *mf.Manifest
}

const (
Expand All @@ -64,6 +65,7 @@ const (
providerTypeRedHat = "redhat"
installerSetNameForResolverTasks = "addon-versioned-resolvertasks"
installerSetNameForResolverStepAction = "addon-versioned-resolverstepactions"
providerTypeCommunity = "community"
)

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

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

if err := r.EnsureCommunityTask(ctx, ctVal, ta); err != nil {
ready = false
errorMsg = fmt.Sprintf("community tasks not yet ready: %v", err)
logger.Error(errorMsg)
}

if !ready {
ta.Status.MarkInstallerSetNotReady(errorMsg)
return nil
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/common/00_tektonconfigdeployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (s *TektonConfigTestSuite) Test05_DisableAndEnableAddons() {
tc := s.getCurrentConfig(timeout)
tc.Spec.Addon.Params = []v1alpha1.Param{
{Name: v1alpha1.ClusterTasksParam, Value: "false"},
{Name: v1alpha1.CommunityClusterTasks, Value: "false"},
{Name: v1alpha1.CommunityTasks, Value: "false"},
{Name: v1alpha1.PipelineTemplatesParam, Value: "false"},
}
_, err := s.clients.TektonConfig().Update(context.TODO(), tc, metav1.UpdateOptions{})
Expand Down
1 change: 1 addition & 0 deletions test/resources/tektonaddons.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func AssertTektonInstallerSets(t *testing.T, clients *utils.Clients) {
assertInstallerSets(t, clients, tektonaddon.TriggersResourcesInstallerSet)
assertInstallerSets(t, clients, tektonaddon.ConsoleCLIInstallerSet)
assertInstallerSets(t, clients, tektonaddon.MiscellaneousResourcesInstallerSet)
assertInstallerSets(t, clients, tektonaddon.CommunityTaskInstallerSet)
}

func assertInstallerSets(t *testing.T, clients *utils.Clients, component string) {
Expand Down
2 changes: 1 addition & 1 deletion test/resources/tektonconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func EnsureTektonConfigExists(kubeClientSet *kubernetes.Clientset, clients opera
Value: "true",
},
{
Name: "communityClusterTasks",
Name: "communityTasks",
Value: "true",
},
},
Expand Down

0 comments on commit dc9939d

Please sign in to comment.