Skip to content

Commit

Permalink
restore community tasks as openshift addons
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhelil committed Jan 6, 2025
1 parent 7340583 commit 7287d12
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 34 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: communityResolverTasks
value: "true"
params:
- name: createRbacResource
value: "true"
Expand Down
7 changes: 5 additions & 2 deletions docs/TektonAddon.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 6
-->
# Tekton Addon

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

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

Expand All @@ -38,7 +40,8 @@ Available params are
- `pipelineTemplates` (Default: `true`)
- `resolverTasks` (Default: `true`)
- `resolverStepActions` (Default: `true`)
- `communityResolverTasks` (Default: `true`)

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

- Pipelines templates uses tasks from `openshift-pipelines` in them so to install pipelineTemplates, resolverTasks must be `true`
- Pipelines templates uses tasks from `openshift-pipelines`. Therefore, to install pipelineTemplates, resolverTasks must be set to `true`
4 changes: 3 additions & 1 deletion docs/TektonConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ By default pruner job will be created from the global pruner config (`spec.prune
> `keep: 100` <br>
### Addon

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

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

Expand All @@ -343,6 +343,8 @@ addon:
value: "true"
- name: "resolverStepActions"
value: "true"
- name: "communityResolverTasks"
value: "true"
```

**NOTE**: TektonAddon is currently available for OpenShift Platform only. Enabling this for Kubernetes platform is in roadmap
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\": \"communityResolverTasks\",\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
2 changes: 2 additions & 0 deletions pkg/apis/operator/v1alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
ProfileLite = "lite"

// Addon Params
CommunityResolverTasks = "communityResolverTasks"
PipelineTemplatesParam = "pipelineTemplates"
ResolverTasks = "resolverTasks"
ResolverStepActions = "resolverStepActions"
Expand Down Expand Up @@ -109,6 +110,7 @@ var (
}

AddonParams = map[string]ParamValue{
CommunityResolverTasks: defaultParamValue,
PipelineTemplatesParam: defaultParamValue,
ResolverTasks: defaultParamValue,
ResolverStepActions: defaultParamValue,
Expand Down
31 changes: 31 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonaddon_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,34 @@ func Test_AddonSetDefaults_ResolverStepActions(t *testing.T) {
assert.Equal(t, true, ok)
assert.Equal(t, "false", value)
}

func Test_AddonSetDefaults_CommunityResolverTasks(t *testing.T) {

ta := &TektonAddon{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: TektonAddonSpec{
CommonSpec: CommonSpec{
TargetNamespace: "namespace",
},
Addon: Addon{
Params: []Param{
{
Name: "communityResolverTasks",
Value: "false",
},
},
},
},
}

ta.SetDefaults(context.TODO())
assert.Equal(t, 5, len(ta.Spec.Params))

params := ParseParams(ta.Spec.Params)
value, ok := params[CommunityResolverTasks]
assert.Equal(t, true, ok)
assert.Equal(t, "false", value)
}
28 changes: 26 additions & 2 deletions pkg/apis/operator/v1alpha1/tektonconfig_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,32 @@ func Test_SetDefaults_Addon_Params(t *testing.T) {
t.Setenv("PLATFORM", "openshift")

tc.SetDefaults(context.TODO())
if len(tc.Spec.Addon.Params) != 3 {
t.Error("Setting default failed for TektonConfig (spec.addon.params)")

expectedParams := map[string]ParamValue{
CommunityResolverTasks: defaultParamValue,
PipelineTemplatesParam: defaultParamValue,
ResolverTasks: defaultParamValue,
ResolverStepActions: defaultParamValue,
}

if len(tc.Spec.Addon.Params) != len(expectedParams) {
t.Fatalf("Expected %d addon params, got %d", len(expectedParams), len(tc.Spec.Addon.Params))
}

for k, v := range expectedParams {
found := false
for _, param := range tc.Spec.Addon.Params {
if param.Name == k {
found = true
if param.Value != v.Default {
t.Errorf("Param %q has incorrect value. Expected %q, got %q", k, v.Default, param.Value)
}
break
}
}
if !found {
t.Errorf("Param %q is missing in Spec.Addon.Params", k)
}
}
}

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 2024 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) EnsureCommunityResolverTask(ctx context.Context, enable string, ta *v1alpha1.TektonAddon) error {
if len(r.communityResolverTaskManifest.Resources()) == 0 {
return nil
}
manifest := *r.communityResolverTaskManifest
if enable == "true" {
if err := r.installerSetClient.CustomSet(ctx, ta, CommunityResolverTaskInstallerSet, &manifest, filterAndTransformCommunityResolverTask(), nil); err != nil {
return err
}
} else {
if err := r.installerSetClient.CleanupCustomSet(ctx, CommunityResolverTaskInstallerSet); err != nil {
return err
}
}
return nil
}

func filterAndTransformCommunityResolverTask() 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 appendCommunityResolverTasks(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 fetchCommunityResolverTasks(manifest *mf.Manifest) error {
if err := appendCommunityResolverTasks(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"
CommunityResolverTaskInstallerSet = "CommunityResolverTask"
versionedClusterTaskPatchChar = "0"
PipelinesTemplateInstallerSet = "PipelinesTemplate"
TriggersResourcesInstallerSet = "TriggersResources"
Expand Down
35 changes: 21 additions & 14 deletions pkg/reconciler/openshift/tektonaddon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,28 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro
logger.Fatalf("failed to read console cli from kodata: %v", err)
}

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

c := &Reconciler{
crdClientSet: crdClient,
installerSetClient: client.NewInstallerSetClient(tisClient, version, "addon", v1alpha1.KindTektonAddon, metrics),
operatorClientSet: operatorclient.Get(ctx),
extension: generator(ctx),
pipelineInformer: tektonPipelineinformer.Get(ctx),
triggerInformer: tektonTriggerinformer.Get(ctx),
manifest: manifest,
operatorVersion: version,
resolverTaskManifest: resolverTaskManifest,
resolverStepActionManifest: resolverStepActionManifest,
triggersResourcesManifest: triggersResourcesManifest,
pipelineTemplateManifest: pipelineTemplateManifest,
openShiftConsoleManifest: openShiftConsoleManifest,
consoleCLIManifest: consoleCLIManifest,
crdClientSet: crdClient,
installerSetClient: client.NewInstallerSetClient(tisClient, version, "addon", v1alpha1.KindTektonAddon, metrics),
operatorClientSet: operatorclient.Get(ctx),
extension: generator(ctx),
pipelineInformer: tektonPipelineinformer.Get(ctx),
triggerInformer: tektonTriggerinformer.Get(ctx),
manifest: manifest,
operatorVersion: version,
resolverTaskManifest: resolverTaskManifest,
resolverStepActionManifest: resolverStepActionManifest,
triggersResourcesManifest: triggersResourcesManifest,
pipelineTemplateManifest: pipelineTemplateManifest,
openShiftConsoleManifest: openShiftConsoleManifest,
consoleCLIManifest: consoleCLIManifest,
communityResolverTaskManifest: communityResolverTaskManifest,
}
impl := tektonAddonreconciler.NewImpl(ctx, c)

Expand Down
35 changes: 22 additions & 13 deletions pkg/reconciler/openshift/tektonaddon/tektonaddon.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ type Reconciler struct {
// installer Set client to do CRUD operations for components
installerSetClient *client.InstallerSetClient
// crdClientSet allows us to talk to the k8s for core APIs
crdClientSet *apiextensionsclient.Clientset
manifest mf.Manifest
operatorClientSet clientset.Interface
extension common.Extension
pipelineInformer informer.TektonPipelineInformer
triggerInformer informer.TektonTriggerInformer
operatorVersion string
resolverTaskManifest *mf.Manifest
resolverStepActionManifest *mf.Manifest
triggersResourcesManifest *mf.Manifest
pipelineTemplateManifest *mf.Manifest
openShiftConsoleManifest *mf.Manifest
consoleCLIManifest *mf.Manifest
crdClientSet *apiextensionsclient.Clientset
manifest mf.Manifest
operatorClientSet clientset.Interface
extension common.Extension
pipelineInformer informer.TektonPipelineInformer
triggerInformer informer.TektonTriggerInformer
operatorVersion string
resolverTaskManifest *mf.Manifest
resolverStepActionManifest *mf.Manifest
triggersResourcesManifest *mf.Manifest
pipelineTemplateManifest *mf.Manifest
openShiftConsoleManifest *mf.Manifest
consoleCLIManifest *mf.Manifest
communityResolverTaskManifest *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.CommunityResolverTasks)

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.EnsureCommunityResolverTask(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
1 change: 1 addition & 0 deletions test/e2e/common/00_tektonconfigdeployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ func (s *TektonConfigTestSuite) Test05_DisableAndEnableAddons() {
// disable addons and update
tc := s.getCurrentConfig(timeout)
tc.Spec.Addon.Params = []v1alpha1.Param{
{Name: v1alpha1.CommunityResolverTasks, 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.CommunityResolverTaskInstallerSet)
}

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: "communityResolverTasks",
Value: "true",
},
},
Expand Down

0 comments on commit 7287d12

Please sign in to comment.