fix: fix kvm2 numa simulate ut&lint
parent
badc5d4532
commit
529881e01c
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -320,11 +320,11 @@ 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")
|
||||
}
|
||||
d.NUMANodeXML = NUMAXML
|
||||
d.NUMANodeXML = numaXML
|
||||
}
|
||||
|
||||
store := d.ResolveStorePath(".")
|
||||
|
|
|
@ -24,8 +24,8 @@ import (
|
|||
"text/template"
|
||||
)
|
||||
|
||||
// NUMATmpl NUMA XML Template
|
||||
const NUMATmpl = `
|
||||
// numaTmpl NUMA XML Template
|
||||
const numaTmpl = `
|
||||
<numa>
|
||||
{{- range $idx,$val :=. }}
|
||||
<cell id='{{$idx}}' cpus='{{$val.CPUTopology}}' memory='{{$val.Memory}}' unit='MiB'/>
|
||||
|
@ -33,16 +33,19 @@ const NUMATmpl = `
|
|||
</numa>
|
||||
`
|
||||
|
||||
// NUMA this struct use for NUMATmpl
|
||||
// NUMA this struct use for numaTmpl
|
||||
type NUMA struct {
|
||||
CPUCount int
|
||||
Memory int
|
||||
// cpu count on numa node
|
||||
CPUCount int
|
||||
// memory on numa node
|
||||
Memory int
|
||||
// cpu sequence on numa node eg: 0,1,2,3
|
||||
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")
|
||||
}
|
||||
|
@ -81,10 +84,10 @@ func NumaXml(cpu, memory, numaCount int) (string, error) {
|
|||
numaNodes[i].Memory++
|
||||
}
|
||||
|
||||
tmpl := template.Must(template.New("numa").Parse(NUMATmpl))
|
||||
var NUMAXML bytes.Buffer
|
||||
if err := tmpl.Execute(&NUMAXML, numaNodes); err != nil {
|
||||
tmpl := template.Must(template.New("numa").Parse(numaTmpl))
|
||||
var numaXML bytes.Buffer
|
||||
if err := tmpl.Execute(&numaXML, numaNodes); err != nil {
|
||||
return "", fmt.Errorf("couldn't generate numa XML: %v", err)
|
||||
}
|
||||
return NUMAXML.String(), nil
|
||||
return numaXML.String(), nil
|
||||
}
|
||||
|
|
|
@ -21,13 +21,13 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestGetNUMAXml(t *testing.T) {
|
||||
_, err := NumaXml(1, 1024, 0)
|
||||
func TestNumaXml(t *testing.T) {
|
||||
_, 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'/>
|
||||
|
|
Loading…
Reference in New Issue