1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-15 04:57:56 +00:00

nfd-master: export label and annotation prefixes

In order to be able to use the constants in end-to-end tests.
This commit is contained in:
Markus Lehtonen 2020-02-26 10:08:21 +02:00
parent 208e1bc99e
commit 54eaf16871
3 changed files with 24 additions and 23 deletions

View file

@ -63,8 +63,8 @@ func TestUpdateNodeFeatures(t *testing.T) {
mockClient := &k8sclient.Clientset{}
// Mock node with old features
mockNode := newMockNode()
mockNode.Labels[labelNs+"old-feature"] = "old-value"
mockNode.Annotations[annotationNs+"feature-labels"] = "old-feature"
mockNode.Labels[LabelNs+"old-feature"] = "old-value"
mockNode.Annotations[AnnotationNs+"feature-labels"] = "old-feature"
Convey("When I successfully update the node with feature labels", func() {
mockAPIHelper.On("GetClient").Return(mockClient, nil)
@ -78,11 +78,11 @@ func TestUpdateNodeFeatures(t *testing.T) {
Convey("Node object should have updated with labels and annotations", func() {
So(len(mockNode.Labels), ShouldEqual, len(fakeFeatureLabels))
for k, v := range fakeFeatureLabels {
So(mockNode.Labels[labelNs+k], ShouldEqual, v)
So(mockNode.Labels[LabelNs+k], ShouldEqual, v)
}
So(len(mockNode.Annotations), ShouldEqual, len(fakeAnnotations))
for k, v := range fakeAnnotations {
So(mockNode.Annotations[annotationNs+k], ShouldEqual, v)
So(mockNode.Annotations[AnnotationNs+k], ShouldEqual, v)
}
})
})
@ -209,11 +209,11 @@ func TestSetLabels(t *testing.T) {
Convey("Node object should have updated with labels and annotations", func() {
So(len(mockNode.Labels), ShouldEqual, len(mockLabels))
for k, v := range mockLabels {
So(mockNode.Labels[labelNs+k], ShouldEqual, v)
So(mockNode.Labels[LabelNs+k], ShouldEqual, v)
}
So(len(mockNode.Annotations), ShouldEqual, len(expectedAnnotations))
for k, v := range expectedAnnotations {
So(mockNode.Annotations[annotationNs+k], ShouldEqual, v)
So(mockNode.Annotations[AnnotationNs+k], ShouldEqual, v)
}
})
})
@ -229,9 +229,9 @@ func TestSetLabels(t *testing.T) {
})
Convey("Node object should only have whitelisted labels", func() {
So(len(mockNode.Labels), ShouldEqual, 1)
So(mockNode.Labels, ShouldResemble, map[string]string{labelNs + "feature-2": "val-2"})
So(mockNode.Labels, ShouldResemble, map[string]string{LabelNs + "feature-2": "val-2"})
a := map[string]string{annotationNs + "worker.version": workerVer, annotationNs + "feature-labels": "feature-2"}
a := map[string]string{AnnotationNs + "worker.version": workerVer, AnnotationNs + "feature-labels": "feature-2"}
So(len(mockNode.Annotations), ShouldEqual, len(a))
So(mockNode.Annotations, ShouldResemble, a)
})
@ -252,9 +252,9 @@ func TestSetLabels(t *testing.T) {
})
Convey("Node object should only have allowed label namespaces", func() {
So(len(mockNode.Labels), ShouldEqual, 2)
So(mockNode.Labels, ShouldResemble, map[string]string{labelNs + "feature-1": "val-1", "valid.ns/feature-2": "val-2"})
So(mockNode.Labels, ShouldResemble, map[string]string{LabelNs + "feature-1": "val-1", "valid.ns/feature-2": "val-2"})
a := map[string]string{annotationNs + "worker.version": workerVer, annotationNs + "feature-labels": "feature-1,valid.ns/feature-2"}
a := map[string]string{AnnotationNs + "worker.version": workerVer, AnnotationNs + "feature-labels": "feature-1,valid.ns/feature-2"}
So(len(mockNode.Annotations), ShouldEqual, len(a))
So(mockNode.Annotations, ShouldResemble, a)
})
@ -300,7 +300,7 @@ func TestAddLabels(t *testing.T) {
test1 := "test1"
labels[test1] = "true"
addLabels(n, labels)
So(n.Labels, ShouldContainKey, labelNs+test1)
So(n.Labels, ShouldContainKey, LabelNs+test1)
})
})
}

View file

@ -41,10 +41,10 @@ import (
const (
// Namespace for feature labels
labelNs = "feature.node.kubernetes.io/"
LabelNs = "feature.node.kubernetes.io/"
// Namespace for all NFD-related annotations
annotationNs = "nfd.node.kubernetes.io/"
AnnotationNs = "nfd.node.kubernetes.io/"
)
// package loggers
@ -301,7 +301,7 @@ func updateNodeFeatures(helper apihelper.APIHelpers, nodeName string, labels Lab
}
// Remove old labels
if l, ok := node.Annotations[annotationNs+"feature-labels"]; ok {
if l, ok := node.Annotations[AnnotationNs+"feature-labels"]; ok {
oldLabels := strings.Split(l, ",")
removeLabels(node, oldLabels)
}
@ -341,7 +341,7 @@ func removeLabels(n *api.Node, labelNames []string) {
if strings.Contains(l, "/") {
delete(n.Labels, l)
} else {
delete(n.Labels, labelNs+l)
delete(n.Labels, LabelNs+l)
}
}
}
@ -352,7 +352,7 @@ func addLabels(n *api.Node, labels map[string]string) {
if strings.Contains(k, "/") {
n.Labels[k] = v
} else {
n.Labels[labelNs+k] = v
n.Labels[LabelNs+k] = v
}
}
}
@ -360,6 +360,6 @@ func addLabels(n *api.Node, labels map[string]string) {
// Add Annotations to a Node object
func addAnnotations(n *api.Node, annotations map[string]string) {
for k, v := range annotations {
n.Annotations[annotationNs+k] = v
n.Annotations[AnnotationNs+k] = v
}
}

View file

@ -31,12 +31,13 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
master "sigs.k8s.io/node-feature-discovery/pkg/nfd-master"
)
var (
dockerRepo = flag.String("nfd.repo", "quay.io/kubernetes_incubator/node-feature-discovery", "Docker repository to fetch image from")
dockerTag = flag.String("nfd.tag", "e2e-test", "Docker tag to use")
labelPrefix = "feature.node.kubernetes.io/"
)
// Create required RBAC configuration
@ -239,9 +240,9 @@ var _ = framework.KubeDescribe("Node Feature Discovery", func() {
ns := f.Namespace.Name
image := fmt.Sprintf("%s:%s", *dockerRepo, *dockerTag)
fakeFeatureLabels := map[string]string{
labelPrefix + "fake-fakefeature1": "true",
labelPrefix + "fake-fakefeature2": "true",
labelPrefix + "fake-fakefeature3": "true",
master.LabelNs + "fake-fakefeature1": "true",
master.LabelNs + "fake-fakefeature2": "true",
master.LabelNs + "fake-fakefeature3": "true",
}
defer deconfigureRBAC(f.ClientSet, f.Namespace.Name)