Skip to content

Commit

Permalink
Get bundle version according to preset
Browse files Browse the repository at this point in the history
This commits add logic to GetBundleVersion to provide ocp or okd
version as per user set preset. It changes the GetBundleVersion function
signature with an added preset argument.
  • Loading branch information
praveenkumar authored and anjannath committed Aug 1, 2022
1 parent f09bacf commit 5ed578d
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/crc/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func runPrerun(cmd *cobra.Command) error {
}
logging.InitLogrus(logFile)

for _, str := range defaultVersion().lines() {
for _, str := range defaultVersion(crcConfig.GetPreset(config)).lines() {
logging.Debugf(str)
}
return nil
Expand Down
7 changes: 4 additions & 3 deletions cmd/crc/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

crcConfig "github.com/code-ready/crc/pkg/crc/config"
"github.com/code-ready/crc/pkg/crc/logging"
crcPreset "github.com/code-ready/crc/pkg/crc/preset"
crcversion "github.com/code-ready/crc/pkg/crc/version"
"github.com/spf13/cobra"
)
Expand All @@ -21,7 +22,7 @@ var versionCmd = &cobra.Command{
Short: "Print version information",
Long: "Print version information",
RunE: func(cmd *cobra.Command, args []string) error {
return runPrintVersion(os.Stdout, defaultVersion(), outputFormat)
return runPrintVersion(os.Stdout, defaultVersion(crcConfig.GetPreset(config)), outputFormat)
},
}

Expand All @@ -39,11 +40,11 @@ type version struct {
PodmanVersion string `json:"podmanVersion"`
}

func defaultVersion() *version {
func defaultVersion(preset crcPreset.Preset) *version {
return &version{
Version: crcversion.GetCRCVersion(),
Commit: crcversion.GetCommitSha(),
OpenshiftVersion: crcversion.GetBundleVersion(),
OpenshiftVersion: crcversion.GetBundleVersion(preset),
PodmanVersion: crcversion.GetPodmanVersion(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/api/api_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestVersion(t *testing.T) {
t,
apiClient.VersionResult{
CrcVersion: version.GetCRCVersion(),
OpenshiftVersion: version.GetBundleVersion(),
OpenshiftVersion: version.GetBundleVersion(preset.OpenShift),
CommitSha: version.GetCommitSha(),
PodmanVersion: version.GetPodmanVersion(),
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/crc/api/api_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
crcConfig "github.com/code-ready/crc/pkg/crc/config"
"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/machine/fakemachine"
"github.com/code-ready/crc/pkg/crc/preset"
"github.com/code-ready/crc/pkg/crc/version"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -265,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(), version.GetPodmanVersion())),
response: jSon(fmt.Sprintf(`{"CrcVersion":"%s","CommitSha":"%s","OpenshiftVersion":"%s","PodmanVersion":"%s"}`, version.GetCRCVersion(), version.GetCommitSha(), version.GetBundleVersion(preset.OpenShift), version.GetPodmanVersion())),
},

// version never fails
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (h *Handler) GetVersion(c *context) error {
return c.JSON(http.StatusOK, &client.VersionResult{
CrcVersion: version.GetCRCVersion(),
CommitSha: version.GetCommitSha(),
OpenshiftVersion: version.GetBundleVersion(),
OpenshiftVersion: version.GetBundleVersion(crcConfig.GetPreset(h.Config)),
PodmanVersion: version.GetPodmanVersion(),
})
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/crc/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ func defaultBundleForOs(preset crcpreset.Preset) map[string]string {
}
}
return map[string]string{
"darwin": fmt.Sprintf("crc_vfkit_%s_%s.crcbundle", version.GetBundleVersion(), runtime.GOARCH),
"linux": fmt.Sprintf("crc_libvirt_%s_%s.crcbundle", version.GetBundleVersion(), runtime.GOARCH),
"windows": fmt.Sprintf("crc_hyperv_%s_%s.crcbundle", version.GetBundleVersion(), runtime.GOARCH),
"darwin": fmt.Sprintf("crc_vfkit_%s_%s.crcbundle", version.GetBundleVersion(preset), runtime.GOARCH),
"linux": fmt.Sprintf("crc_libvirt_%s_%s.crcbundle", version.GetBundleVersion(preset), runtime.GOARCH),
"windows": fmt.Sprintf("crc_hyperv_%s_%s.crcbundle", version.GetBundleVersion(preset), runtime.GOARCH),
}
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/crc/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/Masterminds/semver/v3"
"github.com/code-ready/crc/pkg/crc/logging"
crcPreset "github.com/code-ready/crc/pkg/crc/preset"
)

// The following variables are private fields and should be set when compiling with ldflags, for example --ldflags="-X github.com/code-ready/crc/pkg/version.crcVersion=vX.Y.Z
Expand Down Expand Up @@ -66,7 +67,7 @@ func GetCommitSha() string {
return commitSha
}

func GetBundleVersion() string {
func GetBundleVersion(_ crcPreset.Preset) string {
return bundleVersion
}

Expand Down

0 comments on commit 5ed578d

Please sign in to comment.