1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00
node-feature-discovery/pkg
Markus Lehtonen c8d73666d6 pkg/apis/nfd: support label name templating
Support templating of label names in feature rules. It is available both
in NodeFeatureRule CRs and in custom rule configuration of nfd-worker.

This patch adds a new 'labelsTemplate' field to the rule spec, making it
possible to dynamically generate multiple labels per rule based on the
matched features. The feature relies on the golang "text/template"
package.  When expanded, the template must contain labels in a raw
<key>[=<value>] format (where 'value' defaults to "true"), separated by
newlines i.e.:

  - name: <rule-name>
    labelsTemplate: |
      <label-1>[=<value-1>]
      <label-2>[=<value-2>]
      ...

All the matched features of 'matchFeatures' directives are available for
templating engine in a nested data structure that can be described in
yaml as:

.
  <domain-1>:
      <key-feature-1>:
        - Name: <matched-key>
        - ...

      <value-feature-1:
        - Name: <matched-key>
          Value: <matched-value>
        - ...

      <instance-feature-1>:
        - <attribute-1-name>: <attribute-1-value>
          <attribute-2-name>: <attribute-2-value>
          ...
        - ...

  <domain-2>:
     ...

That is, the per-feature data available for matching depends on the type
of feature that was matched:

- "key features": only 'Name' is available
- "value features": 'Name' and 'Value' can be used
- "instance features": all attributes of the matched instance are
   available

NOTE: In case of matchAny is specified, the template is executed
separately against each individual matchFeatures matcher and the
eventual set of labels is a superset of all these expansions.  Consider
the following:

  - name: <name>
    labelsTemplate: <template>
    matchAny:
      - matchFeatures: <matcher#1>
      - matchFeatures: <matcher#2>
    matchFeatures: <matcher#3>

In the example above (assuming the overall result is a match) the
template would be executed on matcher#1 and/or matcher#2 (depending on
whether both or only one of them match), and finally on matcher#3, and
all the labels from these separate expansions would be created (i.e. the
end result would be a union of all the individual expansions).

NOTE 2: The 'labels' field has priority over 'labelsTemplate', i.e.
labels specified in the 'labels' field will override any labels
originating from the 'labelsTemplate' field.

A special case of an empty match expression set matches everything (i.e.
matches/returns all existing keys/values). This makes it simpler to
write templates that run over all values. Also, makes it possible to
later implement support for templates that run over all _keys_ of a
feature.

Some example configurations:

  - name: "my-pci-template-features"
    labelsTemplate: |
      {{ range .pci.device }}intel-{{ .class }}-{{ .device }}=present
      {{ end }}
    matchFeatures:
      - feature: pci.device
        matchExpressions:
          class: {op: InRegexp, value: ["^06"]}
          vendor: ["8086"]

  - name: "my-system-template-features"
    labelsTemplate: |
      {{ range .system.osrelease }}system-{{ .Name }}={{ .Value }}
      {{ end }}
    matchFeatures:
      - feature: system.osRelease
        matchExpressions:
          ID: {op: Exists}
          VERSION_ID.major: {op: Exists}

Imaginative template pipelines are possible, of course, but care must be
taken in order to produce understandable and maintainable rule sets.
2021-11-23 21:03:22 +02:00
..
api/feature grpc: extend the API to send raw features 2021-11-16 17:32:28 +02:00
apihelper pkg/apihelpers: split out loading of kubeconfig to a separate function 2021-11-22 16:57:42 +02:00
apis/nfd/v1alpha1 pkg/apis/nfd: support label name templating 2021-11-23 21:03:22 +02:00
cpuid pkg/cpuid: lint fixes 2020-05-20 21:48:06 +03:00
generated pkg/generated: add code for interacting with CRD API 2021-11-17 18:51:34 +02:00
kubeconf topologyupdater: Bootstrap nfd-topology-updater in NFD 2021-09-21 10:47:39 +01:00
labeler grpc: extend the API to send raw features 2021-11-16 17:32:28 +02:00
nfd-client pkg/apihelpers: split out loading of kubeconfig to a separate function 2021-11-22 16:57:42 +02:00
nfd-master nfd-master: process labeling rules from CRs 2021-11-23 09:18:07 +02:00
podres topologyupdater: Bootstrap nfd-topology-updater in NFD 2021-09-21 10:47:39 +01:00
resourcemonitor Remove fatal logging to error based on the feedback 2021-11-19 16:57:21 -05:00
topologypolicy topologyupdater: Bootstrap nfd-topology-updater in NFD 2021-09-21 10:47:39 +01:00
topologyupdater Update auto-generated code 2021-09-21 13:37:36 +03:00
utils utils: add methods to fetch NUMA nodes hugepages and memory capacity 2021-11-04 10:14:51 +02:00
version version: allow undefined version 2020-03-20 07:21:43 +02:00