@@ -226,12 +226,9 @@ var _ = Describe("SriovOperatorConfig controller", Ordered, func() {
226226
227227 It ("should be able to update the node selector of sriov-network-config-daemon" , func () {
228228 By ("specify the configDaemonNodeSelector" )
229- config := & sriovnetworkv1.SriovOperatorConfig {}
230- Expect (k8sClient .Get (ctx , types.NamespacedName {Namespace : testNamespace , Name : "default" }, config )).NotTo (HaveOccurred ())
231-
232- config .Spec .ConfigDaemonNodeSelector = map [string ]string {"node-role.kubernetes.io/worker" : "" }
233- err := k8sClient .Update (ctx , config )
234- Expect (err ).NotTo (HaveOccurred ())
229+ nodeSelector := map [string ]string {"node-role.kubernetes.io/worker" : "" }
230+ restore := updateConfigDaemonNodeSelector (nodeSelector )
231+ DeferCleanup (restore )
235232
236233 daemonSet := & appsv1.DaemonSet {}
237234 Eventually (func () map [string ]string {
@@ -241,28 +238,26 @@ var _ = Describe("SriovOperatorConfig controller", Ordered, func() {
241238 return nil
242239 }
243240 return daemonSet .Spec .Template .Spec .NodeSelector
244- }, util .APITimeout , util .RetryInterval ).Should (Equal (config . Spec . ConfigDaemonNodeSelector ))
241+ }, util .APITimeout , util .RetryInterval ).Should (Equal (nodeSelector ))
245242 })
246243
247244 It ("should be able to do multiple updates to the node selector of sriov-network-config-daemon" , func () {
248245 By ("changing the configDaemonNodeSelector" )
249- config := & sriovnetworkv1.SriovOperatorConfig {}
250- Expect (k8sClient .Get (ctx , types.NamespacedName {Namespace : testNamespace , Name : "default" }, config )).NotTo (HaveOccurred ())
251- config .Spec .ConfigDaemonNodeSelector = map [string ]string {"labelA" : "" , "labelB" : "" , "labelC" : "" }
252- err := k8sClient .Update (ctx , config )
253- Expect (err ).NotTo (HaveOccurred ())
254- config .Spec .ConfigDaemonNodeSelector = map [string ]string {"labelA" : "" , "labelB" : "" }
255- err = k8sClient .Update (ctx , config )
256- Expect (err ).NotTo (HaveOccurred ())
246+ firstNodeSelector := map [string ]string {"labelA" : "" , "labelB" : "" , "labelC" : "" }
247+ restore := updateConfigDaemonNodeSelector (firstNodeSelector )
248+ DeferCleanup (restore )
257249
250+ secondNodeSelector := map [string ]string {"labelA" : "" , "labelB" : "" }
251+ updateConfigDaemonNodeSelector (secondNodeSelector )
252+
258253 daemonSet := & appsv1.DaemonSet {}
259254 Eventually (func () map [string ]string {
260255 err := k8sClient .Get (ctx , types.NamespacedName {Name : "sriov-network-config-daemon" , Namespace : testNamespace }, daemonSet )
261256 if err != nil {
262257 return nil
263258 }
264259 return daemonSet .Spec .Template .Spec .NodeSelector
265- }, util .APITimeout , util .RetryInterval ).Should (Equal (config . Spec . ConfigDaemonNodeSelector ))
260+ }, util .APITimeout , util .RetryInterval ).Should (Equal (secondNodeSelector ))
266261 })
267262
268263 It ("should not render disable-plugins cmdline flag of sriov-network-config-daemon if disablePlugin not provided in spec" , func () {
@@ -365,6 +360,23 @@ var _ = Describe("SriovOperatorConfig controller", Ordered, func() {
365360 Expect (err ).ToNot (HaveOccurred ())
366361 })
367362
363+ It ("should deploy the sriov-network-metrics-exporter using the Spec.ConfigDaemonNodeSelector field" , func () {
364+ nodeSelector := map [string ]string {
365+ "node-role.kubernetes.io/worker" : "" ,
366+ "bool-key" : "true" ,
367+ }
368+
369+ restore := updateConfigDaemonNodeSelector (nodeSelector )
370+ DeferCleanup (restore )
371+
372+ Eventually (func (g Gomega ) {
373+ metricsDaemonset := appsv1.DaemonSet {}
374+ err := util .WaitForNamespacedObject (& metricsDaemonset , k8sClient , testNamespace , "sriov-network-metrics-exporter" , util .RetryInterval , util .APITimeout )
375+ g .Expect (err ).NotTo (HaveOccurred ())
376+ g .Expect (metricsDaemonset .Spec .Template .Spec .NodeSelector ).To ((Equal (nodeSelector )))
377+ }).Should (Succeed ())
378+ })
379+
368380 It ("should deploy extra configuration when the Prometheus operator is installed" , func () {
369381 DeferCleanup (os .Setenv , "METRICS_EXPORTER_PROMETHEUS_OPERATOR_ENABLED" , os .Getenv ("METRICS_EXPORTER_PROMETHEUS_OPERATOR_ENABLED" ))
370382 os .Setenv ("METRICS_EXPORTER_PROMETHEUS_OPERATOR_ENABLED" , "true" )
@@ -501,3 +513,20 @@ func assertResourceExists(gvk schema.GroupVersionKind, key client.ObjectKey) {
501513 err := k8sClient .Get (context .Background (), key , u )
502514 Expect (err ).NotTo (HaveOccurred ())
503515}
516+
517+ func updateConfigDaemonNodeSelector (newValue map [string ]string ) func () {
518+ config := & sriovnetworkv1.SriovOperatorConfig {}
519+ err := k8sClient .Get (context .Background (), types.NamespacedName {Namespace : testNamespace , Name : "default" }, config )
520+ Expect (err ).NotTo (HaveOccurred ())
521+
522+ previousValue := config .Spec .ConfigDaemonNodeSelector
523+ ret := func () {
524+ updateConfigDaemonNodeSelector (previousValue )
525+ }
526+
527+ config .Spec .ConfigDaemonNodeSelector = newValue
528+ err = k8sClient .Update (context .Background (), config )
529+ Expect (err ).NotTo (HaveOccurred ())
530+
531+ return ret
532+ }
0 commit comments