Repository: code-ready/crc
Pull request #2416 (2021-06-09 13:43:27)

Remove fat macOS binary, keep only for the .pkg for release

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

This pull-request has been approved by: *<a href="https://github.com/code-ready/crc/pull/2416#" title="Author self-approved">guillaumerose</a>*

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

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

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

- ~~[OWNERS](https://github.com/code-ready/crc/blob/master/OWNERS)~~ [guillaumerose]

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":[]} -->
openshift-ci[bot]: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/code-ready/crc/pull/2416#pullrequestreview-679677199" title="Approved">cfergeau</a>*, *<a href="https://github.com/code-ready/crc/pull/2416#" title="Author self-approved">guillaumerose</a>*

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

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

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

- ~~[OWNERS](https://github.com/code-ready/crc/blob/master/OWNERS)~~ [cfergeau,guillaumerose]

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":[]} -->

Patch:
diff --git a/Makefile b/Makefile
index 7d2210dfa..3b773568f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 SHELL := /bin/bash
 
-BUNDLE_VERSION ?= 4.7.11
+BUNDLE_VERSION ?= 4.7.13
 BUNDLE_EXTENSION = crcbundle
 CRC_VERSION = 1.27.0
 COMMIT_SHA=$(shell git rev-parse --short HEAD)
@@ -212,10 +212,6 @@ gen_release_info:
 release: LDFLAGS += $(RELEASE_VERSION_VARIABLES)
 release: cross-lint embed_bundle gen_release_info
 	mkdir $(RELEASE_DIR)
-	
-	@mkdir -p $(BUILD_DIR)/crc-macos-$(CRC_VERSION)-amd64
-	@cp LICENSE $(BUILD_DIR)/macos-amd64/crc $(BUILD_DIR)/crc-macos-$(CRC_VERSION)-amd64
-	tar cJSf $(RELEASE_DIR)/crc-macos-amd64.tar.xz -C $(BUILD_DIR) crc-macos-$(CRC_VERSION)-amd64 --owner=0 --group=0
 
 	@mkdir -p $(BUILD_DIR)/crc-linux-$(CRC_VERSION)-amd64
 	@cp LICENSE $(BUILD_DIR)/linux-amd64/crc $(BUILD_DIR)/crc-linux-$(CRC_VERSION)-amd64
@@ -240,8 +236,7 @@ ifeq ($(MOCK_BUNDLE),true)
 endif
 	@$(call check_defined, BUNDLE_DIR, "Embedding bundle requires BUNDLE_DIR set to a directory containing CRC bundles for all hypervisors")
 
-embed_bundle: clean cross $(HOST_BUILD_DIR)/crc-embedder check_bundledir $(HYPERKIT_BUNDLENAME) $(HYPERV_BUNDLENAME) $(LIBVIRT_BUNDLENAME)
-	$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --goos=darwin --bundle-dir=$(BUNDLE_DIR) $(BUILD_DIR)/macos-amd64/crc
+embed_bundle: clean cross $(HOST_BUILD_DIR)/crc-embedder check_bundledir $(HYPERV_BUNDLENAME) $(LIBVIRT_BUNDLENAME)
 	$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --goos=linux --bundle-dir=$(BUNDLE_DIR) $(BUILD_DIR)/linux-amd64/crc
 	$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --goos=windows --bundle-dir=$(BUNDLE_DIR) $(BUILD_DIR)/windows-amd64/crc.exe
 
diff --git a/centos_ci.sh b/centos_ci.sh
index 9fa5f1bcb..54b186e42 100644
--- a/centos_ci.sh
+++ b/centos_ci.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 # bundle location
-BUNDLE_VERSION=4.7.11
+BUNDLE_VERSION=4.7.13
 BUNDLE=crc_libvirt_$BUNDLE_VERSION.crcbundle
 GO_VERSION=1.14.13
 
diff --git a/pkg/crc/machine/bundle/copier.go b/pkg/crc/machine/bundle/copier.go
index 0179ebc41..3dfab9220 100644
--- a/pkg/crc/machine/bundle/copier.go
+++ b/pkg/crc/machine/bundle/copier.go
@@ -37,7 +37,7 @@ func NewCopier(srcBundle *CrcBundleInfo, basePath string, customBundleName strin
 		return nil, err
 	}
 
-	copier.copiedBundle.bundleName = customBundleName
+	copier.copiedBundle.Name = customBundleName
 	copier.copiedBundle.Type = "custom"
 	copier.srcBundle = srcBundle
 	copier.copiedBundle.cachedPath = bundlePath
@@ -114,7 +114,7 @@ func (copier *Copier) GenerateBundle(bundleName string) error {
 		return fmt.Errorf("error copying bundle metadata  %w", err)
 	}
 
-	logging.Infof("Compressing %s...", GetBundleNameWithoutExtension(copier.copiedBundle.bundleName))
+	logging.Infof("Compressing %s...", GetBundleNameWithoutExtension(copier.copiedBundle.Name))
 	return compress.Compress(copier.copiedBundle.cachedPath, fmt.Sprintf("%s%s", bundleName, bundleExtension))
 }
 
diff --git a/pkg/crc/machine/bundle/metadata.go b/pkg/crc/machine/bundle/metadata.go
index 6762c4ad8..0b575980f 100644
--- a/pkg/crc/machine/bundle/metadata.go
+++ b/pkg/crc/machine/bundle/metadata.go
@@ -17,13 +17,14 @@ import (
 type CrcBundleInfo struct {
 	Version     string      `json:"version"`
 	Type        string      `json:"type"`
+	Name        string      `json:"name"`
 	BuildInfo   BuildInfo   `json:"buildInfo"`
 	ClusterInfo ClusterInfo `json:"clusterInfo"`
 	Nodes       []Node      `json:"nodes"`
 	Storage     Storage     `json:"storage"`
 	DriverInfo  DriverInfo  `json:"driverInfo"`
-	cachedPath  string
-	bundleName  string
+
+	cachedPath string
 }
 
 type BuildInfo struct {
@@ -89,7 +90,7 @@ func (bundle *CrcBundleInfo) resolvePath(filename string) string {
 }
 
 func (bundle *CrcBundleInfo) GetBundleName() string {
-	return bundle.bundleName
+	return bundle.Name
 }
 
 func (bundle *CrcBundleInfo) GetAPIHostname() string {
diff --git a/pkg/crc/machine/bundle/repository.go b/pkg/crc/machine/bundle/repository.go
index cf11c3d8f..bbe194eca 100644
--- a/pkg/crc/machine/bundle/repository.go
+++ b/pkg/crc/machine/bundle/repository.go
@@ -48,7 +48,6 @@ func (repo *Repository) Get(bundleName string) (*CrcBundleInfo, error) {
 		return nil, err
 	}
 	bundleInfo.cachedPath = path
-	bundleInfo.bundleName = bundleName
 
 	if err := bundleInfo.verify(); err != nil {
 		return nil, err
diff --git a/pkg/crc/machine/start.go b/pkg/crc/machine/start.go
index eedf5b9bc..64e1d9931 100644
--- a/pkg/crc/machine/start.go
+++ b/pkg/crc/machine/start.go
@@ -41,8 +41,7 @@ import (
 
 const minimumMemoryForMonitoring = 14336
 
-func getCrcBundleInfo(bundlePath string) (*bundle.CrcBundleInfo, error) {
-	bundleName := filepath.Base(bundlePath)
+func getCrcBundleInfo(bundleName, bundlePath string) (*bundle.CrcBundleInfo, error) {
 	bundleInfo, err := bundle.Use(bundleName)
 	if err == nil {
 		logging.Infof("Loading bundle: %s...", bundleName)
@@ -150,6 +149,8 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
 		return nil, errors.Wrap(err, "Cannot determine if VM exists")
 	}
 
+	bundleName := bundle.GetBundleNameWithoutExtension(filepath.Base(startConfig.BundlePath))
+
 	if !exists {
 		telemetry.SetStartType(ctx, telemetry.CreationStartType)
 
@@ -159,7 +160,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
 			return nil, errors.Wrap(err, "Failed to ask for pull secret")
 		}
 
-		crcBundleMetadata, err := getCrcBundleInfo(startConfig.BundlePath)
+		crcBundleMetadata, err := getCrcBundleInfo(bundleName, startConfig.BundlePath)
 		if err != nil {
 			return nil, errors.Wrap(err, "Error getting bundle metadata")
 		}
@@ -168,7 +169,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
 
 		machineConfig := config.MachineConfig{
 			Name:            client.name,
-			BundleName:      filepath.Base(startConfig.BundlePath),
+			BundleName:      bundleName,
 			CPUs:            startConfig.CPUs,
 			Memory:          startConfig.Memory,
 			DiskSize:        startConfig.DiskSize,
@@ -197,13 +198,13 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
 	if err != nil {
 		return nil, errors.Wrap(err, "Error loading bundle metadata")
 	}
-	bundleName := crcBundleMetadata.GetBundleName()
-	if bundleName != filepath.Base(startConfig.BundlePath) {
+	currentBundleName := crcBundleMetadata.GetBundleName()
+	if currentBundleName != bundleName {
 		logging.Debugf("Bundle '%s' was requested, but the existing VM is using '%s'",
-			filepath.Base(startConfig.BundlePath), bundleName)
+			bundleName, currentBundleName)
 		return nil, fmt.Errorf("Bundle '%s' was requested, but the existing VM is using '%s'",
-			filepath.Base(startConfig.BundlePath),
-			bundleName)
+			bundleName,
+			currentBundleName)
 	}
 	vmState, err := host.Driver.GetState()
 	if err != nil {
@@ -224,7 +225,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
 		}, nil
 	}
 
-	if _, err := bundle.Use(bundleName); err != nil {
+	if _, err := bundle.Use(currentBundleName); err != nil {
 		return nil, err
 	}
 
@@ -288,10 +289,15 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
 	}
 
 	// Start network time synchronization if `CRC_DEBUG_ENABLE_STOP_NTP` is not set
-	if stopNtp, _ := strconv.ParseBool(os.Getenv("CRC_DEBUG_ENABLE_STOP_NTP")); !stopNtp {
-		logging.Info("Starting network time synchronization in CodeReady Containers VM")
-		if _, _, err := sshRunner.Run("sudo timedatectl set-ntp on"); err != nil {
-			return nil, errors.Wrap(err, "Failed to start network time synchronization")
+	if stopNtp, _ := strconv.ParseBool(os.Getenv("CRC_DEBUG_ENABLE_STOP_NTP")); stopNtp {
+		logging.Info("Stopping network time synchronization in CodeReady Containers VM")
+		if _, _, err := sshRunner.RunPrivileged("Turning off the ntp server", "timedatectl set-ntp off"); err != nil {
+			return nil, errors.Wrap(err, "Failed to stop network time synchronization")
+		}
+		logging.Info("Setting clock to host clock (UTC timezone)")
+		dateCmd := fmt.Sprintf("date -s '%s'", time.Now().Format(time.UnixDate))
+		if _, _, err := sshRunner.RunPrivileged("Setting clock same as host", dateCmd); err != nil {
+			return nil, errors.Wrap(err, "Failed to set clock to same as host")
 		}
 	}
 
diff --git a/pkg/crc/ssh/ssh.go b/pkg/crc/ssh/ssh.go
index 54e6ad8ea..414ffbd14 100644
--- a/pkg/crc/ssh/ssh.go
+++ b/pkg/crc/ssh/ssh.go
@@ -44,6 +44,7 @@ func (runner *Runner) RunPrivate(cmd string, args ...string) (string, string, er
 }
 
 func (runner *Runner) RunPrivileged(reason string, cmdAndArgs ...string) (string, string, error) {
+	logging.Debugf("Using root access: %s", reason)
 	commandline := fmt.Sprintf("sudo %s", strings.Join(cmdAndArgs, " "))
 	return runner.runSSHCommand(commandline, false)
 }


Test patch:
diff --git a/pkg/crc/machine/bundle/copier_test.go b/pkg/crc/machine/bundle/copier_test.go
index 9e36c817d..22707444d 100644
--- a/pkg/crc/machine/bundle/copier_test.go
+++ b/pkg/crc/machine/bundle/copier_test.go
@@ -8,7 +8,6 @@ import (
 	"path/filepath"
 	"testing"
 
-	"github.com/code-ready/crc/pkg/crc/constants"
 	crcos "github.com/code-ready/crc/pkg/os"
 	"github.com/stretchr/testify/assert"
 )
@@ -16,12 +15,10 @@ import (
 func TestGenerateBundle(t *testing.T) {
 	var b CrcBundleInfo
 	assert.NoError(t, json.Unmarshal([]byte(jsonForBundle("crc_4.7.1")), &b))
-	b.bundleName = "crc_4.7.1"
-	b.Storage.Files[0].Name = constants.OcExecutableName
 
 	tmpBundleDir, err := ioutil.TempDir("", "bundle_data")
 	assert.NoError(t, err)
-	b.cachedPath = filepath.Join(tmpBundleDir, b.bundleName)
+	b.cachedPath = filepath.Join(tmpBundleDir, b.Name)
 	defer os.RemoveAll(tmpBundleDir)
 
 	createDummyBundleFiles(t, &b)
diff --git a/pkg/crc/machine/bundle/metadata_test.go b/pkg/crc/machine/bundle/metadata_test.go
index 99f6da4b7..5c468562f 100644
--- a/pkg/crc/machine/bundle/metadata_test.go
+++ b/pkg/crc/machine/bundle/metadata_test.go
@@ -23,6 +23,7 @@ func jsonForBundleWithVersion(version, name string) string {
 	return fmt.Sprintf(`{
   "version": "%s",
   "type": "snc",
+  "name": "%s",
   "buildInfo": {
     "buildTime": "2020-10-26T04:48:26+00:00",
     "openshiftInstallerVersion": "./openshift-install v4.6.0\nbuilt from commit ebdbda57fc18d3b73e69f0f2cc499ddfca7e6593\nrelease image registry.svc.ci.openshift.org/origin/release:4.5",
@@ -68,7 +69,7 @@ func jsonForBundleWithVersion(version, name string) string {
   "driverInfo": {
     "name": "libvirt"
   }
-}`, version, openshiftVersion(name), constants.OcExecutableName)
+}`, version, name, openshiftVersion(name), constants.OcExecutableName)
 }
 
 func openshiftVersion(name string) string {
@@ -79,6 +80,7 @@ func openshiftVersion(name string) string {
 var parsedReference = CrcBundleInfo{
 	Version: "1.0",
 	Type:    "snc",
+	Name:    "crc_libvirt_4.6.1",
 	BuildInfo: BuildInfo{
 		BuildTime:                 "2020-10-26T04:48:26+00:00",
 		OpenshiftInstallerVersion: "./openshift-install v4.6.0\nbuilt from commit ebdbda57fc18d3b73e69f0f2cc499ddfca7e6593\nrelease image registry.svc.ci.openshift.org/origin/release:4.5",