44 "context"
55 "os"
66 "sync"
7+ "sync/atomic"
78 "time"
89
910 . "github.com/onsi/ginkgo/v2"
4243 mockCtrl * gomock.Controller
4344 hostHelper * mock_helper.MockHostHelpersInterface
4445 platformHelper * mock_platforms.MockInterface
46+
47+ discoverSriovReturn atomic.Pointer [[]sriovnetworkv1.InterfaceExt ]
48+ nodeState * sriovnetworkv1.SriovNetworkNodeState
49+
50+ daemonReconciler * daemon.NodeReconciler
4551)
4652
4753const (
@@ -94,9 +100,8 @@ var _ = Describe("Daemon Controller", Ordered, func() {
94100 } else {
95101 vars .ClusterType = constants .ClusterTypeKubernetes
96102 }
97- })
98103
99- BeforeEach ( func () {
104+ By ( "Init mock functions" )
100105 t = GinkgoT ()
101106 mockCtrl = gomock .NewController (t )
102107 hostHelper = mock_helper .NewMockHostHelpersInterface (mockCtrl )
@@ -115,90 +120,71 @@ var _ = Describe("Daemon Controller", Ordered, func() {
115120 hostHelper .EXPECT ().Chroot (gomock .Any ()).Return (func () error { return nil }, nil ).AnyTimes ()
116121 hostHelper .EXPECT ().RunCommand ("/bin/sh" , gomock .Any (), gomock .Any (), gomock .Any ()).Return ("" , "" , nil ).AnyTimes ()
117122
123+ discoverSriovReturn .Store (& []sriovnetworkv1.InterfaceExt {})
124+
125+ hostHelper .EXPECT ().DiscoverSriovDevices (hostHelper ).DoAndReturn (func (helpersInterface helper.HostHelpersInterface ) ([]sriovnetworkv1.InterfaceExt , error ) {
126+ return * discoverSriovReturn .Load (), nil
127+ }).AnyTimes ()
128+
129+ hostHelper .EXPECT ().LoadPfsStatus ("0000:16:00.0" ).Return (& sriovnetworkv1.Interface {ExternallyManaged : false }, true , nil ).AnyTimes ()
130+
131+ hostHelper .EXPECT ().ClearPCIAddressFolder ().Return (nil ).AnyTimes ()
132+ hostHelper .EXPECT ().DiscoverRDMASubsystem ().Return ("shared" , nil ).AnyTimes ()
133+ hostHelper .EXPECT ().GetCurrentKernelArgs ().Return ("" , nil ).AnyTimes ()
134+ hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgPciRealloc ).Return (true ).AnyTimes ()
135+ hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgIntelIommu ).Return (true ).AnyTimes ()
136+ hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgIommuPt ).Return (true ).AnyTimes ()
137+ hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgRdmaExclusive ).Return (false ).AnyTimes ()
138+ hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgRdmaShared ).Return (false ).AnyTimes ()
139+ hostHelper .EXPECT ().SetRDMASubsystem ("" ).Return (nil ).AnyTimes ()
140+
141+ hostHelper .EXPECT ().ConfigSriovInterfaces (gomock .Any (), gomock .Any (), gomock .Any (), false ).Return (nil ).AnyTimes ()
142+
143+ // k8s plugin for k8s cluster type
144+ if vars .ClusterType == constants .ClusterTypeKubernetes {
145+ hostHelper .EXPECT ().ReadServiceManifestFile (gomock .Any ()).Return (& hostTypes.Service {Name : "test" }, nil ).AnyTimes ()
146+ hostHelper .EXPECT ().ReadServiceInjectionManifestFile (gomock .Any ()).Return (& hostTypes.Service {Name : "test" }, nil ).AnyTimes ()
147+ }
148+
149+ featureGates := featuregate .New ()
150+ featureGates .Init (map [string ]bool {})
151+ daemonReconciler = createDaemon (hostHelper , platformHelper , featureGates , []string {})
152+ startDaemon (daemonReconciler )
153+
154+ _ , nodeState = createNode ("node1" )
118155 })
119156
120- AfterEach (func () {
157+ AfterAll (func () {
121158 Expect (k8sClient .DeleteAllOf (context .Background (), & corev1.Node {})).ToNot (HaveOccurred ())
122159
123160 Expect (k8sClient .DeleteAllOf (context .Background (), & sriovnetworkv1.SriovNetworkNodeState {}, client .InNamespace (testNamespace ))).ToNot (HaveOccurred ())
124161 Expect (k8sClient .DeleteAllOf (context .Background (), & sriovnetworkv1.SriovOperatorConfig {}, client .InNamespace (testNamespace ))).ToNot (HaveOccurred ())
125162 })
126163
127164 Context ("Config Daemon generic flow" , func () {
128- BeforeEach (func () {
129- // k8s plugin for k8s cluster type
130- if vars .ClusterType == constants .ClusterTypeKubernetes {
131- hostHelper .EXPECT ().ReadServiceManifestFile (gomock .Any ()).Return (& hostTypes.Service {Name : "test" }, nil ).AnyTimes ()
132- hostHelper .EXPECT ().ReadServiceInjectionManifestFile (gomock .Any ()).Return (& hostTypes.Service {Name : "test" }, nil ).AnyTimes ()
133- }
134- })
135165
136166 It ("Should expose nodeState Status section" , func (ctx context.Context ) {
137- By ("Init mock functions" )
138- afterConfig := false
139- hostHelper .EXPECT ().DiscoverSriovDevices (hostHelper ).DoAndReturn (func (helpersInterface helper.HostHelpersInterface ) ([]sriovnetworkv1.InterfaceExt , error ) {
140- interfaceExtList := []sriovnetworkv1.InterfaceExt {
141- {
142- Name : "eno1" ,
143- Driver : "ice" ,
144- PciAddress : "0000:16:00.0" ,
145- DeviceID : "1593" ,
146- Vendor : "8086" ,
147- EswitchMode : "legacy" ,
148- LinkAdminState : "up" ,
149- LinkSpeed : "10000 Mb/s" ,
150- LinkType : "ETH" ,
151- Mac : "aa:bb:cc:dd:ee:ff" ,
152- Mtu : 1500 ,
153- TotalVfs : 2 ,
154- NumVfs : 0 ,
155- },
156- }
157-
158- if afterConfig {
159- interfaceExtList [0 ].NumVfs = 2
160- interfaceExtList [0 ].VFs = []sriovnetworkv1.VirtualFunction {
161- {
162- Name : "eno1f0" ,
163- PciAddress : "0000:16:00.1" ,
164- VfID : 0 ,
165- },
166- {
167- Name : "eno1f1" ,
168- PciAddress : "0000:16:00.2" ,
169- VfID : 1 ,
170- }}
171- }
172- return interfaceExtList , nil
173- }).AnyTimes ()
174-
175- hostHelper .EXPECT ().LoadPfsStatus ("0000:16:00.0" ).Return (& sriovnetworkv1.Interface {ExternallyManaged : false }, true , nil ).AnyTimes ()
176-
177- hostHelper .EXPECT ().ClearPCIAddressFolder ().Return (nil ).AnyTimes ()
178- hostHelper .EXPECT ().DiscoverRDMASubsystem ().Return ("shared" , nil ).AnyTimes ()
179- hostHelper .EXPECT ().GetCurrentKernelArgs ().Return ("" , nil ).AnyTimes ()
180- hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgPciRealloc ).Return (true ).AnyTimes ()
181- hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgIntelIommu ).Return (true ).AnyTimes ()
182- hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgIommuPt ).Return (true ).AnyTimes ()
183- hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgRdmaExclusive ).Return (false ).AnyTimes ()
184- hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgRdmaShared ).Return (false ).AnyTimes ()
185- hostHelper .EXPECT ().SetRDMASubsystem ("" ).Return (nil ).AnyTimes ()
186-
187- hostHelper .EXPECT ().ConfigSriovInterfaces (gomock .Any (), gomock .Any (), gomock .Any (), false ).Return (nil ).AnyTimes ()
188-
189- featureGates := featuregate .New ()
190- featureGates .Init (map [string ]bool {})
191- dc := createDaemon (hostHelper , platformHelper , featureGates , []string {})
192- startDaemon (dc )
193-
194- _ , nodeState := createNode ("node1" )
195- By ("waiting for state to be succeeded" )
196- EventuallyWithOffset (1 , func (g Gomega ) {
197- g .Expect (k8sClient .Get (context .Background (), types.NamespacedName {Namespace : nodeState .Namespace , Name : nodeState .Name }, nodeState )).
198- ToNot (HaveOccurred ())
199167
200- g .Expect (nodeState .Status .SyncStatus ).To (Equal (constants .SyncStatusSucceeded ))
201- }, waitTime , retryTime ).Should (Succeed ())
168+ discoverSriovReturn .Store (& []sriovnetworkv1.InterfaceExt {
169+ {
170+ Name : "eno1" ,
171+ Driver : "ice" ,
172+ PciAddress : "0000:16:00.0" ,
173+ DeviceID : "1593" ,
174+ Vendor : "8086" ,
175+ EswitchMode : "legacy" ,
176+ LinkAdminState : "up" ,
177+ LinkSpeed : "10000 Mb/s" ,
178+ LinkType : "ETH" ,
179+ Mac : "aa:bb:cc:dd:ee:ff" ,
180+ Mtu : 1500 ,
181+ TotalVfs : 2 ,
182+ NumVfs : 0 ,
183+ },
184+ })
185+
186+ By ("waiting for state to be succeeded" )
187+ eventuallySyncStatusEqual (nodeState , constants .SyncStatusSucceeded )
202188
203189 By ("add spec to node state" )
204190 err := k8sClient .Get (ctx , types.NamespacedName {Namespace : nodeState .Namespace , Name : nodeState .Name }, nodeState )
@@ -216,14 +202,44 @@ var _ = Describe("Daemon Controller", Ordered, func() {
216202 VfRange : "eno1#0-1" },
217203 }},
218204 }
219- afterConfig = true
205+
206+ discoverSriovReturn .Store (& []sriovnetworkv1.InterfaceExt {
207+ {
208+ Name : "eno1" ,
209+ Driver : "ice" ,
210+ PciAddress : "0000:16:00.0" ,
211+ DeviceID : "1593" ,
212+ Vendor : "8086" ,
213+ EswitchMode : "legacy" ,
214+ LinkAdminState : "up" ,
215+ LinkSpeed : "10000 Mb/s" ,
216+ LinkType : "ETH" ,
217+ Mac : "aa:bb:cc:dd:ee:ff" ,
218+ Mtu : 1500 ,
219+ TotalVfs : 2 ,
220+ NumVfs : 2 ,
221+ VFs : []sriovnetworkv1.VirtualFunction {
222+ {
223+ Name : "eno1f0" ,
224+ PciAddress : "0000:16:00.1" ,
225+ VfID : 0 ,
226+ },
227+ {
228+ Name : "eno1f1" ,
229+ PciAddress : "0000:16:00.2" ,
230+ VfID : 1 ,
231+ }},
232+ },
233+ })
234+
220235 err = k8sClient .Update (ctx , nodeState )
221236 Expect (err ).ToNot (HaveOccurred ())
237+
222238 By ("waiting to require drain" )
223239 EventuallyWithOffset (1 , func (g Gomega ) {
224240 g .Expect (k8sClient .Get (context .Background (), types.NamespacedName {Namespace : nodeState .Namespace , Name : nodeState .Name }, nodeState )).
225241 ToNot (HaveOccurred ())
226- g .Expect (dc .GetLastAppliedGeneration ()).To (Equal (int64 (2 )))
242+ g .Expect (daemonReconciler .GetLastAppliedGeneration ()).To (Equal (int64 (2 )))
227243 }, waitTime , retryTime ).Should (Succeed ())
228244
229245 err = k8sClient .Get (ctx , types.NamespacedName {Namespace : nodeState .Namespace , Name : nodeState .Name }, nodeState )
@@ -264,55 +280,35 @@ var _ = Describe("Daemon Controller", Ordered, func() {
264280 DeferCleanup (func (x bool ) { vars .DisableDrain = x }, vars .DisableDrain )
265281 vars .DisableDrain = true
266282
267- By ("Init mock functions" )
268- hostHelper .EXPECT ().DiscoverSriovDevices (hostHelper ).DoAndReturn (func (helpersInterface helper.HostHelpersInterface ) ([]sriovnetworkv1.InterfaceExt , error ) {
269- interfaceExtList := []sriovnetworkv1.InterfaceExt {
270- {
271- Name : "eno1" ,
272- Driver : "ice" ,
273- PciAddress : "0000:16:00.0" ,
274- DeviceID : "1593" ,
275- Vendor : "8086" ,
276- EswitchMode : "legacy" ,
277- LinkAdminState : "up" ,
278- LinkSpeed : "10000 Mb/s" ,
279- LinkType : "ETH" ,
280- Mac : "aa:bb:cc:dd:ee:ff" ,
281- Mtu : 1500 ,
282- TotalVfs : 2 ,
283- NumVfs : 2 ,
284- VFs : []sriovnetworkv1.VirtualFunction {
285- {
286- Name : "eno1f0" ,
287- PciAddress : "0000:16:00.1" ,
288- VfID : 0 ,
289- },
290- {
291- Name : "eno1f1" ,
292- PciAddress : "0000:16:00.2" ,
293- VfID : 1 ,
294- }},
295- },
296- }
297-
298- return interfaceExtList , nil
299- }).AnyTimes ()
300-
301- hostHelper .EXPECT ().LoadPfsStatus ("0000:16:00.0" ).Return (& sriovnetworkv1.Interface {ExternallyManaged : false }, true , nil ).AnyTimes ()
302-
303- hostHelper .EXPECT ().ClearPCIAddressFolder ().Return (nil ).AnyTimes ()
304- hostHelper .EXPECT ().DiscoverRDMASubsystem ().Return ("shared" , nil ).AnyTimes ()
305- hostHelper .EXPECT ().GetCurrentKernelArgs ().Return ("" , nil ).AnyTimes ()
306- hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgPciRealloc ).Return (true ).AnyTimes ()
307- hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgIntelIommu ).Return (true ).AnyTimes ()
308- hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgIommuPt ).Return (true ).AnyTimes ()
309- hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgRdmaExclusive ).Return (false ).AnyTimes ()
310- hostHelper .EXPECT ().IsKernelArgsSet ("" , constants .KernelArgRdmaShared ).Return (false ).AnyTimes ()
311- hostHelper .EXPECT ().SetRDMASubsystem ("" ).Return (nil ).AnyTimes ()
312-
313- hostHelper .EXPECT ().ConfigSriovInterfaces (gomock .Any (), gomock .Any (), gomock .Any (), false ).Return (nil ).AnyTimes ()
314-
315- _ , nodeState := createNode ("node1" )
283+ discoverSriovReturn .Store (& []sriovnetworkv1.InterfaceExt {
284+ {
285+ Name : "eno1" ,
286+ Driver : "ice" ,
287+ PciAddress : "0000:16:00.0" ,
288+ DeviceID : "1593" ,
289+ Vendor : "8086" ,
290+ EswitchMode : "legacy" ,
291+ LinkAdminState : "up" ,
292+ LinkSpeed : "10000 Mb/s" ,
293+ LinkType : "ETH" ,
294+ Mac : "aa:bb:cc:dd:ee:ff" ,
295+ Mtu : 1500 ,
296+ TotalVfs : 2 ,
297+ NumVfs : 2 ,
298+ VFs : []sriovnetworkv1.VirtualFunction {
299+ {
300+ Name : "eno1f0" ,
301+ PciAddress : "0000:16:00.1" ,
302+ VfID : 0 ,
303+ },
304+ {
305+ Name : "eno1f1" ,
306+ PciAddress : "0000:16:00.2" ,
307+ VfID : 1 ,
308+ }},
309+ },
310+ })
311+
316312 nodeState .Spec .Interfaces = []sriovnetworkv1.Interface {
317313 {Name : "eno1" ,
318314 PciAddress : "0000:16:00.0" ,
@@ -328,11 +324,6 @@ var _ = Describe("Daemon Controller", Ordered, func() {
328324 err := k8sClient .Update (ctx , nodeState )
329325 Expect (err ).ToNot (HaveOccurred ())
330326
331- featureGates := featuregate .New ()
332- featureGates .Init (map [string ]bool {})
333- dc := createDaemon (hostHelper , platformHelper , featureGates , []string {})
334- startDaemon (dc )
335-
336327 eventuallySyncStatusEqual (nodeState , constants .SyncStatusSucceeded )
337328
338329 By ("Simulate node policy removal" )
0 commit comments