Skip to content

Commit

Permalink
Remove okd build logic and IsOkdBuild function
Browse files Browse the repository at this point in the history
Since now we have OKD preset to make decision around code flow, better
to use preset logic.
  • Loading branch information
praveenkumar authored and anjannath committed Aug 1, 2022
1 parent e031382 commit 50315e6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 39 deletions.
9 changes: 0 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 11 additions & 15 deletions cmd/crc/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"os"
"runtime"
"strings"
"text/template"

"github.com/Masterminds/semver/v3"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
`
)

Expand All @@ -263,15 +255,19 @@ 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)
}

return writePodmanTemplatedMessage(writer, s)
}

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
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/crc/cluster/pullsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/crc/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions pkg/crc/preflight/preflight_checks_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/crc/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,10 +81,6 @@ func GetAdminHelperVersion() string {
return crcAdminHelperVersion
}

func IsOkdBuild() bool {
return okdBuild == "true"
}

func GetTrayVersion() string {
return crcTrayElectronVersion
}
Expand Down

0 comments on commit 50315e6

Please sign in to comment.