99 "path"
1010 "testing"
1111
12- . "github.com/onsi/ginkgo"
12+ . "github.com/onsi/ginkgo/v2 "
1313 . "github.com/onsi/gomega"
1414
1515 cni100 "github.com/containernetworking/cni/pkg/types/100"
@@ -204,31 +204,15 @@ var _ = Describe("Dynamic Attachment controller", func() {
204204 })
205205
206206 When ("an update to an existing attachment occurs" , func () {
207- BeforeEach (func () {
208- var err error
209-
210- currentPodAttachments , err := networkSelectionElements (pod .Annotations , pod .GetNamespace ())
211- Expect (err ).NotTo (HaveOccurred ())
212- Expect (currentPodAttachments ).NotTo (BeEmpty ())
207+ DescribeTable ("nothing happens" , func (updatedNetworkSelectionElement nad.NetworkSelectionElement ) {
208+ Expect (updatePodNetworkSelectionElements (k8sClient , pod , updatedNetworkSelectionElement )).To (Succeed ())
213209
214- currentPodAttachments [0 ].MacRequest = "07:06:05:04:03:02"
215- var newAttachments []nad.NetworkSelectionElement
216- for i := range currentPodAttachments {
217- newAttachments = append (newAttachments , * currentPodAttachments [i ])
218- }
219-
220- serializedAttachments , err := json .Marshal (newAttachments )
221- Expect (err ).NotTo (HaveOccurred ())
222- pod .Annotations [nad .NetworkAttachmentAnnot ] = string (serializedAttachments )
223-
224- _ , err = k8sClient .CoreV1 ().Pods (namespace ).UpdateStatus (
210+ _ , err := k8sClient .CoreV1 ().Pods (namespace ).UpdateStatus (
225211 context .TODO (),
226212 pod ,
227213 metav1.UpdateOptions {})
228214 Expect (err ).NotTo (HaveOccurred ())
229- })
230215
231- It ("nothing happens" , func () {
232216 Consistently (func () ([]nad.NetworkStatus , error ) {
233217 updatedPod , err := k8sClient .CoreV1 ().Pods (namespace ).Get (context .TODO (), podName , metav1.GetOptions {})
234218 if err != nil {
@@ -240,12 +224,50 @@ var _ = Describe("Dynamic Attachment controller", func() {
240224 }
241225 return status , nil
242226 }).Should (ConsistOf (ifaceStatus (namespace , networkName , "net0" , "" )))
243- })
227+ },
228+ Entry ("when the MAC address is updated" , nad.NetworkSelectionElement {
229+ Name : networkName ,
230+ Namespace : namespace ,
231+ InterfaceRequest : "net0" ,
232+ MacRequest : "07:06:05:04:03:02" ,
233+ }),
234+ XEntry ("when the iface name is updated" , nad.NetworkSelectionElement {
235+ Name : networkName ,
236+ Namespace : namespace ,
237+ InterfaceRequest : "newiface" ,
238+ }, Label ("issue#66" )),
239+ )
244240 })
245241 })
246242 })
247243})
248244
245+ func updatePodNetworkSelectionElements (k8sClient k8sclient.Interface , pod * corev1.Pod , newAttachments ... nad.NetworkSelectionElement ) error {
246+ currentPodAttachments , err := networkSelectionElements (pod .Annotations , pod .GetNamespace ())
247+ if err != nil {
248+ return err
249+ } else if len (currentPodAttachments ) == 0 {
250+ return fmt .Errorf ("no attachments " )
251+ }
252+
253+ for i := range currentPodAttachments [1 :] {
254+ newAttachments = append (newAttachments , * currentPodAttachments [i ])
255+ }
256+
257+ serializedAttachments , err := json .Marshal (newAttachments )
258+ if err != nil {
259+ return err
260+ }
261+
262+ pod .Annotations [nad .NetworkAttachmentAnnot ] = string (serializedAttachments )
263+ _ , err = k8sClient .CoreV1 ().Pods (pod .GetNamespace ()).UpdateStatus (
264+ context .TODO (),
265+ pod ,
266+ metav1.UpdateOptions {})
267+
268+ return err
269+ }
270+
249271func networkConfig (cmd , ifaceName , mac string ) fakemultusclient.NetworkConfig {
250272 const cniVersion = "1.0.0"
251273 return fakemultusclient.NetworkConfig {
0 commit comments