Skip to content

Commit 69f693f

Browse files
anjannathpraveenkumar
authored andcommitted
Issue #356 Unpack bundle to disk on crc setup command
1 parent 4c86ae6 commit 69f693f

File tree

18 files changed

+736
-9
lines changed

18 files changed

+736
-9
lines changed

cmd/crc/cmd/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ var (
3333
// Preflight checks
3434
SkipCheckVirtualBoxInstalled = createSetting("skip-check-virtualbox-installed", nil, []validationFnType{validations.ValidateBool})
3535
WarnCheckVirtualBoxInstalled = createSetting("warn-check-virtualbox-installed", nil, []validationFnType{validations.ValidateBool})
36+
SkipCheckBundleCached = createSetting("skip-check-bundle-cached", nil, []validationFnType{validations.ValidateBool})
37+
WarnCheckBundleCached = createSetting("warn-check-bundle-cached", true, []validationFnType{validations.ValidateBool})
3638
)
3739

3840
// CreateSetting returns a filled struct of ConfigSetting

cmd/crc/cmd/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func runStart(arguments []string) {
7878

7979
func initStartCmdFlagSet() *pflag.FlagSet {
8080
flagSet := pflag.NewFlagSet("start", pflag.ExitOnError)
81-
flagSet.StringP(config.Bundle.Name, "b", constants.GetDefaultBundle(), "The system bundle used for deployment of the OpenShift cluster.")
81+
flagSet.StringP(config.Bundle.Name, "b", constants.DefaultBundlePath, "The system bundle used for deployment of the OpenShift cluster.")
8282
flagSet.StringP(config.VMDriver.Name, "d", machine.DefaultDriver.Driver, fmt.Sprintf("The driver to use for the CRC VM. Possible values: %v", machine.SupportedDriverValues()))
8383
flagSet.StringP(config.PullSecretFile.Name, "p", "", fmt.Sprintf("File path of Image pull secret for User (Download it from %s)", constants.DefaultPullSecretURL))
8484
flagSet.IntP(config.CPUs.Name, "c", constants.DefaultCPUs, "Number of CPU cores to allocate to the CRC VM")

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/code-ready/crc
33
require (
44
github.com/BurntSushi/toml v0.3.1 // indirect
55
github.com/DATA-DOG/godog v0.7.13
6+
github.com/YourFin/binappend v0.0.0-20181105185800-0add4bf0b9ad
67
github.com/cavaliercoder/grab v2.0.0+incompatible
78
github.com/code-ready/clicumber v0.0.0-20190503113956-2563aed4ef12
89
github.com/code-ready/goodhosts v0.0.0-20190712111040-f090f3f77c26

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/DATA-DOG/godog v0.7.13 h1:JmgpKcra7Vf3yzI9vPsWyoQRx13tyKziHtXWDCUUgok
44
github.com/DATA-DOG/godog v0.7.13/go.mod h1:z2OZ6a3X0/YAKVqLfVzYBwFt3j6uSt3Xrqa7XTtcQE0=
55
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
66
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
7+
github.com/YourFin/binappend v0.0.0-20181105185800-0add4bf0b9ad h1:OUogh+sUEo6yRwGEkqifcr3MfXNi0AtdCSwh7H8yTUM=
8+
github.com/YourFin/binappend v0.0.0-20181105185800-0add4bf0b9ad/go.mod h1:QhzJSct0NZ/q7HOtQrw867061u93HYPWa4KTotzdzls=
79
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
810
github.com/bugsnag/bugsnag-go v1.5.1/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
911
github.com/bugsnag/panicwrap v1.2.0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=

pkg/crc/constants/constants_darwin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ package constants
33
import (
44
"fmt"
55
"github.com/code-ready/crc/pkg/crc/version"
6+
"path/filepath"
67
)
78

89
const (
910
OcBinaryName = "oc"
1011
DefaultOcURL = "https://mirror.openshift.com/pub/openshift-v4/clients/oc/latest/macosx/oc.tar.gz"
1112
)
1213

14+
var (
15+
DefaultBundlePath = filepath.Join(CrcBaseDir, GetDefaultBundle())
16+
)
17+
1318
func GetDefaultBundle() string {
1419
return fmt.Sprintf("crc_hyperkit_%s.crcbundle", version.GetBundleVersion())
1520
}

pkg/crc/constants/constants_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ package constants
33
import (
44
"fmt"
55
"github.com/code-ready/crc/pkg/crc/version"
6+
"path/filepath"
67
)
78

89
const (
910
OcBinaryName = "oc"
1011
DefaultOcURL = "https://mirror.openshift.com/pub/openshift-v4/clients/oc/latest/linux/oc.tar.gz"
1112
)
1213

14+
var (
15+
DefaultBundlePath = filepath.Join(CrcBaseDir, GetDefaultBundle())
16+
)
17+
1318
func GetDefaultBundle() string {
1419
return fmt.Sprintf("crc_libvirt_%s.crcbundle", version.GetBundleVersion())
1520
}

pkg/crc/constants/constants_windows.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ package constants
33
import (
44
"fmt"
55
"github.com/code-ready/crc/pkg/crc/version"
6+
"path/filepath"
67
)
78

89
const (
910
OcBinaryName = "oc.exe"
1011
DefaultOcURL = "https://mirror.openshift.com/pub/openshift-v4/clients/oc/latest/windows/oc.zip"
1112
)
1213

14+
var (
15+
DefaultBundlePath = filepath.Join(CrcBaseDir, GetDefaultBundle())
16+
)
17+
1318
func GetDefaultBundle() string {
1419
// TODO: we will change once we have correct bundle for windows
1520
return fmt.Sprintf("crc_hyperv_%s.crcbundle", version.GetBundleVersion())
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package preflight
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
8+
"github.com/YourFin/binappend"
9+
"github.com/kardianos/osext"
10+
11+
"github.com/code-ready/crc/pkg/crc/constants"
12+
)
13+
14+
func checkBundleCached() (bool, error) {
15+
if _, err := os.Stat(constants.DefaultBundlePath); os.IsNotExist(err) {
16+
return false, err
17+
}
18+
return true, nil
19+
}
20+
21+
func fixBundleCached() (bool, error) {
22+
if constants.BundleEmbedded() {
23+
currentExecutable, err := osext.Executable()
24+
if err != nil {
25+
return false, err
26+
}
27+
extractor, err := binappend.MakeExtractor(currentExecutable)
28+
if err != nil {
29+
return false, err
30+
}
31+
f, err := os.Create(constants.DefaultBundlePath)
32+
if err != nil {
33+
return false, err
34+
}
35+
available := extractor.AvalibleData()
36+
data, err := extractor.ByteArray(available[0])
37+
if err != nil {
38+
return false, err
39+
}
40+
w := bufio.NewWriter(f)
41+
defer w.Flush()
42+
w.Write(data)
43+
return true, nil
44+
}
45+
return false, fmt.Errorf("CRC bundle is not embedded in the binary, see 'crc help' for more details.")
46+
}

pkg/crc/preflight/preflight_common.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,16 @@ func preflightCheckAndFix(configuredToSkip bool, check, fix PreflightCheckFixFun
3737
if ok {
3838
return
3939
}
40-
41-
if configuredToWarn {
42-
logging.Warn(err.Error())
43-
return
44-
}
4540
logging.Debug(err.Error())
4641

4742
ok, err = fix()
4843
if ok {
4944
return
5045
}
5146

47+
if configuredToWarn {
48+
logging.Warn(err.Error())
49+
return
50+
}
5251
logging.Fatal(err.Error())
5352
}

pkg/crc/preflight/preflight_darwin.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func StartPreflightChecks(vmDriver string) {
4545
fmt.Sprintf("Checking file permissions for %s", hostFile),
4646
config.GetBool(cmdConfig.WarnCheckResolvConfFilePermissions.Name),
4747
)
48+
preflightCheckSucceedsOrFails(config.GetBool(cmdConfig.SkipCheckBundleCached.Name),
49+
checkBundleCached,
50+
"Checking if CRC bundle is cached in '$HOME/.crc'",
51+
config.GetBool(cmdConfig.WarnCheckBundleCached.Name),
52+
)
4853
}
4954

5055
// SetupHost performs the prerequisite checks and setups the host to run the cluster
@@ -92,4 +97,10 @@ func SetupHost(vmDriver string) {
9297
fmt.Sprintf("Setting file permissions for %s", hostFile),
9398
config.GetBool(cmdConfig.WarnCheckResolvConfFilePermissions.Name),
9499
)
100+
preflightCheckAndFix(config.GetBool(cmdConfig.SkipCheckBundleCached.Name),
101+
checkBundleCached,
102+
fixBundleCached,
103+
"Unpacking bundle from the CRC binary",
104+
config.GetBool(cmdConfig.WarnCheckBundleCached.Name),
105+
)
95106
}

0 commit comments

Comments
 (0)