diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 73e0f99470..e573e0af52 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -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) @@ -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 diff --git a/Makefile b/Makefile index 374bcd9346..d0d78d0aee 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/cmd/openshift/operator/kodata/tekton-addon/tekton-pipeline-template/pipeline_using_workspace.yaml b/cmd/openshift/operator/kodata/tekton-addon/tekton-pipeline-template/pipeline_using_workspace.yaml index eb1cfe39a3..f395191456 100644 --- a/cmd/openshift/operator/kodata/tekton-addon/tekton-pipeline-template/pipeline_using_workspace.yaml +++ b/cmd/openshift/operator/kodata/tekton-addon/tekton-pipeline-template/pipeline_using_workspace.yaml @@ -22,8 +22,10 @@ spec: tasks: - name: fetch-repository taskRef: - name: git-clone - kind: ClusterTask + resolver: cluster + params: + - name: git-clone-task + value: git-clone workspaces: - name: output workspace: workspace @@ -39,7 +41,10 @@ spec: - name: build taskRef: - kind: ClusterTask + resolver: cluster + params: + - name: build-task + value: s2i runAfter: - fetch-repository workspaces: diff --git a/config/crs/openshift/config/all/operator_v1alpha1_config_cr.yaml b/config/crs/openshift/config/all/operator_v1alpha1_config_cr.yaml index ecb413e3b7..9f21a16e35 100644 --- a/config/crs/openshift/config/all/operator_v1alpha1_config_cr.yaml +++ b/config/crs/openshift/config/all/operator_v1alpha1_config_cr.yaml @@ -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 diff --git a/docs/TektonAddon.md b/docs/TektonAddon.md index a134ea1c36..63c6d623c3 100644 --- a/docs/TektonAddon.md +++ b/docs/TektonAddon.md @@ -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, resolverStepActions 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. @@ -22,8 +22,6 @@ metadata: spec: targetNamespace: openshift-pipelines params: - - name: clusterTasks - value: "true" - name: pipelineTemplates value: "true" - name: resolverTasks @@ -37,12 +35,10 @@ 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`. +- Pipelines templates uses tasks from `openshift-pipelines` in them so to install pipelineTemplates, resolverTasks must be `true` \ No newline at end of file diff --git a/docs/TektonConfig.md b/docs/TektonConfig.md index 5f6c98035e..c71e4a36c7 100644 --- a/docs/TektonConfig.md +++ b/docs/TektonConfig.md @@ -329,7 +329,7 @@ By default pruner job will be created from the global pruner config (`spec.prune > `keep: 100`
### 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). @@ -337,8 +337,6 @@ Example: ```yaml addon: params: - - name: "clusterTask" - value: "true" - name: "pipelineTemplates" value: "true" - name: "resolverTasks" diff --git a/hack/fetch-releases.sh b/hack/fetch-releases.sh index 616d7942de..da7f40406d 100755 --- a/hack/fetch-releases.sh +++ b/hack/fetch-releases.sh @@ -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" diff --git a/hack/openshift/fetch-tektoncd-catalog-tasks.sh b/hack/openshift/fetch-tektoncd-catalog-tasks.sh index e479c22a54..3221a12116 100755 --- a/hack/openshift/fetch-tektoncd-catalog-tasks.sh +++ b/hack/openshift/fetch-tektoncd-catalog-tasks.sh @@ -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 } @@ -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" diff --git a/operatorhub/openshift/manifests/bases/openshift-pipelines-operator-rh.clusterserviceversion.template.yaml b/operatorhub/openshift/manifests/bases/openshift-pipelines-operator-rh.clusterserviceversion.template.yaml index d6a5545d4e..09d484239f 100644 --- a/operatorhub/openshift/manifests/bases/openshift-pipelines-operator-rh.clusterserviceversion.template.yaml +++ b/operatorhub/openshift/manifests/bases/openshift-pipelines-operator-rh.clusterserviceversion.template.yaml @@ -111,7 +111,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 Tasks, StepActions, consoleyamlsamples, consoleclidownloads and consolequickstarts) displayName: Tekton Addons kind: TektonAddon name: tektonaddons.operator.tekton.dev diff --git a/pkg/apis/operator/v1alpha1/const.go b/pkg/apis/operator/v1alpha1/const.go index 26d76bf871..2b622e8d66 100644 --- a/pkg/apis/operator/v1alpha1/const.go +++ b/pkg/apis/operator/v1alpha1/const.go @@ -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" @@ -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, } diff --git a/pkg/apis/operator/v1alpha1/tektonaddon_default_test.go b/pkg/apis/operator/v1alpha1/tektonaddon_default_test.go index e3d1785696..10b695fa70 100644 --- a/pkg/apis/operator/v1alpha1/tektonaddon_default_test.go +++ b/pkg/apis/operator/v1alpha1/tektonaddon_default_test.go @@ -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{ @@ -61,7 +61,7 @@ func Test_AddonSetDefaults_ClusterTaskIsFalse(t *testing.T) { Addon: Addon{ Params: []Param{ { - Name: "clusterTasks", + Name: "resolverTasks", Value: "false", }, }, @@ -73,7 +73,39 @@ 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) } + +func Test_AddonSetDefaults_ResolverStepActions(t *testing.T) { + + ta := &TektonAddon{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "namespace", + }, + Spec: TektonAddonSpec{ + CommonSpec: CommonSpec{ + TargetNamespace: "namespace", + }, + Addon: Addon{ + Params: []Param{ + { + Name: "resolverStepActions", + Value: "false", + }, + }, + }, + }, + } + + ta.SetDefaults(context.TODO()) + assert.Equal(t, 5, len(ta.Spec.Params)) + + params := ParseParams(ta.Spec.Params) + value, ok := params[ResolverStepActions] + assert.Equal(t, true, ok) + assert.Equal(t, "false", value) +} + diff --git a/pkg/apis/operator/v1alpha1/tektonaddon_defaults.go b/pkg/apis/operator/v1alpha1/tektonaddon_defaults.go index fc974b6be7..c947b33de0 100644 --- a/pkg/apis/operator/v1alpha1/tektonaddon_defaults.go +++ b/pkg/apis/operator/v1alpha1/tektonaddon_defaults.go @@ -28,11 +28,11 @@ func setAddonDefaults(addon *Addon) { paramsMap := ParseParams(addon.Params) _, ptOk := paramsMap[PipelineTemplatesParam] - ct, ctOk := paramsMap[ClusterTasksParam] + rt, rtOk := paramsMap[ResolverTasks] - // 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) { + // If ResolverTask is false and pipelineTemplate is not set, then set it as false + // as pipelines templates are created using ResolverTask + if rtOk && (rt == "false" && !ptOk) { addon.Params = append(addon.Params, Param{ Name: PipelineTemplatesParam, Value: "false", diff --git a/pkg/apis/operator/v1alpha1/tektonaddon_validation.go b/pkg/apis/operator/v1alpha1/tektonaddon_validation.go index bcd011d32b..bc0156e27f 100644 --- a/pkg/apis/operator/v1alpha1/tektonaddon_validation.go +++ b/pkg/apis/operator/v1alpha1/tektonaddon_validation.go @@ -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 } diff --git a/pkg/apis/operator/v1alpha1/tektonaddon_validation_test.go b/pkg/apis/operator/v1alpha1/tektonaddon_validation_test.go index f37d19c656..909007fd62 100644 --- a/pkg/apis/operator/v1alpha1/tektonaddon_validation_test.go +++ b/pkg/apis/operator/v1alpha1/tektonaddon_validation_test.go @@ -85,7 +85,7 @@ func Test_ValidateTektonAddon_InvalidParamValue(t *testing.T) { Addon: Addon{ Params: []Param{ { - Name: "clusterTasks", + Name: "resolverTasks", Value: "test", }, }, @@ -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()) } diff --git a/pkg/apis/operator/v1alpha1/tektonconfig_validation_test.go b/pkg/apis/operator/v1alpha1/tektonconfig_validation_test.go index 5ab0bcc545..3c1223df0d 100644 --- a/pkg/apis/operator/v1alpha1/tektonconfig_validation_test.go +++ b/pkg/apis/operator/v1alpha1/tektonconfig_validation_test.go @@ -170,7 +170,7 @@ func Test_ValidateTektonConfig_InvalidAddonParamValue(t *testing.T) { Addon: Addon{ Params: []Param{ { - Name: "clusterTasks", + Name: "resolverTasks", Value: "test", }, }, @@ -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) { diff --git a/pkg/reconciler/openshift/tektonaddon/cluster_task.go b/pkg/reconciler/openshift/tektonaddon/cluster_task.go deleted file mode 100644 index bd3e1e528c..0000000000 --- a/pkg/reconciler/openshift/tektonaddon/cluster_task.go +++ /dev/null @@ -1,78 +0,0 @@ -/* -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" - "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) - return formattedVersionSnake(ver) -} - -func formattedVersionSnake(version string) string { - ver := strings.TrimPrefix(version, "v") - return strings.Replace(ver, ".", "-", -1) -} - -// To get the minor major version for label i.e. v1.6 -func getPatchVersionTrimmed(version string) string { - endIndex := strings.LastIndex(version, ".") - if endIndex != -1 { - version = version[:endIndex] - } - return version -} diff --git a/pkg/reconciler/openshift/tektonaddon/cluster_task_versioned.go b/pkg/reconciler/openshift/tektonaddon/cluster_task_versioned.go deleted file mode 100644 index c5d76b83b4..0000000000 --- a/pkg/reconciler/openshift/tektonaddon/cluster_task_versioned.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -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" - - mf "github.com/manifestival/manifestival" - "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" - "github.com/tektoncd/operator/pkg/reconciler/common" -) - -func (r *Reconciler) EnsureVersionedClusterTask(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), - setVersionedNames(r.operatorVersion), - } - if err := r.installerSetClient.VersionedTaskSet(ctx, ta, &manifest, filterAndTransformClusterTask(tfs), - VersionedClusterTaskInstallerSet, installerSetNameForClusterTasks); err != nil { - return err - } - } else { - if err := r.installerSetClient.CleanupCustomSet(ctx, VersionedClusterTaskInstallerSet); err != nil { - return err - } - } - return nil -} diff --git a/pkg/reconciler/openshift/tektonaddon/community_cluster_tasks.go b/pkg/reconciler/openshift/tektonaddon/community_cluster_tasks.go deleted file mode 100644 index c62b96ab0e..0000000000 --- a/pkg/reconciler/openshift/tektonaddon/community_cluster_tasks.go +++ /dev/null @@ -1,89 +0,0 @@ -/* -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/git-cli/0.4/git-cli.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) EnsureCommunityClusterTask(ctx context.Context, enable string, ta *v1alpha1.TektonAddon) error { - if len(r.communityClusterTaskManifest.Resources()) == 0 { - return nil - } - manifest := *r.communityClusterTaskManifest - if enable == "true" { - if err := r.installerSetClient.CustomSet(ctx, ta, CommunityClusterTaskInstallerSet, &manifest, filterAndTransformCommunityClusterTask(), nil); err != nil { - return err - } - } else { - if err := r.installerSetClient.CleanupCustomSet(ctx, CommunityClusterTaskInstallerSet); err != nil { - return err - } - } - return nil -} - -func filterAndTransformCommunityClusterTask() 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{ - replaceKind("Task", "ClusterTask"), - injectLabel(labelProviderType, providerTypeCommunity, overwrite, "ClusterTask"), - 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 -} diff --git a/pkg/reconciler/openshift/tektonaddon/const.go b/pkg/reconciler/openshift/tektonaddon/const.go index 287f406384..89e56a911b 100644 --- a/pkg/reconciler/openshift/tektonaddon/const.go +++ b/pkg/reconciler/openshift/tektonaddon/const.go @@ -19,10 +19,7 @@ package tektonaddon const ( ResolverTaskInstallerSet = "ResolverTask" ResolverStepActionInstallerSet = "ResolverStepAction" - ClusterTaskInstallerSet = "ClusterTask" OpenShiftConsoleInstallerSet = "OpenShiftConsole" - CommunityClusterTaskInstallerSet = "CommunityClusterTask" - VersionedClusterTaskInstallerSet = "VersionedClusterTask" VersionedResolverTaskInstallerSet = "VersionedResolverTask" VersionedResolverStepActionInstallerSet = "VersionedResolverStepAction" versionedClusterTaskPatchChar = "0" @@ -35,5 +32,4 @@ const ( CreatedByValue = "TektonAddon" KindTask = "Task" KindStepAction = "StepAction" - KindClusterTask = "ClusterTask" ) diff --git a/pkg/reconciler/openshift/tektonaddon/controller.go b/pkg/reconciler/openshift/tektonaddon/controller.go index 4e035bd72c..5b25920577 100644 --- a/pkg/reconciler/openshift/tektonaddon/controller.go +++ b/pkg/reconciler/openshift/tektonaddon/controller.go @@ -88,17 +88,6 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro logger.Fatalf("failed to read namespaced stepactions from kodata: %v", err) } - clusterTaskManifest := &mf.Manifest{} - if err := applyAddons(clusterTaskManifest, "02-clustertasks"); err != nil { - logger.Fatalf("failed to read clustertask from kodata: %v", err) - } - - communityClusterTaskManifest := &mf.Manifest{} - if err := fetchCommunityTasks(communityClusterTaskManifest); err != nil { - // if unable to fetch community task, don't fail - logger.Errorf("failed to read community task: %v", err) - } - triggersResourcesManifest := &mf.Manifest{} if err := applyAddons(triggersResourcesManifest, "01-clustertriggerbindings"); err != nil { logger.Fatalf("failed to read trigger Resources from kodata: %v", err) @@ -126,22 +115,20 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro } 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, - clusterTaskManifest: clusterTaskManifest, - triggersResourcesManifest: triggersResourcesManifest, - pipelineTemplateManifest: pipelineTemplateManifest, - communityClusterTaskManifest: communityClusterTaskManifest, - 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, } impl := tektonAddonreconciler.NewImpl(ctx, c) diff --git a/pkg/reconciler/openshift/tektonaddon/tektonaddon.go b/pkg/reconciler/openshift/tektonaddon/tektonaddon.go index 1619cc2ed1..18735d2381 100644 --- a/pkg/reconciler/openshift/tektonaddon/tektonaddon.go +++ b/pkg/reconciler/openshift/tektonaddon/tektonaddon.go @@ -41,21 +41,19 @@ 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 - clusterTaskManifest *mf.Manifest - triggersResourcesManifest *mf.Manifest - pipelineTemplateManifest *mf.Manifest - communityClusterTaskManifest *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 } const ( @@ -63,11 +61,9 @@ const ( overwrite labelProviderType = "operator.tekton.dev/provider-type" - providerTypeCommunity = "community" providerTypeRedHat = "redhat" installerSetNameForResolverTasks = "addon-versioned-resolvertasks" installerSetNameForResolverStepAction = "addon-versioned-resolverstepactions" - installerSetNameForClusterTasks = "addon-versioned-clustertasks" ) // Check that our Reconciler implements controller.Reconciler @@ -133,13 +129,11 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon // validate the params ptVal, _ := findValue(ta.Spec.Params, v1alpha1.PipelineTemplatesParam) - ctVal, _ := findValue(ta.Spec.Params, v1alpha1.ClusterTasksParam) - cctVal, _ := findValue(ta.Spec.Params, v1alpha1.CommunityClusterTasks) rtVal, _ := findValue(ta.Spec.Params, v1alpha1.ResolverTasks) rsaVal, _ := findValue(ta.Spec.Params, v1alpha1.ResolverStepActions) - if ptVal == "true" && ctVal == "false" { - ta.Status.MarkNotReady("pipelineTemplates cannot be true if clusterTask is false") + if ptVal == "true" && rtVal == "false" { + ta.Status.MarkNotReady("pipelineTemplates cannot be true if ResolverTask is false") return nil } @@ -182,24 +176,6 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon logger.Error(errorMsg) } - if err := r.EnsureClusterTask(ctx, ctVal, ta); err != nil { - ready = false - errorMsg = fmt.Sprintf("cluster tasks not yet ready: %v", err) - logger.Error(errorMsg) - } - - if err := r.EnsureVersionedClusterTask(ctx, ctVal, ta); err != nil { - ready = false - errorMsg = fmt.Sprintf("versioned cluster tasks not yet ready: %v", err) - logger.Error(errorMsg) - } - - if err := r.EnsureCommunityClusterTask(ctx, cctVal, ta); err != nil { - ready = false - errorMsg = fmt.Sprintf("community cluster tasks not yet ready: %v", err) - logger.Error(errorMsg) - } - if err := r.EnsurePipelineTemplates(ctx, ptVal, ta); err != nil { ready = false errorMsg = fmt.Sprintf("pipelines templates not yet ready: %v", err) diff --git a/pkg/reconciler/openshift/tektonaddon/transform.go b/pkg/reconciler/openshift/tektonaddon/transform.go index 489295fc8a..599520fa3a 100644 --- a/pkg/reconciler/openshift/tektonaddon/transform.go +++ b/pkg/reconciler/openshift/tektonaddon/transform.go @@ -37,7 +37,6 @@ func transformers(ctx context.Context, manifest *mf.Manifest, comp v1alpha1.Tekt // However, it is recomended to use InjectOperandNameLabelPreserveExisting here (in Addons) as we cannot be sure // about order of future addition of transformers in this reconciler or in sub functions which take care of various addons common.InjectOperandNameLabelPreserveExisting(openshift.OperandOpenShiftPipelinesAddons), - injectLabel(labelProviderType, providerTypeRedHat, overwrite, "ClusterTask"), common.TaskImages(ctx, addonImages), } addonTfs = append(addonTfs, addnTfs...) diff --git a/pkg/reconciler/openshift/tektonaddon/transformer.go b/pkg/reconciler/openshift/tektonaddon/transformer.go index 33fb2ecf48..cad56101b7 100644 --- a/pkg/reconciler/openshift/tektonaddon/transformer.go +++ b/pkg/reconciler/openshift/tektonaddon/transformer.go @@ -18,6 +18,7 @@ package tektonaddon import ( "fmt" + "strings" mf "github.com/manifestival/manifestival" console "github.com/openshift/api/console/v1" @@ -25,17 +26,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) -func replaceKind(fromKind, toKind string) mf.Transformer { - return func(u *unstructured.Unstructured) error { - kind := u.GetKind() - if kind != fromKind { - return nil - } - u.SetKind(toKind) - return nil - } -} - // injectLabel adds label key:value to a resource // overwritePolicy (Retain/Overwrite) decides whehther to overwrite an already existing label // []kinds specify the Kinds on which the label should be applied @@ -129,7 +119,7 @@ func replaceURLCCD(baseURL string) mf.Transformer { func setVersionedNames(operatorVersion string) mf.Transformer { return func(u *unstructured.Unstructured) error { - if u.GetKind() != "ClusterTask" && u.GetKind() != "Task" && u.GetKind() != "StepAction" { + if u.GetKind() != "Task" && u.GetKind() != "StepAction" { return nil } name := u.GetName() @@ -139,3 +129,23 @@ func setVersionedNames(operatorVersion string) mf.Transformer { return nil } } + +func formattedVersionMajorMinorX(version, x string) string { + ver := getPatchVersionTrimmed(version) + ver = fmt.Sprintf("%s.%s", ver, x) + return formattedVersionSnake(ver) +} + +func formattedVersionSnake(version string) string { + ver := strings.TrimPrefix(version, "v") + return strings.Replace(ver, ".", "-", -1) +} + +// To get the minor major version for label i.e. v1.6 +func getPatchVersionTrimmed(version string) string { + endIndex := strings.LastIndex(version, ".") + if endIndex != -1 { + version = version[:endIndex] + } + return version +} diff --git a/pkg/reconciler/openshift/tektonaddon/transformer_test.go b/pkg/reconciler/openshift/tektonaddon/transformer_test.go index 5a1c2d4af2..8e25594437 100644 --- a/pkg/reconciler/openshift/tektonaddon/transformer_test.go +++ b/pkg/reconciler/openshift/tektonaddon/transformer_test.go @@ -58,27 +58,24 @@ func TestUpdateConsoleCLIDownload(t *testing.T) { } func TestSetVersionedNames(t *testing.T) { - tests := []struct { + tests := []struct{ name string inputPath string expectedPath string errorMessage string - }{{ - name: "test for versioned clustertask", - inputPath: "test-versioned-clustertask-name.yaml", - expectedPath: "test-versioned-clustertask-name-expected.yaml", - errorMessage: "failed to update versioned clustertask name %s", - }, { + }{ + { name: "test for versioned resolver task", inputPath: "test-versioned-resolvertask-name.yaml", expectedPath: "test-versioned-resolver-name-expected.yaml", errorMessage: "failed to update versioned resolver task name %s", - }, { + }, + { name: "test for versioned resolver stepaction", inputPath: "test-versioned-resolverstepaction-name.yaml", expectedPath: "test-versioned-resolver-stepaction-expected.yaml", errorMessage: "failed to update versioned resolver stepaction name %s", - }} + },} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/reconciler/shared/tektonconfig/upgrade/post_upgrade.go b/pkg/reconciler/shared/tektonconfig/upgrade/post_upgrade.go index 18a746afe5..689eeb0224 100644 --- a/pkg/reconciler/shared/tektonconfig/upgrade/post_upgrade.go +++ b/pkg/reconciler/shared/tektonconfig/upgrade/post_upgrade.go @@ -18,16 +18,26 @@ package upgrade import ( "context" + "fmt" + "strings" + "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/client/clientset/versioned" + + "github.com/tektoncd/operator/pkg/reconciler/common" upgrade "github.com/tektoncd/operator/pkg/reconciler/shared/tektonconfig/upgrade/helper" "go.uber.org/zap" apixclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" ) +const ( + customType = "custom" +) + // performs storage versions upgrade // lists all the resources and keeps only one storage version func upgradeStorageVersion(ctx context.Context, logger *zap.SugaredLogger, k8sClient kubernetes.Interface, operatorClient versioned.Interface, restConfig *rest.Config) error { @@ -70,3 +80,66 @@ func upgradeStorageVersion(ctx context.Context, logger *zap.SugaredLogger, k8sCl return nil } + +// Remove the all cluster tasks installer sets +func removeAllClusterTasksInstallerSets(ctx context.Context, logger *zap.SugaredLogger, k8sClient kubernetes.Interface, operatorClient versioned.Interface, restConfig *rest.Config) error { + + if !v1alpha1.IsOpenShiftPlatform() { + return nil + } + + tisClient := operatorClient.OperatorV1alpha1().TektonInstallerSets() + + ctLS := v1.LabelSelector{ + MatchLabels: map[string]string{ + v1alpha1.InstallerSetType: installerSetType(customType, "ClusterTask"), + }, + } + ctLabel, err := common.LabelSelector(ctLS) + if err != nil { + return err + } + if err := tisClient.DeleteCollection(ctx, v1.DeleteOptions{}, v1.ListOptions{ + LabelSelector: ctLabel, + }); err != nil { + logger.Error("Failed to delete the ClusterTask installer set", err) + return err + } + + cctLS := v1.LabelSelector{ + MatchLabels: map[string]string{ + v1alpha1.InstallerSetType: installerSetType(customType, "CommunityClusterTask"), + }, + } + cctLabel, err := common.LabelSelector(cctLS) + if err != nil { + return err + } + if err := tisClient.DeleteCollection(ctx, v1.DeleteOptions{}, v1.ListOptions{ + LabelSelector: cctLabel, + }); err != nil { + logger.Error("Failed to delete the CommunityClusterTask installer set", err) + return err + } + + vctLS := v1.LabelSelector{ + MatchLabels: map[string]string{ + v1alpha1.InstallerSetType: installerSetType(customType, "VersionedClusterTask"), + }, + } + vctLabel, err := common.LabelSelector(vctLS) + if err != nil { + return err + } + if err := tisClient.DeleteCollection(ctx, v1.DeleteOptions{}, v1.ListOptions{ + LabelSelector: vctLabel, + }); err != nil { + logger.Error("Failed to delete the VersionedClusterTask installer set", err) + return err + } + + return nil +} +func installerSetType(installerType, insType string) string { + return fmt.Sprintf("%s-%s", installerType, strings.ToLower(insType)) +} diff --git a/pkg/reconciler/shared/tektonconfig/upgrade/upgrade.go b/pkg/reconciler/shared/tektonconfig/upgrade/upgrade.go index 41b6cf150e..69a3960d66 100644 --- a/pkg/reconciler/shared/tektonconfig/upgrade/upgrade.go +++ b/pkg/reconciler/shared/tektonconfig/upgrade/upgrade.go @@ -38,7 +38,8 @@ var ( // post upgrade functions postUpgradeFunctions = []upgradeFunc{ - upgradeStorageVersion, // upgrade #1: performs storage version migration + upgradeStorageVersion, // upgrade #1: performs storage version migration + removeAllClusterTasksInstallerSets, // Remove all cluster tasks installersets } ) diff --git a/test/resources/tektonaddons.go b/test/resources/tektonaddons.go index b9f3cc1ec4..900a377f85 100644 --- a/test/resources/tektonaddons.go +++ b/test/resources/tektonaddons.go @@ -96,10 +96,9 @@ func AssertTektonAddonCRReadyStatus(t *testing.T, clients *utils.Clients, names // AssertTektonInstallerSets verifies if the TektonInstallerSets are created. func AssertTektonInstallerSets(t *testing.T, clients *utils.Clients) { - assertInstallerSets(t, clients, tektonaddon.CommunityClusterTaskInstallerSet) - assertInstallerSets(t, clients, tektonaddon.ClusterTaskInstallerSet) - assertInstallerSets(t, clients, tektonaddon.VersionedClusterTaskInstallerSet) assertInstallerSets(t, clients, tektonaddon.PipelinesTemplateInstallerSet) + assertInstallerSets(t, clients, tektonaddon.ResolverTaskInstallerSet) + assertInstallerSets(t, clients, tektonaddon.ResolverStepActionInstallerSet) assertInstallerSets(t, clients, tektonaddon.TriggersResourcesInstallerSet) assertInstallerSets(t, clients, tektonaddon.ConsoleCLIInstallerSet) assertInstallerSets(t, clients, tektonaddon.MiscellaneousResourcesInstallerSet)