@@ -32,6 +32,8 @@ import (
3232 "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/fakefilesystem"
3333)
3434
35+ var SriovDevicePluginPod corev1.Pod
36+
3537func TestConfigDaemon (t * testing.T ) {
3638 RegisterFailHandler (Fail )
3739 RunSpecs (t , "Config Daemon Suite" )
@@ -107,19 +109,6 @@ var _ = Describe("Config Daemon", func() {
107109 },
108110 }
109111
110- SriovDevicePluginPod := corev1.Pod {
111- ObjectMeta : metav1.ObjectMeta {
112- Name : "sriov-device-plugin-xxxx" ,
113- Namespace : vars .Namespace ,
114- Labels : map [string ]string {
115- "app" : "sriov-device-plugin" ,
116- },
117- },
118- Spec : corev1.PodSpec {
119- NodeName : "test-node" ,
120- },
121- }
122-
123112 err = sriovnetworkv1 .AddToScheme (scheme .Scheme )
124113 Expect (err ).ToNot (HaveOccurred ())
125114 kClient := kclient .NewClientBuilder ().WithScheme (scheme .Scheme ).WithRuntimeObjects (& corev1.Node {
@@ -130,7 +119,7 @@ var _ = Describe("Config Daemon", func() {
130119 Namespace : vars .Namespace ,
131120 }}).Build ()
132121
133- kubeClient := fakek8s .NewSimpleClientset (& FakeSupportedNicIDs , & SriovDevicePluginPod )
122+ kubeClient := fakek8s .NewSimpleClientset (& FakeSupportedNicIDs )
134123 snclient := snclientset .NewSimpleClientset ()
135124 err = sriovnetworkv1 .InitNicIDMapFromConfigMap (kubeClient , vars .Namespace )
136125 Expect (err ).ToNot (HaveOccurred ())
@@ -175,6 +164,22 @@ var _ = Describe("Config Daemon", func() {
175164 err := sut .Run (stopCh , exitCh )
176165 Expect (err ).ToNot (HaveOccurred ())
177166 }()
167+
168+ SriovDevicePluginPod = corev1.Pod {
169+ ObjectMeta : metav1.ObjectMeta {
170+ Name : "sriov-device-plugin-xxxx" ,
171+ Namespace : vars .Namespace ,
172+ Labels : map [string ]string {
173+ "app" : "sriov-device-plugin" ,
174+ },
175+ },
176+ Spec : corev1.PodSpec {
177+ NodeName : "test-node" ,
178+ },
179+ }
180+ _ , err = sut .kubeClient .CoreV1 ().Pods (vars .Namespace ).Create (context .Background (), & SriovDevicePluginPod , metav1.CreateOptions {})
181+ Expect (err ).ToNot (HaveOccurred ())
182+
178183 })
179184
180185 AfterEach (func () {
@@ -286,6 +291,34 @@ var _ = Describe("Config Daemon", func() {
286291
287292 Expect (sut .desiredNodeState .GetGeneration ()).To (BeNumerically ("==" , 777 ))
288293 })
294+
295+ It ("restart all the sriov-device-plugin pods present on the node" , func () {
296+ otherPod1 := SriovDevicePluginPod .DeepCopy ()
297+ otherPod1 .Name = "sriov-device-plugin-xxxa"
298+ _ , err := sut .kubeClient .CoreV1 ().Pods (vars .Namespace ).Create (context .Background (), otherPod1 , metav1.CreateOptions {})
299+ Expect (err ).ToNot (HaveOccurred ())
300+
301+ otherPod2 := SriovDevicePluginPod .DeepCopy ()
302+ otherPod2 .Name = "sriov-device-plugin-xxxz"
303+ _ , err = sut .kubeClient .CoreV1 ().Pods (vars .Namespace ).Create (context .Background (), otherPod2 , metav1.CreateOptions {})
304+ Expect (err ).ToNot (HaveOccurred ())
305+
306+ err = sut .restartDevicePluginPod ()
307+ Expect (err ).ToNot (HaveOccurred ())
308+
309+ Eventually (func () (int , error ) {
310+ podList , err := sut .kubeClient .CoreV1 ().Pods (vars .Namespace ).List (context .Background (), metav1.ListOptions {
311+ LabelSelector : "app=sriov-device-plugin" ,
312+ FieldSelector : "spec.nodeName=test-node" ,
313+ })
314+
315+ if err != nil {
316+ return 0 , err
317+ }
318+
319+ return len (podList .Items ), nil
320+ }, "1s" ).Should (BeZero ())
321+ })
289322 })
290323})
291324
0 commit comments