forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving node-labeller and cpu plugin from ssp operator into kubevirt
This feature labels nodes with host supported cpu models and features. It runs empty virt-launcher pod which contains info about supported cpus on the host. Virt-handler then parses all info and labels the node. Signed-off-by: Karel Simon <[email protected]>
- Loading branch information
Showing
32 changed files
with
1,342 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [ ! -e /dev/kvm ]; then | ||
mknod /dev/kvm c 10 $(grep '\\<kvm\\>' /proc/misc | cut -f 1 -d' ') | ||
fi | ||
chmod o+rw /dev/kvm | ||
|
||
libvirtd -d | ||
|
||
virsh domcapabilities --machine q35 --arch x86_64 --virttype kvm > /var/lib/kubevirt-node-labeller/virsh_domcapabilities.xml | ||
|
||
cp -r /usr/share/libvirt/cpu_map /var/lib/kubevirt-node-labeller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = [ | ||
"config.go", | ||
"cpu_plugin.go", | ||
"model.go", | ||
"node_labeller.go", | ||
"test-util.go", | ||
], | ||
importpath = "kubevirt.io/kubevirt/pkg/virt-handler/node-labeller", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/virt-handler/device-manager:go_default_library", | ||
"//staging/src/kubevirt.io/client-go/kubecli:go_default_library", | ||
"//staging/src/kubevirt.io/client-go/log:go_default_library", | ||
"//vendor/gopkg.in/yaml.v2:go_default_library", | ||
"//vendor/k8s.io/api/core/v1:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", | ||
"//vendor/k8s.io/client-go/tools/cache:go_default_library", | ||
"//vendor/k8s.io/client-go/util/workqueue:go_default_library", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "go_default_test", | ||
srcs = [ | ||
"config_test.go", | ||
"cpu_plugin_test.go", | ||
"node_labeller_suite_test.go", | ||
], | ||
embed = [":go_default_library"], | ||
deps = [ | ||
"//staging/src/kubevirt.io/client-go/kubecli:go_default_library", | ||
"//vendor/github.com/golang/mock/gomock:go_default_library", | ||
"//vendor/github.com/onsi/ginkgo:go_default_library", | ||
"//vendor/github.com/onsi/gomega:go_default_library", | ||
"//vendor/k8s.io/api/core/v1:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", | ||
"//vendor/k8s.io/client-go/kubernetes/fake:go_default_library", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Copyright 2020 Red Hat, Inc. | ||
*/ | ||
|
||
package nodelabeller | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
//Config holds data about obsolete cpus and minimal baseline cpus | ||
type Config struct { | ||
ObsoleteCPUs []string `yaml:"obsoleteCPUs"` | ||
MinCPU string `yaml:"minCPU"` | ||
} | ||
|
||
var configPath = "/var/lib/kubevirt-node-labeller/cpu-plugin-configmap.yaml" | ||
|
||
//LoadConfig loads config yaml file with obsolete cpus and minimal baseline cpus | ||
func (n *NodeLabeller) loadConfig() (Config, error) { | ||
config := Config{} | ||
cm, err := n.clientset.CoreV1().ConfigMaps(n.namespace).Get("kubevirt-cpu-plugin-configmap", metav1.GetOptions{}) | ||
if err != nil { | ||
return config, err | ||
} | ||
|
||
if value, ok := cm.Data["cpu-plugin-configmap.yaml"]; ok { | ||
err := writeConfigFile(configPath, value) | ||
if err != nil { | ||
return config, err | ||
} | ||
} | ||
err = getStructureFromYamlFile(configPath, &config) | ||
if err != nil { | ||
return Config{}, err | ||
} | ||
|
||
return config, nil | ||
} | ||
|
||
//GetObsoleteCPUMap returns map of obsolete cpus | ||
func (c *Config) getObsoleteCPUMap() map[string]bool { | ||
return convertStringSliceToMap(c.ObsoleteCPUs) | ||
} | ||
|
||
//GetMinCPU returns minimal baseline cpu. If minimal cpu is not defined, | ||
//it returns for Intel vendor Penryn cpu model, for AMD it returns Opteron_G1. | ||
func (c *Config) getMinCPU() string { | ||
return c.MinCPU | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Copyright 2020 Red Hat, Inc. | ||
* | ||
*/ | ||
|
||
package nodelabeller | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Node-labeller config", func() { | ||
|
||
It("should return obsolete cpus", func() { | ||
var testCases = []struct { | ||
conf Config | ||
result map[string]bool | ||
}{ | ||
{ | ||
conf: Config{ | ||
ObsoleteCPUs: []string{"Conroe", "Haswell", "Penryn"}, | ||
}, | ||
result: map[string]bool{ | ||
"Conroe": true, | ||
"Haswell": true, | ||
"Penryn": true, | ||
}, | ||
}, | ||
{ | ||
conf: Config{ | ||
ObsoleteCPUs: []string{}, | ||
}, | ||
result: map[string]bool{}, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
m := testCase.conf.getObsoleteCPUMap() | ||
Expect(m).To(Equal(testCase.result), "obsolete cpus are not equal") | ||
} | ||
}) | ||
|
||
It("should return min cpu", func() { | ||
var testCases = []struct { | ||
conf Config | ||
provider string | ||
result string | ||
}{ | ||
{ | ||
conf: Config{ | ||
MinCPU: "Penryn", | ||
}, | ||
result: "Penryn", | ||
}, | ||
{ | ||
conf: Config{ | ||
MinCPU: "", | ||
}, | ||
result: "", | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
result := testCase.conf.getMinCPU() | ||
Expect(result).To(Equal(testCase.result), "minCPU is not equal") | ||
} | ||
}) | ||
|
||
}) |
Oops, something went wrong.