Validate --base-image flag and active driver combo
parent
0a6b52d90d
commit
6bf7ca3dd2
|
@ -38,7 +38,9 @@ import (
|
|||
"github.com/shirou/gopsutil/cpu"
|
||||
gopshost "github.com/shirou/gopsutil/host"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
|
||||
"k8s.io/minikube/pkg/drivers/kic/oci"
|
||||
"k8s.io/minikube/pkg/minikube/bootstrapper/bsutil"
|
||||
|
@ -167,7 +169,10 @@ func runStart(cmd *cobra.Command, args []string) {
|
|||
|
||||
validateSpecifiedDriver(existing)
|
||||
validateKubernetesVersion(existing)
|
||||
|
||||
ds, alts, specified := selectDriver(existing)
|
||||
validateBaseImage(cmd.Flag(kicBaseImage), ds.Name)
|
||||
|
||||
starter, err := provisionWithDriver(cmd, ds, existing)
|
||||
if err != nil {
|
||||
node.ExitIfFatal(err)
|
||||
|
@ -516,6 +521,7 @@ func kubectlVersion(path string) (string, error) {
|
|||
return cv.ClientVersion.GitVersion, nil
|
||||
}
|
||||
|
||||
// returns (current_driver, suggested_drivers, "true, if the driver is set by command line arg or in the config file")
|
||||
func selectDriver(existing *config.ClusterConfig) (registry.DriverState, []registry.DriverState, bool) {
|
||||
// Technically unrelated, but important to perform before detection
|
||||
driver.SetLibvirtURI(viper.GetString(kvmQemuURI))
|
||||
|
@ -1185,6 +1191,25 @@ func validateKubernetesVersion(old *config.ClusterConfig) {
|
|||
}
|
||||
}
|
||||
|
||||
// validateBaseImage checks that --base-image is not passed if the drive being in use is KIC (docker/podman)
|
||||
// if so, the function exits the process
|
||||
func validateBaseImage(baseImage *pflag.Flag, driver string) {
|
||||
if !validBaseImageFlag(baseImage.Changed, driver) {
|
||||
exit.Message(reason.Usage, "TODO: image {{.image}} with driver {{.driver}}",
|
||||
out.V{
|
||||
"driver": driver,
|
||||
"image": baseImage.Value,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
func validBaseImageFlag(baseImageFlagSet bool, driver string) bool {
|
||||
if baseImageFlagSet {
|
||||
return registry.IsKIC(driver)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func getKubernetesVersion(old *config.ClusterConfig) string {
|
||||
paramVersion := viper.GetString(kubernetesVersion)
|
||||
|
||||
|
|
|
@ -23,8 +23,10 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/driver"
|
||||
"k8s.io/minikube/pkg/minikube/proxy"
|
||||
)
|
||||
|
||||
|
@ -278,3 +280,50 @@ func TestSuggestMemoryAllocation(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseImageFlagDriverCombo(t *testing.T) {
|
||||
type testStruct struct {
|
||||
description string
|
||||
imageSet bool
|
||||
driver string
|
||||
}
|
||||
invalidCombos := []testStruct{
|
||||
{"KVM2 with flag", true, driver.KVM2},
|
||||
{"VirtualBox with flag", true, driver.VirtualBox},
|
||||
{"HyperKit with flag", true, driver.HyperKit},
|
||||
{"VMware with flag", true, driver.VMware},
|
||||
{"VMwareFusion with flag", true, driver.VMwareFusion},
|
||||
{"HyperV with flag", true, driver.HyperV},
|
||||
{"Parallels with flag", true, driver.Parallels},
|
||||
}
|
||||
validCombos := []testStruct{
|
||||
{"Docker with flag", true, driver.Docker},
|
||||
{"Podman with flag", true, driver.Podman},
|
||||
{"Docker w/o flag", false, driver.Docker},
|
||||
{"Podman w/o flag", false, driver.Podman},
|
||||
{"KVM2 w/o flag", false, driver.KVM2},
|
||||
{"VirtualBox w/o flag", false, driver.VirtualBox},
|
||||
{"HyperKit w/o flag", false, driver.HyperKit},
|
||||
{"VMware w/o flag", false, driver.VMware},
|
||||
{"VMwareFusion w/o flag", false, driver.VMwareFusion},
|
||||
{"HyperV w/o flag", false, driver.HyperV},
|
||||
{"Parallels w/o flag", false, driver.Parallels},
|
||||
}
|
||||
|
||||
for _, test := range validCombos {
|
||||
t.Run(test.description, func(t *testing.T) {
|
||||
if !validBaseImageFlag(test.imageSet, test.driver) {
|
||||
t.Errorf("invalidBaseImageFlag(base-image-set=%v, driver=%v): got false, expected true",
|
||||
test.imageSet, test.driver)
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, test := range invalidCombos {
|
||||
t.Run(test.description, func(t *testing.T) {
|
||||
if validBaseImageFlag(test.imageSet, test.driver) {
|
||||
t.Errorf("invalidBaseImageFlag(base-image-set=%v, driver=%v): got true, expected false",
|
||||
test.imageSet, test.driver)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue