Skip to content

Commit

Permalink
Merge pull request #1671 from marquiz/devel/nfd-api-multi-type-feature
Browse files Browse the repository at this point in the history
apis/nfd: allow different types of features of the same name
  • Loading branch information
k8s-ci-robot committed May 24, 2024
2 parents 5fe3433 + bb565c0 commit 814255b
Show file tree
Hide file tree
Showing 8 changed files with 700 additions and 88 deletions.
15 changes: 0 additions & 15 deletions api/nfd/v1alpha1/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,6 @@ func (f *Features) InsertAttributeFeatures(domain, feature string, values map[st
maps.Copy(f.Attributes[key].Elements, values)
}

// Exists returns a non-empty string if a feature exists. The return value is
// the type of the feautre, i.e. "flag", "attribute" or "instance".
func (f *Features) Exists(name string) string {
if _, ok := f.Flags[name]; ok {
return "flag"
}
if _, ok := f.Attributes[name]; ok {
return "attribute"
}
if _, ok := f.Instances[name]; ok {
return "instance"
}
return ""
}

// MergeInto merges two FeatureSpecs into one. Data in the input object takes
// precedence (overwrite) over data of the existing object we're merging into.
func (in *NodeFeatureSpec) MergeInto(out *NodeFeatureSpec) {
Expand Down
5 changes: 1 addition & 4 deletions api/nfd/v1alpha1/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,9 @@ func TestInstanceFeatureSet(t *testing.T) {
func TestFeature(t *testing.T) {
f := Features{}

// Test Exists() and InsertAttributeFeatures()
assert.Empty(t, f.Exists("dom.attr"), "empty features shouldn't contain anything")

// Test InsertAttributeFeatures()
f.InsertAttributeFeatures("dom", "attr", map[string]string{"k1": "v1", "k2": "v2"})
expectedAttributes := map[string]string{"k1": "v1", "k2": "v2"}
assert.Equal(t, "attribute", f.Exists("dom.attr"), "attribute feature should exist")
assert.Equal(t, expectedAttributes, f.Attributes["dom.attr"].Elements)

f.InsertAttributeFeatures("dom", "attr", map[string]string{"k2": "v2.override", "k3": "v3"})
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/customization-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ NodeFeature object as NFD uses it to determine the node which it is targeting.

### Feature types

Features are divided into three different types:
Features have three different types:

- **flag** features: a set of names without any associated values, e.g. CPUID
flags or loaded kernel modules
Expand Down Expand Up @@ -955,7 +955,7 @@ true).

The following features are available for matching:

| Feature | [Feature type](#feature-types) | Elements | Value type | Description |
| Feature | [Feature types](#feature-types) | Elements | Value type | Description |
| ---------------- | ------------ | -------- | ---------- | ----------- |
| **`cpu.cpuid`** | flag | | | Supported CPU capabilities |
| | | **`<cpuid-flag>`** | | CPUID flag is present |
Expand Down
Loading

0 comments on commit 814255b

Please sign in to comment.