From 038bbad43cedf2f6010133e90c38ac9a0818cdc8 Mon Sep 17 00:00:00 2001 From: Shubham Date: Tue, 5 Apr 2022 18:00:53 +0530 Subject: [PATCH] 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. --- .../console_cli_download_tkn.yaml | 13 +--- .../openshift/tektonaddon/extension.go | 4 +- .../testdata/test-console-cli-expected.yaml | 20 ++++-- .../openshift/tektonaddon/transformer.go | 61 ++++++++++++++----- .../openshift/tektonaddon/transformer_test.go | 2 +- 5 files changed, 65 insertions(+), 35 deletions(-) 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 dc7372a29c..532a28d4a1 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 23e7d21df9..0e3280b5cc 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/testdata/test-console-cli-expected.yaml b/pkg/reconciler/openshift/tektonaddon/testdata/test-console-cli-expected.yaml index 6c48c5d154..79efb0fbca 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.go b/pkg/reconciler/openshift/tektonaddon/transformer.go index 3c0e9f9981..2fc4915999 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 diff --git a/pkg/reconciler/openshift/tektonaddon/transformer_test.go b/pkg/reconciler/openshift/tektonaddon/transformer_test.go index 224cf599ef..5115648bce 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{}