mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-06 16:57:10 +00:00
Support backreferencing of output values from previous rules. Enables complex rule setups where custom features are further combined together to form even more sophisticated higher level labels. The labels created by preceding rules are available as a special 'rule.matched' feature (for matchFeatures to use). If referencing rules accross multiple configs/CRDs care must be taken with the ordering. Processing order of rules in nfd-worker: 1. Static rules 2. Files from /etc/kubernetes/node-feature-discovery/custom.d/ in alphabetical order. Subdirectories are processed by reading their files in alphabetical order. 3. Custom rules from main nfd-worker.conf In nfd-master, NodeFeatureRule objects are processed in alphabetical order (based on their metadata.name). This patch also adds new 'vars' fields to the rule spec. Like 'labels', it is a map of key-value pairs but no labels are generated from these. The values specified in 'vars' are only added for backreferencing into the 'rules.matched' feature. This may by desired in schemes where the output of certain rules is only used as intermediate variables for other rules and no labels out of these are wanted. An example setup: - name: "kernel feature" labels: kernel-feature: matchFeatures: - feature: kernel.version matchExpressions: major: {op: Gt, value: ["4"]} - name: "intermediate var feature" vars: nolabel-feature: "true" matchFeatures: - feature: cpu.cpuid matchExpressions: AVX512F: {op: Exists} - feature: pci.device matchExpressions: vendor: {op: In, value: ["8086"]} device: {op: In, value: ["1234", "1235"]} - name: top-level-feature matchFeatures: - feature: rule.matched matchExpressions: kernel-feature: "true" nolabel-feature: "true"
139 lines
4.4 KiB
YAML
139 lines
4.4 KiB
YAML
apiVersion: nfd.k8s-sigs.io/v1alpha1
|
|
kind: NodeFeatureRule
|
|
metadata:
|
|
name: my-rule
|
|
spec:
|
|
rules:
|
|
# The following feature demonstrates the capabilities of the matchFeatures and
|
|
# matchAny matchers.
|
|
- name: "my feature rule"
|
|
labels:
|
|
"my-complex-feature": "my-value"
|
|
# matchFeatures implements a logical AND over feature matchers.
|
|
matchFeatures:
|
|
- feature: cpu.cpuid
|
|
matchExpressions:
|
|
AVX512F: {op: Exists}
|
|
- feature: cpu.cstate
|
|
matchExpressions:
|
|
enabled: {op: IsTrue}
|
|
- feature: cpu.pstate
|
|
matchExpressions:
|
|
no_turbo: {op: IsFalse}
|
|
scaling_governor: {op: In, value: ["performance"]}
|
|
- feature: cpu.rdt
|
|
matchExpressions:
|
|
RDTL3CA: {op: Exists}
|
|
- feature: cpu.sst
|
|
matchExpressions:
|
|
bf.enabled: {op: IsTrue}
|
|
- feature: cpu.topology
|
|
matchExpressions:
|
|
hardware_multithreading: {op: IsFalse}
|
|
|
|
- feature: kernel.config
|
|
matchExpressions:
|
|
X86: {op: Exists}
|
|
LSM: {op: InRegexp, value: ["apparmor"]}
|
|
- feature: kernel.loadedmodule
|
|
matchExpressions:
|
|
e1000e: {op: Exists}
|
|
- feature: kernel.selinux
|
|
matchExpressions:
|
|
enabled: {op: IsFalse}
|
|
- feature: kernel.version
|
|
matchExpressions:
|
|
major: {op: In, value: ["5"]}
|
|
minor: {op: Gt, value: ["10"]}
|
|
|
|
- feature: storage.block
|
|
matchExpressions:
|
|
rotational: {op: In, value: ["0"]}
|
|
dax: {op: In, value: ["0"]}
|
|
|
|
- feature: network.device
|
|
matchExpressions:
|
|
operstate: {op: In, value: ["up"]}
|
|
speed: {op: Gt, value: ["100"]}
|
|
|
|
- feature: memory.numa
|
|
matchExpressions:
|
|
node_count: {op: Gt, value: ["2"]}
|
|
- feature: memory.nv
|
|
matchExpressions:
|
|
devtype: {op: In, value: ["nd_dax"]}
|
|
mode: {op: In, value: ["memory"]}
|
|
|
|
- feature: system.osrelease
|
|
matchExpressions:
|
|
ID: {op: In, value: ["fedora", "centos"]}
|
|
- feature: system.name
|
|
matchExpressions:
|
|
nodename: {op: InRegexp, value: ["^worker-X"]}
|
|
|
|
- feature: local.label
|
|
matchExpressions:
|
|
custom-feature-knob: {op: Gt, value: ["100"]}
|
|
|
|
# matchAny implements a logical IF over all listed matchers (i.e. at
|
|
# least one must match)
|
|
matchAny:
|
|
- matchFeatures:
|
|
- feature: pci.device
|
|
matchExpressions:
|
|
vendor: {op: In, value: ["8086"]}
|
|
class: {op: In, value: ["0200"]}
|
|
- feature: usb.device
|
|
matchExpressions:
|
|
vendor: {op: In, value: ["8086"]}
|
|
class: {op: In, value: ["02"]}
|
|
|
|
# The following features demonstreate label templating capabilities
|
|
- name: "my system template feature"
|
|
labelsTemplate: |
|
|
{{ range .system.osrelease }}my-system-feature.{{ .Name }}={{ .Value }}
|
|
{{ end }}
|
|
matchFeatures:
|
|
- feature: system.osrelease
|
|
matchExpressions:
|
|
ID: {op: InRegexp, value: ["^open.*"]}
|
|
VERSION_ID.major: {op: In, value: ["13", "15"]}
|
|
|
|
- name: "my pci template feature"
|
|
labelsTemplate: |
|
|
{{ range .pci.device }}my-pci-device.{{ .class }}-{{ .device }}=with-cpuid
|
|
{{ end }}
|
|
matchFeatures:
|
|
- feature: pci.device
|
|
matchExpressions:
|
|
class: {op: InRegexp, value: ["^06"]}
|
|
vendor: {op: In, value: ["8086"]}
|
|
- feature: cpu.cpuid
|
|
matchExpressions:
|
|
AVX: {op: Exists}
|
|
|
|
# The following examples demonstrate vars field and back-referencing
|
|
# previous labels and vars
|
|
- name: "my dummy kernel rule"
|
|
labels:
|
|
"my.kernel.feature": "true"
|
|
matchFeatures:
|
|
- feature: kernel.version
|
|
matchExpressions:
|
|
major: {op: Gt, value: ["2"]}
|
|
|
|
- name: "my dummy rule with no labels"
|
|
vars:
|
|
"my.dummy.var": "1"
|
|
matchFeatures:
|
|
- feature: cpu.cpuid
|
|
matchExpressions: {}
|
|
|
|
- name: "my rule using backrefs"
|
|
labels:
|
|
"my.backref.feature": "true"
|
|
matchFeatures:
|
|
- feature: rule.matched
|
|
matchExpressions:
|
|
my.kernel.feature: {op: IsTrue}
|
|
my.dummy.var: {op: Gt, value: ["0"]}
|