Skip to content

Commit

Permalink
Remove cluster task installersets
Browse files Browse the repository at this point in the history
This patch will remove cluster task installersets and also
remove the existing cluster task installersets during operator upgrade

Signed-off-by: Shiv Verma <[email protected]>
  • Loading branch information
pratap0007 committed Nov 7, 2024
1 parent efd8c40 commit c4c7993
Show file tree
Hide file tree
Showing 25 changed files with 127 additions and 345 deletions.
8 changes: 4 additions & 4 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- [Iterating](#iterating)
- [Install Operator](#install-operator)
- [Accessing logs](#accessing-logs)
- [Updating the clustertasks in OpenShift addons](#updating-the-clustertasks-in-openshift-addons)
- [Updating the tasks in OpenShift addons](#updating-the-tasks-in-openshift-addons)
- [Running Codegen](#running-codegen)
- [Setup development environment on localhost](#setup-development-environment-on-localhost)
- [Pre-requests](#pre-requests)
Expand Down Expand Up @@ -206,16 +206,16 @@ watch this space!**
**Note: this needs to be completed! We don't yet have any code or config to deploy,
watch this space!**

## Updating the clustertasks in OpenShift addons
## Updating the tasks in OpenShift addons

You can update the clustertasks present in the codebase with the latest using the script present at `/hack/openshift/update-tasks.sh`
You can update the tasks present in the codebase with the latest using the script present at `/hack/openshift/update-tasks.sh`

You can edit the script to mention the specific version of the task or to add a new task.

Then all the tasks mentioned in the script can be added to codebase using

```shell
./hack/openshift/fetch-tektoncd-catalog-tasks.sh cmd/openshift/operator/kodata/tekton-addon/addons/02-clustertasks/source_external
./hack/openshift/fetch-tektoncd-catalog-tasks.sh cmd/openshift/operator/kodata/tekton-addon/addons/02-tasks/source_external
```
## Running Codegen

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ifeq ($(TARGET), openshift)
rm -rf ./cmd/$(TARGET)/operator/kodata/manual-approval-gate
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-pruner
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/pipelines-as-code
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/addons/02-clustertasks/source_external/
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/addons/02-tasks/source_external/
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/addons/07-ecosystem/tasks
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/addons/07-ecosystem/stepactions
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/pipelines-as-code-templates/go.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ spec:
targetNamespace: openshift-pipelines
addon:
params:
- name: clusterTasks
value: "true"
- name: pipelineTemplates
value: "true"
- name: communityClusterTasks
value: "true"
- name: resolverTasks
value: "true"
- name: resolverStepActions
Expand Down
7 changes: 1 addition & 6 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 clusterTasks and pipelineTemplate along with Pipelines.
TektonAddon custom resource allows user to install resource like resolverTasks 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 @@ -22,8 +22,6 @@ metadata:
spec:
targetNamespace: openshift-pipelines
params:
- name: clusterTasks
value: "true"
- name: pipelineTemplates
value: "true"
- name: resolverTasks
Expand All @@ -37,12 +35,9 @@ You can install this component using [TektonConfig](./TektonConfig.md) by choosi

params provide a way to enable/disable the installation of resources.
Available params are

- `clusterTasks` (Default: `true`)
- `pipelineTemplates` (Default: `true`)
- `resolverTasks` (Default: `true`)
- `resolverStepActions` (Default: `true`)

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

Pipelines templates uses clustertasks in them so to install pipelineTemplates, clusterTasks must be `true`.
4 changes: 1 addition & 3 deletions docs/TektonConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,14 @@ 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 ClusterTasks, PipelineTemplates, Tasks.
TektonAddon install some resources along with Tekton Pipelines on the cluster. This provides few PipelineTemplates, ResolverTasks and ResolverStepActions.

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

Example:
```yaml
addon:
params:
- name: "clusterTask"
value: "true"
- name: "pipelineTemplates"
value: "true"
- name: "resolverTasks"
Expand Down
2 changes: 1 addition & 1 deletion hack/fetch-releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ release_yaml_hub() {

fetch_openshift_addon_tasks() {
fetch_addon_task_script="${SCRIPT_DIR}/hack/openshift"
local dest_dir="cmd/openshift/operator/kodata/tekton-addon/addons/02-clustertasks/source_external"
local dest_dir="cmd/openshift/operator/kodata/tekton-addon/addons/02-tasks/source_external"
${fetch_addon_task_script}/fetch-tektoncd-catalog-tasks.sh ${dest_dir}
dest_dir='cmd/openshift/operator/kodata/tekton-addon/addons/07-ecosystem/tasks'
${fetch_addon_task_script}/fetch-tektoncd-catalog-tasks.sh ${dest_dir} "ecosystem_tasks"
Expand Down
4 changes: 2 additions & 2 deletions hack/openshift/fetch-tektoncd-catalog-tasks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ USAGE:
$SCRIPT_NAME DEST_DIR
Example:
$SCRIPT_NAME cmd/openshift/operator/kodata/tekton-addon/addons/02-clustertasks/source_external
$SCRIPT_NAME cmd/openshift/operator/kodata/tekton-addon/addons/02-tasks/source_external
EOF
exit 1
}
Expand Down Expand Up @@ -142,7 +142,7 @@ main() {

case "$type" in
"default")
dest_dir=${1:-'cmd/openshift/operator/kodata/tekton-addon/addons/02-clustertasks/source_external'}
dest_dir=${1:-'cmd/openshift/operator/kodata/tekton-addon/addons/02-tasks/source_external'}
resources=TEKTON_CATALOG_TASKS
branch="main"
catalog="$TEKTON_CATALOG"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ spec:
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:label
version: v1alpha1
- description: Represents an installation of latest version of Addons (exclusively ClusterTasks, consoleyamlsamples, consoleclidownloads and consolequickstarts)
- description: Represents an installation of latest version of Addons (exclusively consoleyamlsamples, consoleclidownloads and consolequickstarts)
displayName: Tekton Addons
kind: TektonAddon
name: tektonaddons.operator.tekton.dev
Expand Down
8 changes: 6 additions & 2 deletions pkg/apis/operator/v1alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ const (
ProfileLite = "lite"

// Addon Params
// Keeping ClusterTasksParams and CommunityClusterTasks params for api compatibility
// will be removed from next api release
ClusterTasksParam = "clusterTasks"
PipelineTemplatesParam = "pipelineTemplates"
CommunityClusterTasks = "communityClusterTasks"
PipelineTemplatesParam = "pipelineTemplates"
ResolverTasks = "resolverTasks"
ResolverStepActions = "resolverStepActions"

Expand Down Expand Up @@ -111,9 +113,11 @@ var (
}

AddonParams = map[string]ParamValue{
// Keeping ClusterTasks and CommunityClusterTasks params
// for api campatibility and will be removed in next api release
ClusterTasksParam: defaultParamValue,
PipelineTemplatesParam: defaultParamValue,
CommunityClusterTasks: defaultParamValue,
PipelineTemplatesParam: defaultParamValue,
ResolverTasks: defaultParamValue,
ResolverStepActions: defaultParamValue,
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/operator/v1alpha1/tektonaddon_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func Test_AddonSetDefaults_DefaultParamsWithValues(t *testing.T) {
assert.Equal(t, 5, len(ta.Spec.Params))

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

func Test_AddonSetDefaults_ClusterTaskIsFalse(t *testing.T) {
func Test_AddonSetDefaults_ResolverTaskIsFalse(t *testing.T) {

ta := &TektonAddon{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -61,7 +61,7 @@ func Test_AddonSetDefaults_ClusterTaskIsFalse(t *testing.T) {
Addon: Addon{
Params: []Param{
{
Name: "clusterTasks",
Name: "resolverTasks",
Value: "false",
},
},
Expand All @@ -73,7 +73,7 @@ func Test_AddonSetDefaults_ClusterTaskIsFalse(t *testing.T) {
assert.Equal(t, 5, len(ta.Spec.Params))

params := ParseParams(ta.Spec.Params)
value, ok := params[PipelineTemplatesParam]
value, ok := params[ResolverTasks]
assert.Equal(t, true, ok)
assert.Equal(t, "false", value)
}
14 changes: 0 additions & 14 deletions pkg/apis/operator/v1alpha1/tektonaddon_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,8 @@ func (ta *TektonAddon) SetDefaults(ctx context.Context) {
}

func setAddonDefaults(addon *Addon) {

paramsMap := ParseParams(addon.Params)
_, ptOk := paramsMap[PipelineTemplatesParam]
ct, ctOk := paramsMap[ClusterTasksParam]

// If clusterTasks is false and pipelineTemplate is not set, then set it as false
// as pipelines templates are created using clusterTasks
if ctOk && (ct == "false" && !ptOk) {
addon.Params = append(addon.Params, Param{
Name: PipelineTemplatesParam,
Value: "false",
})
paramsMap = ParseParams(addon.Params)
}

// set the params with default values if not set in cr
for d := range AddonParams {
_, ok := paramsMap[d]
if !ok {
Expand Down
8 changes: 0 additions & 8 deletions pkg/apis/operator/v1alpha1/tektonaddon_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,5 @@ func validateAddonParams(params []Param, pathToParams string) *apis.FieldError {
}
}

paramsMap := ParseParams(params)
if (paramsMap[ClusterTasksParam] == "false") && (paramsMap[PipelineTemplatesParam] == "true") {
errs = errs.Also(apis.ErrGeneric("pipelineTemplates cannot be true if clusterTask is false", pathToParams))
}
if (paramsMap[ClusterTasksParam] == "false") && (paramsMap[CommunityClusterTasks] == "true") {
errs = errs.Also(apis.ErrGeneric("communityClusterTasks cannot be true if clusterTask is false", pathToParams))
}

return errs
}
34 changes: 2 additions & 32 deletions pkg/apis/operator/v1alpha1/tektonaddon_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Test_ValidateTektonAddon_InvalidParamValue(t *testing.T) {
Addon: Addon{
Params: []Param{
{
Name: "clusterTasks",
Name: "resolverTasks",
Value: "test",
},
},
Expand All @@ -94,35 +94,5 @@ func Test_ValidateTektonAddon_InvalidParamValue(t *testing.T) {
}

err := ta.Validate(context.TODO())
assert.Equal(t, "invalid value: test: spec.params.clusterTasks[0]", err.Error())
}

func Test_ValidateTektonAddon_ClusterTaskIsFalseAndPipelineTemplateIsTrue(t *testing.T) {

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

err := ta.Validate(context.TODO())
assert.Equal(t, "pipelineTemplates cannot be true if clusterTask is false: spec.params", err.Error())
assert.Equal(t, "invalid value: test: spec.params.resolverTasks[0]", err.Error())
}
4 changes: 2 additions & 2 deletions pkg/apis/operator/v1alpha1/tektonconfig_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func Test_ValidateTektonConfig_InvalidAddonParamValue(t *testing.T) {
Addon: Addon{
Params: []Param{
{
Name: "clusterTasks",
Name: "resolverTasks",
Value: "test",
},
},
Expand All @@ -180,7 +180,7 @@ func Test_ValidateTektonConfig_InvalidAddonParamValue(t *testing.T) {
}

err := tc.Validate(context.TODO())
assert.Equal(t, "invalid value: test: spec.addon.params.clusterTasks[0]", err.Error())
assert.Equal(t, "invalid value: test: spec.addon.params.resolverTasks[0]", err.Error())
}

func Test_ValidateTektonConfig_InvalidPipelineProperties(t *testing.T) {
Expand Down
36 changes: 0 additions & 36 deletions pkg/reconciler/openshift/tektonaddon/cluster_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,10 @@ limitations under the License.
package tektonaddon

import (
"context"
"fmt"
"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"
)

func (r *Reconciler) EnsureClusterTask(ctx context.Context, enable string, ta *v1alpha1.TektonAddon) error {
manifest := *r.clusterTaskManifest
if enable == "true" {
addonImages := common.ToLowerCaseKeys(common.ImagesFromEnv(common.AddonsImagePrefix))
tfs := []mf.Transformer{
replaceKind(KindTask, KindClusterTask),
injectLabel(labelProviderType, providerTypeRedHat, overwrite, KindClusterTask),
common.TaskImages(ctx, addonImages),
}
if err := r.installerSetClient.CustomSet(ctx, ta, ClusterTaskInstallerSet, &manifest, filterAndTransformClusterTask(tfs), nil); err != nil {
return err
}
} else {
if err := r.installerSetClient.CleanupCustomSet(ctx, ClusterTaskInstallerSet); err != nil {
return err
}
}
return nil
}

func filterAndTransformClusterTask(tfs []mf.Transformer) client.FilterAndTransform {
return func(ctx context.Context, manifest *mf.Manifest, comp v1alpha1.TektonComponent) (*mf.Manifest, error) {
addon := comp.(*v1alpha1.TektonAddon)
if err := transformers(ctx, manifest, addon, tfs...); err != nil {
return nil, err
}
return manifest, nil
}
}

func formattedVersionMajorMinorX(version, x string) string {
ver := getPatchVersionTrimmed(version)
ver = fmt.Sprintf("%s.%s", ver, x)
Expand Down
47 changes: 0 additions & 47 deletions pkg/reconciler/openshift/tektonaddon/cluster_task_versioned.go

This file was deleted.

Loading

0 comments on commit c4c7993

Please sign in to comment.