From 92f4ddfe5df39a8208b98f54d34c1632fa1bf8e2 Mon Sep 17 00:00:00 2001 From: pratap0007 Date: Wed, 4 Dec 2024 17:28:57 +0530 Subject: [PATCH] Update TektonConfig CR's addon params to remove cluster tasks params Cluster tasks have been deprecated and removed, previous version of TektonConfig CR's addon params have the clusterTasks and communityClusterTasks params and need to remove it from the TektonConfig's addon params this removes the cluster tasks params from TektonConfig's addon params and updates it Signed-off-by: Shiv Verma ' --- pkg/apis/operator/v1alpha1/const.go | 8 ------ .../v1alpha1/tektonaddon_default_test.go | 6 ++--- .../v1alpha1/tektonconfig_default_test.go | 2 +- .../tektonconfig/upgrade/pre_upgrade.go | 27 +++++++++++++++++++ .../shared/tektonconfig/upgrade/upgrade.go | 3 ++- .../common/00_tektonconfigdeployment_test.go | 2 -- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/pkg/apis/operator/v1alpha1/const.go b/pkg/apis/operator/v1alpha1/const.go index c035e609c9..c0d8fda787 100644 --- a/pkg/apis/operator/v1alpha1/const.go +++ b/pkg/apis/operator/v1alpha1/const.go @@ -33,10 +33,6 @@ const ( ProfileLite = "lite" // Addon Params - // Keeping ClusterTasksParams and CommunityClusterTasks params for backward compatibility - // will be removed from next operator api release - ClusterTasksParam = "clusterTasks" - CommunityClusterTasks = "communityClusterTasks" PipelineTemplatesParam = "pipelineTemplates" ResolverTasks = "resolverTasks" ResolverStepActions = "resolverStepActions" @@ -113,10 +109,6 @@ var ( } AddonParams = map[string]ParamValue{ - // Keeping ClusterTasks and CommunityClusterTasks params - // for backward compatibility and will be removed in next operator api release - ClusterTasksParam: 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 5eb4c262f9..2c2dd2d7f3 100644 --- a/pkg/apis/operator/v1alpha1/tektonaddon_default_test.go +++ b/pkg/apis/operator/v1alpha1/tektonaddon_default_test.go @@ -39,7 +39,7 @@ func Test_AddonSetDefaults_DefaultParamsWithValues(t *testing.T) { } ta.SetDefaults(context.TODO()) - assert.Equal(t, 5, len(ta.Spec.Params)) + assert.Equal(t, 3, len(ta.Spec.Params)) params := ParseParams(ta.Spec.Params) value, ok := params[PipelineTemplatesParam] @@ -70,7 +70,7 @@ func Test_AddonSetDefaults_ResolverTaskIsFalse(t *testing.T) { } ta.SetDefaults(context.TODO()) - assert.Equal(t, 5, len(ta.Spec.Params)) + assert.Equal(t, 3, len(ta.Spec.Params)) params := ParseParams(ta.Spec.Params) value, ok := params[ResolverTasks] @@ -101,7 +101,7 @@ func Test_AddonSetDefaults_ResolverStepActions(t *testing.T) { } ta.SetDefaults(context.TODO()) - assert.Equal(t, 5, len(ta.Spec.Params)) + assert.Equal(t, 3, len(ta.Spec.Params)) params := ParseParams(ta.Spec.Params) value, ok := params[ResolverStepActions] diff --git a/pkg/apis/operator/v1alpha1/tektonconfig_default_test.go b/pkg/apis/operator/v1alpha1/tektonconfig_default_test.go index 7756a14e1d..3a385110b1 100644 --- a/pkg/apis/operator/v1alpha1/tektonconfig_default_test.go +++ b/pkg/apis/operator/v1alpha1/tektonconfig_default_test.go @@ -89,7 +89,7 @@ func Test_SetDefaults_Addon_Params(t *testing.T) { t.Setenv("PLATFORM", "openshift") tc.SetDefaults(context.TODO()) - if len(tc.Spec.Addon.Params) != 5 { + if len(tc.Spec.Addon.Params) != 3 { t.Error("Setting default failed for TektonConfig (spec.addon.params)") } } diff --git a/pkg/reconciler/shared/tektonconfig/upgrade/pre_upgrade.go b/pkg/reconciler/shared/tektonconfig/upgrade/pre_upgrade.go index 7373247b01..d1f0764aaa 100644 --- a/pkg/reconciler/shared/tektonconfig/upgrade/pre_upgrade.go +++ b/pkg/reconciler/shared/tektonconfig/upgrade/pre_upgrade.go @@ -75,3 +75,30 @@ func upgradePipelineProperties(ctx context.Context, logger *zap.SugaredLogger, k } return nil } + +// previous version of the TektonConfig CR's addon params has cluster task params to manage the cluster tasks +// and cluster tasks have been deprecated and removed so need to remove the clusterTasks and communityClusterTasks +// params from TektonConfig's addon params and this removes the cluster tasks params and updates TektonConfig's addon params +// Todo: remove this in the next operator release +func removeDeprecatedAddonParams(ctx context.Context, logger *zap.SugaredLogger, k8sClient kubernetes.Interface, operatorClient versioned.Interface, restConfig *rest.Config) error { + tcCR, err := operatorClient.OperatorV1alpha1().TektonConfigs().Get(ctx, v1alpha1.ConfigResourceName, metav1.GetOptions{}) + if err != nil { + if apierrs.IsNotFound(err) { + return nil + } + return err + } + + updatedParams := []v1alpha1.Param{} + for _, p := range tcCR.Spec.Addon.Params { + if p.Name == "clusterTasks" || p.Name == "communityClusterTasks" { + continue + } + updatedParams = append(updatedParams, p) + } + + // update the Tekton config's addon params + tcCR.Spec.Addon.Params = updatedParams + _, err = operatorClient.OperatorV1alpha1().TektonConfigs().Update(ctx, tcCR, metav1.UpdateOptions{}) + return err +} diff --git a/pkg/reconciler/shared/tektonconfig/upgrade/upgrade.go b/pkg/reconciler/shared/tektonconfig/upgrade/upgrade.go index 6f5d0c4045..970968e2c5 100644 --- a/pkg/reconciler/shared/tektonconfig/upgrade/upgrade.go +++ b/pkg/reconciler/shared/tektonconfig/upgrade/upgrade.go @@ -33,7 +33,8 @@ var ( // pre upgrade functions preUpgradeFunctions = []upgradeFunc{ resetTektonConfigConditions, // upgrade #1: removes conditions from TektonConfig CR, clears outdated conditions - upgradePipelineProperties, // update default value of enable-step-actions from false to true + upgradePipelineProperties, // upgrade #2: update default value of enable-step-actions from false to true + removeDeprecatedAddonParams, // upgrade #3: remove the deprecated cluster task params from TektonConfig CR's addon params } // post upgrade functions diff --git a/test/e2e/common/00_tektonconfigdeployment_test.go b/test/e2e/common/00_tektonconfigdeployment_test.go index 7c2838b073..869269b26f 100644 --- a/test/e2e/common/00_tektonconfigdeployment_test.go +++ b/test/e2e/common/00_tektonconfigdeployment_test.go @@ -349,8 +349,6 @@ func (s *TektonConfigTestSuite) Test05_DisableAndEnableAddons() { // disable addons and update tc := s.getCurrentConfig(timeout) tc.Spec.Addon.Params = []v1alpha1.Param{ - {Name: v1alpha1.ClusterTasksParam, Value: "false"}, - {Name: v1alpha1.CommunityClusterTasks, Value: "false"}, {Name: v1alpha1.PipelineTemplatesParam, Value: "false"}, } _, err := s.clients.TektonConfig().Update(context.TODO(), tc, metav1.UpdateOptions{})