Skip to content

Commit

Permalink
fix: fix kvm2 numa simulate ut&lint
Browse files Browse the repository at this point in the history
  • Loading branch information
phantooom committed Feb 22, 2021
1 parent 8bd281a commit 898057e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
29 changes: 17 additions & 12 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions cmd/minikube/cmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/drivers/kvm/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/drivers/kvm/numa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/drivers/kvm/numa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := `<numa>
<cell id='0' cpus='0,1' memory='1280' unit='MiB'/>
<cell id='1' cpus='2,3' memory='1280' unit='MiB'/>
Expand Down

0 comments on commit 898057e

Please sign in to comment.