diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 098916ef4a34..b92ba3767123 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -313,18 +313,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k out.WarningT("--network flag is only valid with the docker/podman drivers, it will be ignored") } - if viper.GetInt(kvmNUMACount) < 1 || viper.GetInt(kvmNUMACount) > 8 { - exit.Message(reason.Usage, "--kvm-numa-count range is 1-8") - } - if viper.GetInt(kvmNUMACount) > 1 { - v, err := pkgutil.ParseKubernetesVersion(k8sVersion) - if err != nil { - exit.Message(reason.Usage, "invalid kubernetes version") - } - if v.LT(semver.Version{Major: 1,Minor: 18}){ - exit.Message(reason.Usage, "numa node is only supported on k8s v1.18 and later") - } - } + checkNumaCount(k8sVersion) cc = config.ClusterConfig{ Name: ClusterFlagValue(), @@ -423,6 +412,22 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k return createNode(cc, kubeNodeName, existing) } +func checkNumaCount(k8sVersion string) { + if viper.GetInt(kvmNUMACount) < 1 || viper.GetInt(kvmNUMACount) > 8 { + exit.Message(reason.Usage, "--kvm-numa-count range is 1-8") + } + + if viper.GetInt(kvmNUMACount) > 1 { + v, err := pkgutil.ParseKubernetesVersion(k8sVersion) + if err != nil { + exit.Message(reason.Usage, "invalid kubernetes version") + } + if v.LT(semver.Version{Major: 1, Minor: 18}) { + exit.Message(reason.Usage, "numa node is only supported on k8s v1.18 and later") + } + } +} + // upgradeExistingConfig upgrades legacy configuration files func upgradeExistingConfig(cc *config.ClusterConfig) { if cc == nil { diff --git a/cmd/minikube/cmd/start_test.go b/cmd/minikube/cmd/start_test.go index a1071c28f974..d5b519e32591 100644 --- a/cmd/minikube/cmd/start_test.go +++ b/cmd/minikube/cmd/start_test.go @@ -133,6 +133,7 @@ func TestMirrorCountry(t *testing.T) { cmd := &cobra.Command{} viper.SetDefault(imageRepository, test.imageRepository) viper.SetDefault(imageMirrorCountry, test.mirrorCountry) + viper.SetDefault(kvmNUMACount, 1) config, _, err := generateClusterConfig(cmd, nil, k8sVersion, "none") if err != nil { t.Fatalf("Got unexpected error %v during config generation", err) diff --git a/pkg/drivers/kvm/kvm.go b/pkg/drivers/kvm/kvm.go index 5843557e0469..4c0eaa3664bf 100644 --- a/pkg/drivers/kvm/kvm.go +++ b/pkg/drivers/kvm/kvm.go @@ -320,7 +320,7 @@ func (d *Driver) Create() (err error) { } if d.NUMANodeCount > 1 { - NUMAXML, err := NumaXml(d.CPU, d.Memory, d.NUMANodeCount) + NUMAXML, err := NumaXML(d.CPU, d.Memory, d.NUMANodeCount) if err != nil { return errors.Wrap(err, "creating NUMA XML") } diff --git a/pkg/drivers/kvm/numa.go b/pkg/drivers/kvm/numa.go index 4ac08a59a066..3e66f6156e9d 100644 --- a/pkg/drivers/kvm/numa.go +++ b/pkg/drivers/kvm/numa.go @@ -40,9 +40,9 @@ type NUMA struct { CPUTopology string } -// NumaXml generate numa xml +// NumaXML generate numa xml // evenly distributed cpu core & memory to each numa node -func NumaXml(cpu, memory, numaCount int) (string, error) { +func NumaXML(cpu, memory, numaCount int) (string, error) { if numaCount < 1 { return "", fmt.Errorf("numa node count must >= 1") } diff --git a/pkg/drivers/kvm/numa_test.go b/pkg/drivers/kvm/numa_test.go index 103d8bf08d17..a64c4e4aae13 100644 --- a/pkg/drivers/kvm/numa_test.go +++ b/pkg/drivers/kvm/numa_test.go @@ -22,12 +22,12 @@ import ( ) func TestGetNUMAXml(t *testing.T) { - _, err := NumaXml(1, 1024, 0) + _, err := NumaXML(1, 1024, 0) if err == nil { t.Errorf("check invalid numa count failed: %s", err) } - xml, err := NumaXml(10, 10240, 8) + xml, err := NumaXML(10, 10240, 8) expXML := `