Repository: code-ready/crc
Pull request #3314 (2022-08-24 12:15:04)

Version: use GetBundleVersion for any type of preset
This pr is a refactor to use `GetBundleVersion` for any type of
preset bundle and return the correct bundle version. After this
PR we don't need `GetPodmanVersion()` and it removes it.



openshift-ci[bot]: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
**Once this PR has been reviewed and has the lgtm label**, please ask for approval from praveenkumar by writing `/assign @praveenkumar` in a comment. For more information see:[The Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

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

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

- **[OWNERS](https://github.com/code-ready/crc/blob/main/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":["praveenkumar"]} -->
openshift-ci[bot]: @praveenkumar: The following test **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
ci/prow/e2e-crc | 3d326840e9864ef23d250bd4a2c6f2adbfcacf28 | [link](https://prow.ci.openshift.org/view/gs/origin-ci-test/pr-logs/pull/code-ready_crc/3314/pull-ci-code-ready-crc-main-e2e-crc/1562414547376017408) | true | `/test e2e-crc`

[Full PR test history](https://prow.ci.openshift.org/pr-history?org=code-ready&repo=crc&pr=3314). [Your PR dashboard](https://prow.ci.openshift.org/pr?query=is:pr+state:open+author:praveenkumar).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
openshift-ci[bot]: New changes are detected. LGTM label has been removed.

Patch:
diff --git a/Makefile b/Makefile
index 3e49da7d8..ec1ce1731 100644
--- a/Makefile
+++ b/Makefile
@@ -53,7 +53,7 @@ __check_defined = \
 
 # Linker flags
 VERSION_VARIABLES := -X $(REPOPATH)/pkg/crc/version.crcVersion=$(CRC_VERSION) \
-	-X $(REPOPATH)/pkg/crc/version.bundleVersion=$(OPENSHIFT_VERSION) \
+	-X $(REPOPATH)/pkg/crc/version.ocpVersion=$(OPENSHIFT_VERSION) \
 	-X $(REPOPATH)/pkg/crc/version.okdVersion=$(OKD_VERSION) \
 	-X $(REPOPATH)/pkg/crc/version.podmanVersion=$(PODMAN_VERSION) \
 	-X $(REPOPATH)/pkg/crc/version.commitSha=$(COMMIT_SHA)
diff --git a/cmd/crc/cmd/version.go b/cmd/crc/cmd/version.go
index df504e352..7d71d9c78 100644
--- a/cmd/crc/cmd/version.go
+++ b/cmd/crc/cmd/version.go
@@ -45,7 +45,7 @@ func defaultVersion(preset crcPreset.Preset) *version {
 		Version:          crcversion.GetCRCVersion(),
 		Commit:           crcversion.GetCommitSha(),
 		OpenshiftVersion: crcversion.GetBundleVersion(preset),
-		PodmanVersion:    crcversion.GetPodmanVersion(),
+		PodmanVersion:    crcversion.GetBundleVersion(crcPreset.Podman),
 	}
 }
 
diff --git a/pkg/crc/api/handlers.go b/pkg/crc/api/handlers.go
index d9185945e..c715f9550 100644
--- a/pkg/crc/api/handlers.go
+++ b/pkg/crc/api/handlers.go
@@ -11,6 +11,7 @@ import (
 	"github.com/code-ready/crc/pkg/crc/machine"
 	"github.com/code-ready/crc/pkg/crc/machine/types"
 	"github.com/code-ready/crc/pkg/crc/preflight"
+	"github.com/code-ready/crc/pkg/crc/preset"
 	"github.com/code-ready/crc/pkg/crc/version"
 )
 
@@ -125,7 +126,7 @@ func (h *Handler) GetVersion(c *context) error {
 		CrcVersion:       version.GetCRCVersion(),
 		CommitSha:        version.GetCommitSha(),
 		OpenshiftVersion: version.GetBundleVersion(crcConfig.GetPreset(h.Config)),
-		PodmanVersion:    version.GetPodmanVersion(),
+		PodmanVersion:    version.GetBundleVersion(preset.Podman),
 	})
 }
 
diff --git a/pkg/crc/constants/constants.go b/pkg/crc/constants/constants.go
index b674a8ad5..e87a04365 100644
--- a/pkg/crc/constants/constants.go
+++ b/pkg/crc/constants/constants.go
@@ -87,9 +87,9 @@ func defaultBundleForOs(preset crcpreset.Preset) map[string]string {
 	switch preset {
 	case crcpreset.Podman:
 		return map[string]string{
-			"darwin":  fmt.Sprintf("crc_podman_vfkit_%s_%s.crcbundle", version.GetPodmanVersion(), runtime.GOARCH),
-			"linux":   fmt.Sprintf("crc_podman_libvirt_%s_%s.crcbundle", version.GetPodmanVersion(), runtime.GOARCH),
-			"windows": fmt.Sprintf("crc_podman_hyperv_%s_%s.crcbundle", version.GetPodmanVersion(), runtime.GOARCH),
+			"darwin":  fmt.Sprintf("crc_podman_vfkit_%s_%s.crcbundle", version.GetBundleVersion(preset), runtime.GOARCH),
+			"linux":   fmt.Sprintf("crc_podman_libvirt_%s_%s.crcbundle", version.GetBundleVersion(preset), runtime.GOARCH),
+			"windows": fmt.Sprintf("crc_podman_hyperv_%s_%s.crcbundle", version.GetBundleVersion(preset), runtime.GOARCH),
 		}
 	case crcpreset.OKD:
 		return map[string]string{
diff --git a/pkg/crc/version/version.go b/pkg/crc/version/version.go
index 964d66c62..8b341895d 100644
--- a/pkg/crc/version/version.go
+++ b/pkg/crc/version/version.go
@@ -22,8 +22,8 @@ var (
 	// The SHA-1 of the commit this executable is build off
 	commitSha = "sha-unset"
 
-	// Bundle version which used for the release.
-	bundleVersion = "0.0.0-unset"
+	// OCP version which is used for the release.
+	ocpVersion = "0.0.0-unset"
 
 	// Podman version for podman specific bundles
 	podmanVersion = "0.0.0-unset"
@@ -67,14 +67,14 @@ func GetCommitSha() string {
 }
 
 func GetBundleVersion(preset crcPreset.Preset) string {
-	if preset == crcPreset.OpenShift {
-		return bundleVersion
+	switch preset {
+	case crcPreset.Podman:
+		return podmanVersion
+	case crcPreset.OKD:
+		return okdVersion
+	default:
+		return ocpVersion
 	}
-	return okdVersion
-}
-
-func GetPodmanVersion() string {
-	return podmanVersion
 }
 
 func GetAdminHelperVersion() string {


Test patch:
diff --git a/pkg/crc/api/api_client_test.go b/pkg/crc/api/api_client_test.go
index 178de733c..0827efb8f 100644
--- a/pkg/crc/api/api_client_test.go
+++ b/pkg/crc/api/api_client_test.go
@@ -52,7 +52,7 @@ func TestVersion(t *testing.T) {
 			CrcVersion:       version.GetCRCVersion(),
 			OpenshiftVersion: version.GetBundleVersion(preset.OpenShift),
 			CommitSha:        version.GetCommitSha(),
-			PodmanVersion:    version.GetPodmanVersion(),
+			PodmanVersion:    version.GetBundleVersion(preset.Podman),
 		},
 		vr,
 	)
diff --git a/pkg/crc/api/api_http_test.go b/pkg/crc/api/api_http_test.go
index bbd3869ee..c16dd3146 100644
--- a/pkg/crc/api/api_http_test.go
+++ b/pkg/crc/api/api_http_test.go
@@ -266,7 +266,7 @@ var testCases = []testCase{
 	// version
 	{
 		request:  get("version"),
-		response: jSon(fmt.Sprintf(`{"CrcVersion":"%s","CommitSha":"%s","OpenshiftVersion":"%s","PodmanVersion":"%s"}`, version.GetCRCVersion(), version.GetCommitSha(), version.GetBundleVersion(preset.OpenShift), version.GetPodmanVersion())),
+		response: jSon(fmt.Sprintf(`{"CrcVersion":"%s","CommitSha":"%s","OpenshiftVersion":"%s","PodmanVersion":"%s"}`, version.GetCRCVersion(), version.GetCommitSha(), version.GetBundleVersion(preset.OpenShift), version.GetBundleVersion(preset.Podman))),
 	},
 
 	// version never fails