Skip to content

Commit

Permalink
[openshift] Fix Versioned ClusterTask names
Browse files Browse the repository at this point in the history
Add logic to format versioned CluterTask names to have a constant "0" as the patch version character

Signed-off-by: Nikhil Thomas <[email protected]>
  • Loading branch information
nikhil-thomas committed Apr 11, 2022
1 parent 6c46be0 commit 3c8ad2d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
22 changes: 18 additions & 4 deletions pkg/reconciler/openshift/tektonaddon/clustertTask.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,24 @@ func (r *Reconciler) ensureClusterTasks(ctx context.Context, ta *v1alpha1.Tekton
return nil
}

// To get the version in the format as in clustertask name i.e. 1-6
func getFormattedVersion(version string) string {
version = strings.TrimPrefix(getPatchVersionTrimmed(version), "v")
return strings.Replace(version, ".", "-", -1)
func formattedVersionMajorMinorPatch(version string) string {
return formattedVersionSnake(version)
}

func formattedVersionMajorMinorX(version, x string) string {
ver := getPatchVersionTrimmed(version)
ver = fmt.Sprintf("%s.%s", ver, x)
return formattedVersionSnake(ver)
}

func formattedVersionMajorMinor(version string) string {
ver := getPatchVersionTrimmed(version)
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
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/openshift/tektonaddon/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
ClusterTaskInstallerSet = "ClusterTask"
CommunityClusterTaskInstallerSet = "CommunityClusterTask"
VersionedClusterTaskInstallerSet = "VersionedClusterTask"
versionedClusterTaskPatchChar = "0"
PipelinesTemplateInstallerSet = "PipelinesTemplate"
TriggersResourcesInstallerSet = "TriggersResources"
ConsoleCLIInstallerSet = "ConsoleCLI"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/openshift/tektonaddon/installerset.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func makeInstallerSet(ta *v1alpha1.TektonAddon, manifest mf.Manifest, prefix, re
// for all patch releases
if component == VersionedClusterTaskInstallerSet {
labels[v1alpha1.ReleaseMinorVersionKey] = getPatchVersionTrimmed(releaseVersion)
namePrefix = fmt.Sprintf("%s%s-", namePrefix, getFormattedVersion(releaseVersion))
namePrefix = fmt.Sprintf("%s%s-", namePrefix, formattedVersionMajorMinor(releaseVersion))
}
return &v1alpha1.TektonInstallerSet{
ObjectMeta: metav1.ObjectMeta{
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/openshift/tektonaddon/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func setVersionedNames(operatorVersion string) mf.Transformer {
return nil
}
name := u.GetName()
formattedVersion := getFormattedVersion(operatorVersion)
formattedVersion := formattedVersionMajorMinorX(operatorVersion, versionedClusterTaskPatchChar)
name = fmt.Sprintf("%s-%s", name, formattedVersion)
u.SetName(name)
return nil
Expand Down

0 comments on commit 3c8ad2d

Please sign in to comment.