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 7, 2025
1 parent 7340583 commit 4d231f8
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 101 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
132 changes: 65 additions & 67 deletions pkg/apis/operator/v1alpha1/tektonaddon_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,87 +24,85 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func Test_AddonSetDefaults_DefaultParamsWithValues(t *testing.T) {

ta := &TektonAddon{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
func Test_AddonSetDefaults(t *testing.T) {
tests := []struct {
name string
initialParams []Param
expectedParams map[string]string
}{
{
name: "Default Params with Values",
initialParams: []Param{
{Name: PipelineTemplatesParam, Value: "true"},
},
expectedParams: map[string]string{
PipelineTemplatesParam: "true",
},
},
Spec: TektonAddonSpec{
CommonSpec: CommonSpec{
TargetNamespace: "namespace",
{
name: "Resolver Task is False",
initialParams: []Param{
{Name: ResolverTasks, Value: "false"},
},
expectedParams: map[string]string{
ResolverTasks: "false",
},
},
}

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

params := ParseParams(ta.Spec.Params)
value, ok := params[PipelineTemplatesParam]
assert.Equal(t, true, ok)
assert.Equal(t, "true", value)
}

func Test_AddonSetDefaults_ResolverTaskIsFalse(t *testing.T) {

ta := &TektonAddon{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
{
name: "Resolver Step Actions",
initialParams: []Param{
{Name: ResolverStepActions, Value: "false"},
},
expectedParams: map[string]string{
ResolverStepActions: "false",
},
},
Spec: TektonAddonSpec{
CommonSpec: CommonSpec{
TargetNamespace: "namespace",
{
name: "Community Resolver Tasks",
initialParams: []Param{
{Name: CommunityResolverTasks, Value: "false"},
},
Addon: Addon{
Params: []Param{
{
Name: "resolverTasks",
Value: "false",
},
},
expectedParams: map[string]string{
CommunityResolverTasks: "false",
},
},
}

ta.SetDefaults(context.TODO())
assert.Equal(t, 3, len(ta.Spec.Params))
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ta := &TektonAddon{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: TektonAddonSpec{
CommonSpec: CommonSpec{
TargetNamespace: "namespace",
},
Addon: Addon{
Params: tt.initialParams,
},
},
}

params := ParseParams(ta.Spec.Params)
value, ok := params[ResolverTasks]
assert.Equal(t, true, ok)
assert.Equal(t, "false", value)
ta.SetDefaults(context.TODO())
checkAddonParams(t, ta.Spec.Addon.Params, tt.expectedParams)
})
}
}

func Test_AddonSetDefaults_ResolverStepActions(t *testing.T) {
func checkAddonParams(t *testing.T, actualParams []Param, expectedParams map[string]string) {
t.Helper()

ta := &TektonAddon{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: TektonAddonSpec{
CommonSpec: CommonSpec{
TargetNamespace: "namespace",
},
Addon: Addon{
Params: []Param{
{
Name: "resolverStepActions",
Value: "false",
},
},
},
},
if len(actualParams) != len(AddonParams) {
t.Fatalf("Expected %d addon params, got %d", len(AddonParams), len(actualParams))
}

ta.SetDefaults(context.TODO())
assert.Equal(t, 3, len(ta.Spec.Params))
paramsMap := ParseParams(actualParams)

params := ParseParams(ta.Spec.Params)
value, ok := params[ResolverStepActions]
assert.Equal(t, true, ok)
assert.Equal(t, "false", value)
for key, expectedValue := range expectedParams {
value, exists := paramsMap[key]
assert.Equal(t, true, exists, "Param %q is missing in Spec.Addon.Params", key)
assert.Equal(t, expectedValue, value, "Param %q has incorrect value", key)
}
}
12 changes: 10 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,16 @@ 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)")

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

for key, expectedValue := range AddonParams {
value, exists := paramsMap[key]
assert.Equal(t, true, exists, "Param %q is missing in Spec.Addon.Params", key)
assert.Equal(t, expectedValue.Default, value, "Param %q has incorrect value", key)
}
}

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
Loading

0 comments on commit 4d231f8

Please sign in to comment.