Skip to content

Commit

Permalink
constants: Simplify (?) generation of default bundle name
Browse files Browse the repository at this point in the history
Instead of hardcoding all the possible variations for the bundle name
depending on preset/os, the bundle name is built using a golang
strings.Builder.
  • Loading branch information
cfergeau authored and anjannath committed Aug 30, 2022
1 parent 6c27952 commit 6c429df
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions pkg/crc/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"

crcpreset "github.com/code-ready/crc/pkg/crc/preset"
"github.com/code-ready/crc/pkg/crc/version"
Expand Down Expand Up @@ -84,29 +85,28 @@ func GetAdminHelperURL() string {
}

func GetDefaultBundle(preset crcpreset.Preset) string {
var bundleMap map[string]string
var bundleName strings.Builder

bundleName.WriteString("crc")

switch preset {
case crcpreset.Podman:
bundleMap = map[string]string{
"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),
}
bundleName.WriteString("_podman")
case crcpreset.OKD:
bundleMap = map[string]string{
"darwin": fmt.Sprintf("crc_okd_vfkit_%s_%s.crcbundle", version.GetBundleVersion(preset), runtime.GOARCH),
"linux": fmt.Sprintf("crc_okd_libvirt_%s_%s.crcbundle", version.GetBundleVersion(preset), runtime.GOARCH),
"windows": fmt.Sprintf("crc_okd_hyperv_%s_%s.crcbundle", version.GetBundleVersion(preset), runtime.GOARCH),
}
default:
bundleMap = map[string]string{
"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),
}
bundleName.WriteString("_okd")
}

switch runtime.GOOS {
case "darwin":
bundleName.WriteString("_vfkit")
case "linux":
bundleName.WriteString("_libvirt")
case "windows":
bundleName.WriteString("_hyperv")
}

return bundleMap[runtime.GOOS]
fmt.Fprintf(&bundleName, "_%s_%s.crcbundle", version.GetBundleVersion(preset), runtime.GOARCH)
return bundleName.String()
}

var (
Expand Down

0 comments on commit 6c429df

Please sign in to comment.