1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-05 16:27:05 +00:00
node-feature-discovery/deployment/base/nfd-crds/cr-sample.yaml
Markus Lehtonen fe412a54b9 apis/nfd: add matchName field in feature matcher terms
Extend the format of feature matcher terms (the elements of the
arrayspecified under under matchFeatures field) with new matchName
field. The value of this field is an expression that is evaluated
against the names of feature elements instead of their values (values
are matched with the matchExpressions field, instead).

The matchName field is useful e.g. in template rules for creating
per-feature-element labels based on feature names (instead of values)
and in non-template rules for checking if (at least) one of certain
feature element names are present.

If both matchExpressions and matchName for certain feature matcher term
is specified, they both must match in order to get an overall match.
Also, in this case the list of matched features (used in templating) is
the union of the results from matchExpressions and matchName.

An example of creating an "avx512" label if any AVX512* CPUID feature is
present:

  - name: "avx wildcard rule"
    labels:
        avx512: "true"
    matchFeatures:
      - feature: cpu.cpuid
        matchName: {op: InRegexp, value: ["^AVX512"]}

An example of a template rule creating a dynamic set of labels  based on
the existence of certain kconfig options.

  - name: "kconfig template rule"
    labelsTemplate: |
      {{ range .kernel.config }}kconfig-{{ .Name }}={{ .Value }}
      {{ end }}
    matchFeatures:
      - feature: kernel.config
        matchName: {op: In, value: ["SWAP", "X86", "ARM"]}

NOTE: this patch changes the corner case of nil/null match expressions
with instance features (i.e. "matchExpressions: null"). Previously, we
returned all instances for templating but now a nil match expression is
not evaluated and no instances for templating are returned.
2023-12-15 11:32:23 +02:00

160 lines
5 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"
taints:
- effect: PreferNoSchedule
key: "feature.node.kubernetes.io/special-node"
value: "true"
- effect: NoExecute
key: "feature.node.kubernetes.io/dedicated-node"
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"]}
- name: "avx wildcard rule"
labels:
"my-avx-feature": "true"
matchFeatures:
- feature: cpu.cpuid
matchName: {op: InRegexp, value: ["^AVX512"]}
# 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"]}
- name: "kconfig template rule"
labelsTemplate: |
{{ range .kernel.config }}kconfig-{{ .Name }}={{ .Value }}
{{ end }}
matchFeatures:
- feature: kernel.config
matchName: {op: In, value: ["SWAP", "X86", "ARM"]}