Repository: tektoncd/operator
Pull request #742 (2022-04-05 13:16:29)

[cherry-pick] Update tkn, pac ConsoleCLIDownload links to 0.23.1
This commit updates the link that ConsoleCLIDownload exposes to 0.23.1
and introduces `tkn-pac` binaries to the list as well.
 Cherry pick #741 

# Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

- [x] Includes [tests](https://github.com/tektoncd/community/blob/master/standards.md#principles) (if functionality changed/added)
- [x] Includes [docs](https://github.com/tektoncd/community/blob/master/standards.md#principles) (if user facing)
- [x] Commit messages follow [commit message best practices](https://github.com/tektoncd/community/blob/master/standards.md#commit-messages)

# Release Notes

```release-note
NONE
```

tekton-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **houshengbo**
You can assign the PR to them by writing `/assign @houshengbo` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=tektoncd%2Foperator).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/tektoncd/operator/blob/release-v0.55.x/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["houshengbo"]} -->
tekton-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/tektoncd/operator/pull/742#pullrequestreview-932001791" title="LGTM">vdemeester</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=tektoncd%2Foperator).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/tektoncd/operator/blob/release-v0.55.x/OWNERS)~~ [vdemeester]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/cmd/openshift/operator/kodata/tekton-addon/addons/04-consolecli/console_cli_download_tkn.yaml b/cmd/openshift/operator/kodata/tekton-addon/addons/04-consolecli/console_cli_download_tkn.yaml
index dc7372a29..532a28d4a 100644
--- a/cmd/openshift/operator/kodata/tekton-addon/addons/04-consolecli/console_cli_download_tkn.yaml
+++ b/cmd/openshift/operator/kodata/tekton-addon/addons/04-consolecli/console_cli_download_tkn.yaml
@@ -4,15 +4,4 @@ metadata:
   name: tkn
 spec:
   description: The OpenShift Pipeline client `tkn` is a CLI tool that allows you to manage OpenShift Pipeline resources.
-  displayName: tkn - OpenShift Pipeline Command Line Interface (CLI)
-  links:
-    - href: https://mirror.openshift.com/pub/openshift-v4/clients/pipeline/0.17.2/tkn-linux-amd64-0.17.2.tar.gz
-      text: Download tkn for Linux
-    - href: https://mirror.openshift.com/pub/openshift-v4/clients/pipeline/0.17.2/tkn-macos-amd64-0.17.2.tar.gz
-      text: Download tkn for Mac
-    - href: https://mirror.openshift.com/pub/openshift-v4/clients/pipeline/0.17.2/tkn-windows-amd64-0.17.2.zip
-      text: Download tkn for Windows
-    - href: https://mirror.openshift.com/pub/openshift-v4/clients/pipeline/0.17.2/tkn-linux-ppc64le-0.17.2.tar.gz
-      text: Download tkn for IBM Power
-    - href: https://mirror.openshift.com/pub/openshift-v4/clients/pipeline/0.17.2/tkn-linux-s390x-0.17.2.tar.gz
-      text: Download tkn for IBM Z
+  displayName: tkn - OpenShift Pipeline Command Line Interface (CLI)
\ No newline at end of file
diff --git a/pkg/reconciler/openshift/tektonaddon/extension.go b/pkg/reconciler/openshift/tektonaddon/extension.go
index 23e7d21df..0e3280b5c 100644
--- a/pkg/reconciler/openshift/tektonaddon/extension.go
+++ b/pkg/reconciler/openshift/tektonaddon/extension.go
@@ -249,6 +249,8 @@ func addonTransform(ctx context.Context, manifest *mf.Manifest, comp v1alpha1.Te
 }
 
 func consoleCLITransform(ctx context.Context, manifest *mf.Manifest, baseURL string) error {
+	tknVersion := "0.23.1"
+
 	if baseURL == "" {
 		return fmt.Errorf("route url should not be empty")
 	}
@@ -256,7 +258,7 @@ func consoleCLITransform(ctx context.Context, manifest *mf.Manifest, baseURL str
 	logger.Debug("Transforming manifest")
 
 	transformers := []mf.Transformer{
-		replaceURLCCD(baseURL),
+		replaceURLCCD(baseURL, tknVersion),
 	}
 
 	transformManifest, err := manifest.Transform(transformers...)
diff --git a/pkg/reconciler/openshift/tektonaddon/transformer.go b/pkg/reconciler/openshift/tektonaddon/transformer.go
index 3c0e9f998..2fc491599 100644
--- a/pkg/reconciler/openshift/tektonaddon/transformer.go
+++ b/pkg/reconciler/openshift/tektonaddon/transformer.go
@@ -80,23 +80,52 @@ func itemInSlice(item string, items []string) bool {
 	return false
 }
 
-func getlinks(baseURL string) []console.CLIDownloadLink {
-	platforms := []struct {
-		key   string
-		value string
+func getlinks(baseURL, tknVersion string) []console.CLIDownloadLink {
+	platformURLs := []struct {
+		platform  string
+		tknURL    string
+		tknPacURL string
 	}{
-		{"Linux", "tkn/tkn-linux-amd64-0.21.0.tar.gz"},
-		{"IBM Power", "tkn/tkn-linux-ppc64le-0.21.0.tar.gz"},
-		{"IBM Z", "tkn/tkn-linux-s390x-0.21.0.tar.gz"},
-		{"Mac", "tkn/tkn-macos-amd64-0.21.0.tar.gz"},
-		{"Windows", "tkn/tkn-windows-amd64-0.21.0.zip"},
+		{
+			"Linux",
+			fmt.Sprintf("tkn/tkn-linux-amd64-%s.tar.gz", tknVersion),
+			fmt.Sprintf("tkn/tkn-pac-linux-amd64-%s.tar.gz", tknVersion),
+		},
+		{
+			"IBM Power",
+			fmt.Sprintf("tkn/tkn-linux-ppc64le-%s.tar.gz", tknVersion),
+			fmt.Sprintf("tkn/tkn-pac-linux-ppc64le-%s.tar.gz", tknVersion),
+		},
+		{
+			"IBM Z",
+			fmt.Sprintf("tkn/tkn-linux-s390x-%s.tar.gz", tknVersion),
+			fmt.Sprintf("tkn/tkn-pac-linux-s390x-%s.tar.gz", tknVersion),
+		},
+		{
+			"Mac",
+			fmt.Sprintf("tkn/tkn-macos-amd64-%s.tar.gz", tknVersion),
+			fmt.Sprintf("tkn/tkn-pac-macos-amd64-%s.tar.gz", tknVersion),
+		},
+		{
+			"Windows",
+			fmt.Sprintf("tkn/tkn-windows-amd64-%s.zip", tknVersion),
+			fmt.Sprintf("tkn/tkn-pac-windows-amd64-%s.zip", tknVersion),
+		},
 	}
 	links := []console.CLIDownloadLink{}
-	for _, platform := range platforms {
-		links = append(links, console.CLIDownloadLink{
-			Href: getURL(baseURL, platform.value),
-			Text: fmt.Sprintf("Download tkn for %s", platform.key),
-		})
+	for _, platformURL := range platformURLs {
+		links = append(links,
+			// tkn
+			console.CLIDownloadLink{
+				Href: getURL(baseURL, platformURL.tknURL),
+				Text: fmt.Sprintf("Download tkn for %s", platformURL.platform),
+			},
+			// tkn-pac
+			console.CLIDownloadLink{
+				Href: getURL(baseURL, platformURL.tknPacURL),
+				Text: fmt.Sprintf("Download tkn-pac for %s", platformURL.platform),
+			},
+		)
 	}
 	return links
 }
@@ -105,7 +134,7 @@ func getURL(baseURL string, path string) string {
 	return fmt.Sprintf("https://%s/%s", baseURL, path)
 }
 
-func replaceURLCCD(baseURL string) mf.Transformer {
+func replaceURLCCD(baseURL, tknVersion string) mf.Transformer {
 	return func(u *unstructured.Unstructured) error {
 		if u.GetKind() != "ConsoleCLIDownload" {
 			return nil
@@ -115,7 +144,7 @@ func replaceURLCCD(baseURL string) mf.Transformer {
 		if err != nil {
 			return err
 		}
-		ccd.Spec.Links = getlinks(baseURL)
+		ccd.Spec.Links = getlinks(baseURL, tknVersion)
 		unstrObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(ccd)
 		if err != nil {
 			return err


Test patch:
diff --git a/pkg/reconciler/openshift/tektonaddon/testdata/test-console-cli-expected.yaml b/pkg/reconciler/openshift/tektonaddon/testdata/test-console-cli-expected.yaml
index 6c48c5d15..79efb0fbc 100644
--- a/pkg/reconciler/openshift/tektonaddon/testdata/test-console-cli-expected.yaml
+++ b/pkg/reconciler/openshift/tektonaddon/testdata/test-console-cli-expected.yaml
@@ -6,13 +6,23 @@ spec:
   description: The OpenShift Pipeline client `tkn` is a CLI tool that allows you to manage OpenShift Pipeline resources.
   displayName: tkn - OpenShift Pipeline Command Line Interface (CLI)
   links:
-    - href: https://testserver.com/tkn/tkn-linux-amd64-0.21.0.tar.gz
+    - href: https://testserver.com/tkn/tkn-linux-amd64-1.2.3.tar.gz
       text: Download tkn for Linux
-    - href: https://testserver.com/tkn/tkn-linux-ppc64le-0.21.0.tar.gz
+    - href: https://testserver.com/tkn/tkn-pac-linux-amd64-1.2.3.tar.gz
+      text: Download tkn-pac for Linux
+    - href: https://testserver.com/tkn/tkn-linux-ppc64le-1.2.3.tar.gz
       text: Download tkn for IBM Power
-    - href: https://testserver.com/tkn/tkn-linux-s390x-0.21.0.tar.gz
+    - href: https://testserver.com/tkn/tkn-pac-linux-ppc64le-1.2.3.tar.gz
+      text: Download tkn-pac for IBM Power
+    - href: https://testserver.com/tkn/tkn-linux-s390x-1.2.3.tar.gz
       text: Download tkn for IBM Z
-    - href: https://testserver.com/tkn/tkn-macos-amd64-0.21.0.tar.gz
+    - href: https://testserver.com/tkn/tkn-pac-linux-s390x-1.2.3.tar.gz
+      text: Download tkn-pac for IBM Z
+    - href: https://testserver.com/tkn/tkn-macos-amd64-1.2.3.tar.gz
       text: Download tkn for Mac
-    - href: https://testserver.com/tkn/tkn-windows-amd64-0.21.0.zip
+    - href: https://testserver.com/tkn/tkn-pac-macos-amd64-1.2.3.tar.gz
+      text: Download tkn-pac for Mac
+    - href: https://testserver.com/tkn/tkn-windows-amd64-1.2.3.zip
       text: Download tkn for Windows
+    - href: https://testserver.com/tkn/tkn-pac-windows-amd64-1.2.3.zip
+      text: Download tkn-pac for Windows
diff --git a/pkg/reconciler/openshift/tektonaddon/transformer_test.go b/pkg/reconciler/openshift/tektonaddon/transformer_test.go
index 224cf599e..5115648bc 100644
--- a/pkg/reconciler/openshift/tektonaddon/transformer_test.go
+++ b/pkg/reconciler/openshift/tektonaddon/transformer_test.go
@@ -42,7 +42,7 @@ func TestUpdateConsoleCLIDownload(t *testing.T) {
 	expectedManifest, err := mf.ManifestFrom(mf.Recursive(testData))
 	assert.NilError(t, err)
 
-	newManifest, err := manifest.Transform(replaceURLCCD("testserver.com"))
+	newManifest, err := manifest.Transform(replaceURLCCD("testserver.com", "1.2.3"))
 	assert.NilError(t, err)
 
 	got := &console.ConsoleCLIDownload{}