Skip to content

Commit

Permalink
Preserve the existing TektonResult CR configuration
Browse files Browse the repository at this point in the history
Now TektonResult is installed by the TektonConfig, TektonConfig config was
creating TektonResult CR with default configuration and also not preserving the exsiting
TektonResult configuration, now this patch fixes to preserve the TektonResult configuration

Signed-off-by: Shiv Verma <[email protected]>
  • Loading branch information
pratap0007 authored and tekton-robot committed Feb 28, 2025
1 parent a3d900d commit 687d810
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
33 changes: 33 additions & 0 deletions pkg/reconciler/shared/tektonconfig/upgrade/pre_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,36 @@ func removeDeprecatedAddonParams(ctx context.Context, logger *zap.SugaredLogger,
_, err = operatorClient.OperatorV1alpha1().TektonConfigs().Update(ctx, tcCR, metav1.UpdateOptions{})
return err
}

// previous version of the Tekton Operator does not install the TektonResult via TektonConfig
// in the new version, we are supporting to installing and manage TektonResult via TektonConfig
// so if TektonResult CR exists on the cluster then needs to copy the TektonResult CR configuration to the TektonConfig CR
func copyResultConfigToTektonConfig(ctx context.Context, logger *zap.SugaredLogger, k8sClient kubernetes.Interface, operatorClient versioned.Interface, restConfig *rest.Config) error {
// get the TekonResult CR
trCR, err := operatorClient.OperatorV1alpha1().TektonResults().Get(ctx, v1alpha1.ResultResourceName, metav1.GetOptions{})
if err != nil {
if apierrs.IsNotFound(err) {
return nil
}
return err
}

// get the TekonConfig CR
tcCR, err := operatorClient.OperatorV1alpha1().TektonConfigs().Get(ctx, v1alpha1.ConfigResourceName, metav1.GetOptions{})
if err != nil {
if apierrs.IsNotFound(err) {
return nil
}
return err
}

// copy the existing TektonResult CR configuration to the TektonConfig CR
tcCR.Spec.Result.ResultsAPIProperties = trCR.Spec.ResultsAPIProperties
tcCR.Spec.Result.LokiStackProperties = trCR.Spec.LokiStackProperties

_, err = operatorClient.OperatorV1alpha1().TektonConfigs().Update(ctx, tcCR, metav1.UpdateOptions{})
if err != nil {
return err
}
return nil
}
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 @@ -35,7 +35,8 @@ var (
resetTektonConfigConditions, // upgrade #1: removes conditions from TektonConfig CR, clears outdated conditions
upgradePipelineProperties, // upgrade #2: update default value of enable-step-actions from false to true
// Todo: Remove the removeDeprecatedAddonParams upgrade function in next operator release
removeDeprecatedAddonParams, // upgrade #3: remove the deprecated cluster task params from TektonConfig CR's addon params
removeDeprecatedAddonParams, // upgrade #3: remove the deprecated cluster task params from TektonConfig CR's addon params
copyResultConfigToTektonConfig, // upgrade #4: copy existing TektonResult configuration to the TektonConfig CR
}

// post upgrade functions
Expand Down

0 comments on commit 687d810

Please sign in to comment.