@@ -47,6 +47,7 @@ import (
47
47
"sigs.k8s.io/node-feature-discovery/source/custom"
48
48
testutils "sigs.k8s.io/node-feature-discovery/test/e2e/utils"
49
49
testds "sigs.k8s.io/node-feature-discovery/test/e2e/utils/daemonset"
50
+ "sigs.k8s.io/node-feature-discovery/test/e2e/utils/namespace"
50
51
testpod "sigs.k8s.io/node-feature-discovery/test/e2e/utils/pod"
51
52
)
52
53
@@ -1011,20 +1012,7 @@ resyncPeriod: "1s"
1011
1012
Expect (targetNodeName ).ToNot (BeEmpty (), "No suitable worker node found" )
1012
1013
1013
1014
// label the namespace in which node feature object is created
1014
- // TODO(TessaIO): add a utility for this.
1015
- patches , err := json .Marshal (
1016
- []utils.JsonPatch {
1017
- utils .NewJsonPatch (
1018
- "add" ,
1019
- "/metadata/labels" ,
1020
- "e2etest" ,
1021
- "fake" ,
1022
- ),
1023
- },
1024
- )
1025
- Expect (err ).NotTo (HaveOccurred ())
1026
-
1027
- _ , err = f .ClientSet .CoreV1 ().Namespaces ().Patch (ctx , f .Namespace .Name , types .JSONPatchType , patches , metav1.PatchOptions {})
1015
+ err = namespace .PatchLabels (f .Namespace .Name , "e2etest" , "fake" , utils .JSONAddOperation , ctx , f )
1028
1016
Expect (err ).NotTo (HaveOccurred ())
1029
1017
1030
1018
// Apply Node Feature object
@@ -1044,20 +1032,9 @@ resyncPeriod: "1s"
1044
1032
eventuallyNonControlPlaneNodes (ctx , f .ClientSet ).Should (MatchLabels (expectedLabels , nodes ))
1045
1033
1046
1034
// remove label the namespace in which node feature object is created
1047
- patches , err = json .Marshal (
1048
- []utils.JsonPatch {
1049
- utils .NewJsonPatch (
1050
- "remove" ,
1051
- "/metadata/labels" ,
1052
- "e2etest" ,
1053
- "fake" ,
1054
- ),
1055
- },
1056
- )
1035
+ err = namespace .PatchLabels (f .Namespace .Name , "e2etest" , "fake" , utils .JSONRemoveOperation , ctx , f )
1057
1036
Expect (err ).NotTo (HaveOccurred ())
1058
1037
1059
- _ , err = f .ClientSet .CoreV1 ().Namespaces ().Patch (ctx , f .Namespace .Name , types .JSONPatchType , patches , metav1.PatchOptions {})
1060
- Expect (err ).NotTo (HaveOccurred ())
1061
1038
By ("Verifying node labels from NodeFeature object #1 are not created" )
1062
1039
// No labels should be created since the f.Namespace is not in the selected Namespaces
1063
1040
expectedLabels = map [string ]k8sLabels {
@@ -1207,6 +1184,19 @@ restrictions:
1207
1184
Expect (err ).NotTo (HaveOccurred ())
1208
1185
})
1209
1186
It ("No feature labels should be created" , func (ctx context.Context ) {
1187
+ // deploy worker to make sure that labels created by worker are not ignored by denyNodeFeatureLabels restriction
1188
+ By ("Creating nfd-worker daemonset" )
1189
+ podSpecOpts := []testpod.SpecOption {
1190
+ testpod .SpecWithContainerImage (dockerImage ()),
1191
+ testpod .SpecWithContainerExtraArgs ("-label-sources=fake" ),
1192
+ }
1193
+ workerDS := testds .NFDWorker (podSpecOpts ... )
1194
+ workerDS , err := f .ClientSet .AppsV1 ().DaemonSets (f .Namespace .Name ).Create (ctx , workerDS , metav1.CreateOptions {})
1195
+ Expect (err ).NotTo (HaveOccurred ())
1196
+
1197
+ By ("Waiting for worker daemonset pods to be ready" )
1198
+ Expect (testpod .WaitForReady (ctx , f .ClientSet , f .Namespace .Name , workerDS .Spec .Template .Labels ["name" ], 2 )).NotTo (HaveOccurred ())
1199
+
1210
1200
// deploy node feature object
1211
1201
nodes , err := getNonControlPlaneNodes (ctx , f .ClientSet )
1212
1202
Expect (err ).NotTo (HaveOccurred ())
@@ -1234,7 +1224,7 @@ restrictions:
1234
1224
"e2e.feature.node.kubernetes.io/restricted-annoation-1" : "yes" ,
1235
1225
"nfd.node.kubernetes.io/feature-annotations" : "e2e.feature.node.kubernetes.io/restricted-annoation-1" ,
1236
1226
"nfd.node.kubernetes.io/extended-resources" : "e2e.feature.node.kubernetes.io/restricted-er-1" ,
1237
- "nfd.node.kubernetes.io/feature-labels" : "e2e.feature.node.kubernetes.io/restricted-label-1" ,
1227
+ "nfd.node.kubernetes.io/feature-labels" : "e2e.feature.node.kubernetes.io/restricted-label-1,fake-fakefeature1,fake-fakefeature2,fake-fakefeature3 " ,
1238
1228
},
1239
1229
}
1240
1230
eventuallyNonControlPlaneNodes (ctx , f .ClientSet ).Should (MatchAnnotations (expectedAnnotations , nodes ))
@@ -1246,11 +1236,12 @@ restrictions:
1246
1236
}
1247
1237
eventuallyNonControlPlaneNodes (ctx , f .ClientSet ).WithTimeout (1 * time .Minute ).Should (MatchCapacity (expectedCapacity , nodes ))
1248
1238
1249
- // TODO(TessaIO): we need one more test where we deploy nfd-worker that would create
1250
- // a non 3rd-party NF that shouldn't be ignored by this restriction
1251
1239
By ("Verifying node labels from NodeFeature object #6 are not created" )
1252
1240
expectedLabels := map [string ]k8sLabels {
1253
1241
"*" : {
1242
+ nfdv1alpha1 .FeatureLabelNs + "/fake-fakefeature1" : "true" ,
1243
+ nfdv1alpha1 .FeatureLabelNs + "/fake-fakefeature2" : "true" ,
1244
+ nfdv1alpha1 .FeatureLabelNs + "/fake-fakefeature3" : "true" ,
1254
1245
"e2e.feature.node.kubernetes.io/restricted-label-1" : "true" ,
1255
1246
},
1256
1247
}
0 commit comments