Skip to content

Commit

Permalink
Update TektonConfig CR's addon params to remove cluster tasks params
Browse files Browse the repository at this point in the history
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 <[email protected]>'
  • Loading branch information
pratap0007 committed Dec 4, 2024
1 parent 7ced192 commit 92f4ddf
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
8 changes: 0 additions & 8 deletions pkg/apis/operator/v1alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/operator/v1alpha1/tektonaddon_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/operator/v1alpha1/tektonconfig_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
}
Expand Down
27 changes: 27 additions & 0 deletions pkg/reconciler/shared/tektonconfig/upgrade/pre_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion pkg/reconciler/shared/tektonconfig/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/common/00_tektonconfigdeployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down

0 comments on commit 92f4ddf

Please sign in to comment.