mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
source/custom: add rules for cpuid and kconfig
Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
This commit is contained in:
parent
d1cce3ba29
commit
e2ee7c6fca
4 changed files with 156 additions and 0 deletions
41
README.md
41
README.md
|
@ -390,6 +390,36 @@ loadedKMod : [<kernel module>, ...]
|
|||
Matching is done by performing logical _AND_ for each provided Element, i.e the Rule will match if all provided Elements (kernel modules) are loaded
|
||||
in the system.
|
||||
|
||||
##### CpuId Rule
|
||||
###### Nomenclature
|
||||
```
|
||||
Element :A CPUID flag
|
||||
```
|
||||
|
||||
The Rule allows matching the available CPUID flags in the system against a provided list of Elements.
|
||||
|
||||
###### Format
|
||||
```yaml
|
||||
cpuId : [<CPUID flag string>, ...]
|
||||
```
|
||||
Matching is done by performing logical _AND_ for each provided Element, i.e the Rule will match if all provided Elements (CPUID flag strings) are available
|
||||
in the system.
|
||||
|
||||
##### Kconfig Rule
|
||||
###### Nomenclature
|
||||
```
|
||||
Element :A Kconfig option
|
||||
```
|
||||
|
||||
The Rule allows matching the kconfig options in the system against a provided list of Elements.
|
||||
|
||||
###### Format
|
||||
```yaml
|
||||
kConfig: [<kernel config option ('y' or 'm') or '=<value>'>, ...]
|
||||
```
|
||||
Matching is done by performing logical _AND_ for each provided Element, i.e the Rule will match if all provided Elements (kernel config options) are enabled ('y' or 'm') or matching '=<value>'.
|
||||
in the kernel.
|
||||
|
||||
#### Example
|
||||
|
||||
```yaml
|
||||
|
@ -419,6 +449,14 @@ custom:
|
|||
- pciId:
|
||||
vendor: ["15b3"]
|
||||
device: ["1014", "1017"]
|
||||
- name: "my.kernel.featureneedscpu"
|
||||
matchOn:
|
||||
- kConfig: ["KVM_INTEL"]
|
||||
- cpuId: ["VMX"]
|
||||
- name: "my.kernel.modulecompiler"
|
||||
matchOn:
|
||||
- kConfig: ["GCC_VERSION=100101"]
|
||||
loadedKMod: ["kmod1"]
|
||||
```
|
||||
|
||||
__In the example above:__
|
||||
|
@ -434,6 +472,9 @@ with a PCI vendor ID of `15b3` _AND_ PCI device ID of `1014` _or_ `1017`.
|
|||
- A node would contain the label: `feature.node.kubernetes.io/custom-my.accumulated.feature=true`
|
||||
if `some_kmod1` _AND_ `some_kmod2` kernel modules are loaded __OR__ the node contains a PCI device
|
||||
with a PCI vendor ID of `15b3` _AND_ PCI device ID of `1014` _OR_ `1017`.
|
||||
- A node would contain the label: `feature.node.kubernetes.io/custom-my.kernel.featureneedscpu=true`
|
||||
if `KVM_INTEL` kernel config is enabled __AND__ the node CPU supports `VMX` virtual machine extensions
|
||||
- A node would contain the label: `feature.node.kubernetes.io/custom-my.kernel.modulecompiler=true` if the in-tree `kmod1` kernel module is loaded __AND__ it's built with `GCC_VERSION=100101`.
|
||||
|
||||
#### Statically defined features
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ type MatchRule struct {
|
|||
PciID *rules.PciIDRule `json:"pciId,omitempty"`
|
||||
UsbID *rules.UsbIDRule `json:"usbId,omitempty"`
|
||||
LoadedKMod *rules.LoadedKModRule `json:"loadedKMod,omitempty"`
|
||||
CpuID *rules.CpuIDRule `json:"cpuId,omitempty"`
|
||||
Kconfig *rules.KconfigRule `json:"kConfig,omitempty"`
|
||||
}
|
||||
|
||||
type FeatureSpec struct {
|
||||
|
@ -119,6 +121,26 @@ func (s Source) discoverFeature(feature FeatureSpec) (bool, error) {
|
|||
continue
|
||||
}
|
||||
}
|
||||
// cpuid rule
|
||||
if rule.CpuID != nil {
|
||||
match, err := rule.CpuID.Match()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !match {
|
||||
continue
|
||||
}
|
||||
}
|
||||
// kconfig rule
|
||||
if rule.Kconfig != nil {
|
||||
match, err := rule.Kconfig.Match()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !match {
|
||||
continue
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
|
|
42
source/custom/rules/cpuid_rule.go
Normal file
42
source/custom/rules/cpuid_rule.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
package rules
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/node-feature-discovery/source/internal/cpuidutils"
|
||||
)
|
||||
|
||||
// CpuIDRule implements Rule
|
||||
type CpuIDRule []string
|
||||
|
||||
var cpuIdFlags map[string]struct{}
|
||||
|
||||
func (cpuids *CpuIDRule) Match() (bool, error) {
|
||||
for _, f := range *cpuids {
|
||||
if _, ok := cpuIdFlags[f]; !ok {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
cpuIdFlags = make(map[string]struct{})
|
||||
for _, f := range cpuidutils.GetCpuidFlags() {
|
||||
cpuIdFlags[f] = struct{}{}
|
||||
}
|
||||
}
|
51
source/custom/rules/kconfig_rule.go
Normal file
51
source/custom/rules/kconfig_rule.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
package rules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sigs.k8s.io/node-feature-discovery/source/internal/kernelutils"
|
||||
)
|
||||
|
||||
// KconfigRule implements Rule
|
||||
type KconfigRule []string
|
||||
|
||||
var kConfigs map[string]struct{}
|
||||
|
||||
func (kconfigs *KconfigRule) Match() (bool, error) {
|
||||
for _, f := range *kconfigs {
|
||||
if _, ok := kConfigs[f]; !ok {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
kConfigs = make(map[string]struct{})
|
||||
|
||||
kconfig, err := kernelutils.ParseKconfig("")
|
||||
if err == nil {
|
||||
for k, v := range kconfig {
|
||||
if v != "true" {
|
||||
kConfigs[fmt.Sprintf("%s=%s", k, v)] = struct{}{}
|
||||
} else {
|
||||
kConfigs[k] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue