Skip to content

Commit 5f56a56

Browse files
committed
Issue #272 Verify the user provide bundle against released one
Most of the time user using older version of crc bundle with new release and this give an unexpected error to the user. We always need to use the bundle version which released as part of the release. This check make sure user is going to use the updated one. Minor refactor around getting bundle info as part of version.
1 parent 4f33e45 commit 5f56a56

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
BUNDLE_VERSION = 4.1.0
16-
CRC_VERSION = 0.87.0-alpha-$(BUNDLE_VERSION)
16+
CRC_VERSION = 0.87.0-alpha
1717
COMMIT_SHA=$(shell git rev-parse --short HEAD)
1818

1919
# Go and compilation related variables
@@ -37,6 +37,7 @@ PACKAGES := go list ./... | grep -v /out
3737

3838
# Linker flags
3939
VERSION_VARIABLES := -X $(REPOPATH)/pkg/crc.crcVersion=$(CRC_VERSION) \
40+
-X $(REPOPATH)/pkg/crc.bundleVersion=$(BUNDLE_VERSION) \
4041
-X $(REPOPATH)/pkg/crc.commitSha=$(COMMIT_SHA)
4142

4243
# https://golang.org/cmd/link/

cmd/crc/cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ var versionCmd = &cobra.Command{
3737
}
3838

3939
func runPrintVersion(arguments []string) {
40-
fmt.Printf("version: %s+%s\n", crcPkg.GetCRCVersion(), crcPkg.GetCommitSha())
40+
fmt.Printf("version: %s-%s+%s\n", crcPkg.GetCRCVersion(), crcPkg.GetBundleVersion(), crcPkg.GetCommitSha())
4141
}

pkg/crc/machine/machine.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/code-ready/crc/pkg/crc/errors"
1212
"github.com/code-ready/crc/pkg/crc/logging"
1313

14-
// host and instance related
1514
"github.com/code-ready/crc/pkg/crc/network"
1615
"github.com/code-ready/crc/pkg/crc/systemd"
1716
crcos "github.com/code-ready/crc/pkg/os"
@@ -55,7 +54,7 @@ func Start(startConfig StartConfig) (StartResult, error) {
5554
Memory: startConfig.Memory,
5655
}
5756

58-
logging.InfoF("Extracting the Bundle tarball ...")
57+
logging.InfoF("Extracting the %s Bundle tarball ...", filepath.Base(machineConfig.BundlePath))
5958
crcBundleMetadata, extractedPath, err := bundle.GetCrcBundleInfo(machineConfig)
6059
if err != nil {
6160
logging.ErrorF("Error to get bundle Metadata %v", err)

pkg/crc/validation/validation.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package validation
22

33
import (
4+
"fmt"
45
"os"
6+
"path/filepath"
7+
"strings"
58

9+
"github.com/code-ready/crc/pkg/crc"
610
"github.com/code-ready/crc/pkg/crc/constants"
711
"github.com/code-ready/crc/pkg/crc/errors"
812
"github.com/code-ready/crc/pkg/crc/machine"
@@ -39,5 +43,11 @@ func ValidateBundle(bundle string) error {
3943
if _, err := os.Stat(bundle); os.IsNotExist(err) {
4044
return errors.NewF("Expected file %s does not exist", bundle)
4145
}
46+
// Check if the version of the bundle provided by user is same as what is released with crc.
47+
releaseBundleVersion := crc.GetBundleVersion()
48+
userProvidedBundleVersion := filepath.Base(bundle)
49+
if !strings.Contains(userProvidedBundleVersion, fmt.Sprintf("%s.tar.xz", releaseBundleVersion)) {
50+
return errors.NewF("%s bundle is not supported for this release use updated one (crc_<hypervisor>_%s.tar.xz)", userProvidedBundleVersion, releaseBundleVersion)
51+
}
4252
return nil
4353
}

pkg/crc/version.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ var (
2323

2424
// The SHA-1 of the commit this binary is build off
2525
commitSha = "sha-unset"
26+
27+
// Bundle version which used for the release.
28+
bundleVersion = "0.0.0-unset"
2629
)
2730

2831
func GetCRCVersion() string {
@@ -32,3 +35,7 @@ func GetCRCVersion() string {
3235
func GetCommitSha() string {
3336
return commitSha
3437
}
38+
39+
func GetBundleVersion() string {
40+
return bundleVersion
41+
}

0 commit comments

Comments
 (0)