mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-15 17:50:49 +00:00
Refactor AddLabels() to add namespace
Makes sure all NFD labels are in the same namespace.
This commit is contained in:
parent
9e4aade6b8
commit
81752b2df1
2 changed files with 13 additions and 13 deletions
8
main.go
8
main.go
|
@ -46,7 +46,7 @@ const (
|
|||
|
||||
var (
|
||||
version = "" // Must not be const, set using ldflags at build time
|
||||
labelPrefix = labelNs + "nfd"
|
||||
labelPrefix = labelNs + "nfd-"
|
||||
)
|
||||
|
||||
// package loggers
|
||||
|
@ -83,7 +83,7 @@ type APIHelpers interface {
|
|||
// subsequently be updated via the API server using the client library.
|
||||
RemoveLabels(*api.Node, string)
|
||||
|
||||
// AddLabels modifies the supplied node's labels collection.
|
||||
// AddLabels adds new NFD labels to the node object.
|
||||
// In order to publish the labels, the node must be subsequently updated via the
|
||||
// API server using the client library.
|
||||
AddLabels(*api.Node, Labels)
|
||||
|
@ -342,7 +342,7 @@ func getFeatureLabels(source source.FeatureSource) (labels Labels, err error) {
|
|||
return nil, err
|
||||
}
|
||||
for k := range features {
|
||||
labels[fmt.Sprintf("%s-%s-%s", labelPrefix, source.Name(), k)] = fmt.Sprintf("%v", features[k])
|
||||
labels[fmt.Sprintf("%s-%s", source.Name(), k)] = fmt.Sprintf("%v", features[k])
|
||||
}
|
||||
return labels, nil
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ func (h k8sHelpers) RemoveLabels(n *api.Node, search string) {
|
|||
|
||||
func (h k8sHelpers) AddLabels(n *api.Node, labels Labels) {
|
||||
for k, v := range labels {
|
||||
n.Labels[k] = v
|
||||
n.Labels[labelPrefix+k] = v
|
||||
}
|
||||
}
|
||||
|
||||
|
|
18
main_test.go
18
main_test.go
|
@ -28,7 +28,7 @@ func TestDiscoveryWithMockSources(t *testing.T) {
|
|||
fakeAnnotations := Annotations{"version": version}
|
||||
for _, f := range fakeFeatureNames {
|
||||
fakeFeatures[f] = true
|
||||
fakeFeatureLabels[fmt.Sprintf("%s-testSource-%s", labelPrefix, f)] = "true"
|
||||
fakeFeatureLabels[fmt.Sprintf("testSource-%s", f)] = "true"
|
||||
}
|
||||
fakeFeatureSource := source.FeatureSource(mockFeatureSource)
|
||||
|
||||
|
@ -289,9 +289,9 @@ func TestCreateFeatureLabels(t *testing.T) {
|
|||
|
||||
Convey("Proper fake labels are returned", func() {
|
||||
So(len(labels), ShouldEqual, 3)
|
||||
So(labels, ShouldContainKey, labelPrefix+"-fake-fakefeature1")
|
||||
So(labels, ShouldContainKey, labelPrefix+"-fake-fakefeature2")
|
||||
So(labels, ShouldContainKey, labelPrefix+"-fake-fakefeature3")
|
||||
So(labels, ShouldContainKey, "fake-fakefeature1")
|
||||
So(labels, ShouldContainKey, "fake-fakefeature2")
|
||||
So(labels, ShouldContainKey, "fake-fakefeature3")
|
||||
})
|
||||
})
|
||||
Convey("When fake feature source is configured with a whitelist that doesn't match", func() {
|
||||
|
@ -303,9 +303,9 @@ func TestCreateFeatureLabels(t *testing.T) {
|
|||
|
||||
Convey("fake labels are not returned", func() {
|
||||
So(len(labels), ShouldEqual, 0)
|
||||
So(labels, ShouldNotContainKey, labelPrefix+"-fake-fakefeature1")
|
||||
So(labels, ShouldNotContainKey, labelPrefix+"-fake-fakefeature2")
|
||||
So(labels, ShouldNotContainKey, labelPrefix+"-fake-fakefeature3")
|
||||
So(labels, ShouldNotContainKey, "fake-fakefeature1")
|
||||
So(labels, ShouldNotContainKey, "fake-fakefeature2")
|
||||
So(labels, ShouldNotContainKey, "fake-fakefeature3")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -330,10 +330,10 @@ func TestAddLabels(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("They should be added to the node.Labels", func() {
|
||||
test1 := labelPrefix + ".test1"
|
||||
test1 := "test1"
|
||||
labels[test1] = "true"
|
||||
helper.AddLabels(n, labels)
|
||||
So(n.Labels, ShouldContainKey, test1)
|
||||
So(n.Labels, ShouldContainKey, labelPrefix+test1)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue