From 50315e6332c549f7afb7384ec0c173eb7829e70a Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Tue, 26 Jul 2022 14:47:23 +0530 Subject: [PATCH] Remove okd build logic and IsOkdBuild function Since now we have OKD preset to make decision around code flow, better to use preset logic. --- Makefile | 9 ------- cmd/crc/cmd/start.go | 26 +++++++++----------- pkg/crc/cluster/pullsecret.go | 5 ++-- pkg/crc/image/image.go | 9 ++++--- pkg/crc/preflight/preflight_checks_common.go | 3 +-- pkg/crc/version/version.go | 6 ----- 6 files changed, 19 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index e0a6c7e3a3..20f87c20b6 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,6 @@ CONTAINER_RUNTIME ?= podman TOOLS_DIR := tools include tools/tools.mk -ifdef OKD_VERSION - OPENSHIFT_VERSION = $(OKD_VERSION) - CRC_VERSION := $(CRC_VERSION)-OKD -endif - # Go and compilation related variables BUILD_DIR ?= out SOURCE_DIRS = cmd pkg test @@ -64,10 +59,6 @@ VERSION_VARIABLES := -X $(REPOPATH)/pkg/crc/version.crcVersion=$(CRC_VERSION) \ -X $(REPOPATH)/pkg/crc/version.commitSha=$(COMMIT_SHA) RELEASE_VERSION_VARIABLES := -X $(REPOPATH)/pkg/crc/segment.WriteKey=cvpHsNcmGCJqVzf6YxrSnVlwFSAZaYtp -ifdef OKD_VERSION - VERSION_VARIABLES := $(VERSION_VARIABLES) -X $(REPOPATH)/pkg/crc/version.okdBuild=true -endif - # https://golang.org/cmd/link/ LDFLAGS := $(VERSION_VARIABLES) ${GO_EXTRA_LDFLAGS} # Same build flags are used in the podman remote to cross build it https://github.com/containers/podman/blob/main/Makefile diff --git a/cmd/crc/cmd/start.go b/cmd/crc/cmd/start.go index 1e5fdc87af..2db253b48d 100644 --- a/cmd/crc/cmd/start.go +++ b/cmd/crc/cmd/start.go @@ -7,7 +7,6 @@ import ( "io" "os" "runtime" - "strings" "text/template" "github.com/Masterminds/semver/v3" @@ -156,18 +155,7 @@ func (s *startResult) prettyPrintTo(writer io.Writer) error { return errors.New("either Error or ClusterConfig is needed") } - if err := writeTemplatedMessage(writer, s); err != nil { - return err - } - if crcversion.IsOkdBuild() { - _, err := fmt.Fprintln(writer, strings.Join([]string{ - "", - "NOTE:", - "This cluster was built from OKD - The Community Distribution of Kubernetes that powers Red Hat OpenShift.", - "If you find an issue, please report it at https://github.com/openshift/okd"}, "\n")) - return err - } - return nil + return writeTemplatedMessage(writer, s) } func validateStartFlags() error { @@ -252,6 +240,10 @@ Use the 'oc' command line interface: Use the 'podman' command line interface: {{ .CommandLinePrefix }} {{ .EvalCommandLine }} {{ .CommandLinePrefix }} {{ .PodmanRemote }} COMMAND +` + startTemplateForOKD = `NOTE: +This cluster was built from OKD - The Community Distribution of Kubernetes that powers Red Hat OpenShift. +If you find an issue, please report it at https://github.com/openshift/okd ` ) @@ -263,7 +255,7 @@ type templateVariables struct { } func writeTemplatedMessage(writer io.Writer, s *startResult) error { - if s.ClusterConfig.ClusterType == preset.OpenShift { + if s.ClusterConfig.ClusterType == preset.OpenShift || s.ClusterConfig.ClusterType == preset.OKD { return writeOpenShiftTemplatedMessage(writer, s) } @@ -271,7 +263,11 @@ func writeTemplatedMessage(writer io.Writer, s *startResult) error { } func writeOpenShiftTemplatedMessage(writer io.Writer, s *startResult) error { - parsed, err := template.New("template").Parse(startTemplateForOpenshift) + tmpl := startTemplateForOpenshift + if s.ClusterConfig.ClusterType == preset.OKD { + tmpl = fmt.Sprintf("%s\n\n%s", startTemplateForOpenshift, startTemplateForOKD) + } + parsed, err := template.New("template").Parse(tmpl) if err != nil { return err } diff --git a/pkg/crc/cluster/pullsecret.go b/pkg/crc/cluster/pullsecret.go index 09ce6e840f..53ca708be6 100644 --- a/pkg/crc/cluster/pullsecret.go +++ b/pkg/crc/cluster/pullsecret.go @@ -15,7 +15,6 @@ import ( "github.com/code-ready/crc/pkg/crc/logging" "github.com/code-ready/crc/pkg/crc/preset" "github.com/code-ready/crc/pkg/crc/validation" - crcversion "github.com/code-ready/crc/pkg/crc/version" crcos "github.com/code-ready/crc/pkg/os" "github.com/AlecAivazis/survey/v2" @@ -77,8 +76,8 @@ func NewNonInteractivePullSecretLoader(config crcConfig.Storage, path string) Pu } func (loader *nonInteractivePullSecretLoader) Value() (string, error) { - // If crc is built from an OKD bundle or podman bundle is used, then use the fake pull secret in contants. - if crcversion.IsOkdBuild() || crcConfig.GetPreset(loader.config) == preset.Podman { + // If crc is built from an OKD bundle or podman bundle is used, then use the fake pull secret in constants. + if crcConfig.GetPreset(loader.config) == preset.OKD || crcConfig.GetPreset(loader.config) == preset.Podman { return constants.OkdPullSecret, nil } diff --git a/pkg/crc/image/image.go b/pkg/crc/image/image.go index 30c08e80f9..a7cd971e1b 100644 --- a/pkg/crc/image/image.go +++ b/pkg/crc/image/image.go @@ -85,13 +85,14 @@ func getLayerPath(m *v1.Manifest, index int, mediaType string) (string, error) { } func getImageName(preset crcpreset.Preset) string { - if preset == crcpreset.Podman { + switch preset { + case crcpreset.Podman: return "podman-bundle" - } - if version.IsOkdBuild() { + case crcpreset.OKD: return "okd-bundle" + default: + return "openshift-bundle" } - return "openshift-bundle" } func PullBundle(preset crcpreset.Preset) error { diff --git a/pkg/crc/preflight/preflight_checks_common.go b/pkg/crc/preflight/preflight_checks_common.go index 9fc3370e72..939233f84a 100644 --- a/pkg/crc/preflight/preflight_checks_common.go +++ b/pkg/crc/preflight/preflight_checks_common.go @@ -13,7 +13,6 @@ import ( "github.com/code-ready/crc/pkg/crc/machine/bundle" crcpreset "github.com/code-ready/crc/pkg/crc/preset" "github.com/code-ready/crc/pkg/crc/validation" - "github.com/code-ready/crc/pkg/crc/version" "github.com/pkg/errors" ) @@ -102,7 +101,7 @@ func fixBundleExtracted(bundlePath string, preset crcpreset.Preset) func() error logging.Infof("Downloading %s", constants.GetDefaultBundle(preset)) // In case of OKD or podman bundle then pull the bundle image from quay // otherwise use mirror location to download the bundle. - if version.IsOkdBuild() || preset == crcpreset.Podman { + if preset == crcpreset.OKD || preset == crcpreset.Podman { if err := image.PullBundle(preset); err != nil { return err } diff --git a/pkg/crc/version/version.go b/pkg/crc/version/version.go index 8e26cdb1a6..9afb7c19a2 100644 --- a/pkg/crc/version/version.go +++ b/pkg/crc/version/version.go @@ -28,8 +28,6 @@ var ( // Podman version for podman specific bundles podmanVersion = "0.0.0-unset" - okdBuild = "false" - okdVersion = "0.0.0-unset" // will always be false on linux // will be true for releases on macos and windows @@ -83,10 +81,6 @@ func GetAdminHelperVersion() string { return crcAdminHelperVersion } -func IsOkdBuild() bool { - return okdBuild == "true" -} - func GetTrayVersion() string { return crcTrayElectronVersion }