Skip to content

Commit 13ccf0b

Browse files
committed
controller, test: assert the network status after interface add/delete
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
1 parent 3646bd8 commit 13ccf0b

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

pkg/controller/pod_test.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ var _ = Describe("Dynamic Attachment controller", func() {
107107
eventRecorder,
108108
fakecri.NewFakeRuntime(*pod),
109109
fakemultusclient.NewFakeClient(
110-
networkConfig(multuscni.CmdAdd, "net1", networkName, macAddr),
111-
networkConfig(multuscni.CmdDel, "net0", "", "")),
110+
networkConfig(multuscni.CmdAdd, "net1", macAddr),
111+
networkConfig(multuscni.CmdDel, "net0", "")),
112112
)).NotTo(BeNil())
113113
Expect(func() []nad.NetworkStatus {
114114
updatedPod, err := k8sClient.CoreV1().Pods(namespace).Get(context.TODO(), podName, metav1.GetOptions{})
@@ -150,6 +150,22 @@ var _ = Describe("Dynamic Attachment controller", func() {
150150
)
151151
Eventually(<-eventRecorder.Events).Should(Equal(expectedEventPayload))
152152
})
153+
154+
It("the pod network-status is updated with the new network attachment", func() {
155+
Eventually(func() ([]nad.NetworkStatus, error) {
156+
updatedPod, err := k8sClient.CoreV1().Pods(namespace).Get(context.TODO(), podName, metav1.GetOptions{})
157+
if err != nil {
158+
return nil, err
159+
}
160+
status, err := networkStatus(updatedPod.Annotations)
161+
if err != nil {
162+
return nil, err
163+
}
164+
return status, nil
165+
}).Should(ConsistOf(
166+
ifaceStatus(namespace, networkName, "net0", ""),
167+
ifaceStatus(namespace, networkToAdd, "net1", macAddr)))
168+
})
153169
})
154170

155171
When("an attachment is removed from the pod's network annotations", func() {
@@ -171,12 +187,26 @@ var _ = Describe("Dynamic Attachment controller", func() {
171187
)
172188
Eventually(<-eventRecorder.Events).Should(Equal(expectedEventPayload))
173189
})
190+
191+
It("the pod network-status no longer features the removed network", func() {
192+
Eventually(func() ([]nad.NetworkStatus, error) {
193+
updatedPod, err := k8sClient.CoreV1().Pods(namespace).Get(context.TODO(), podName, metav1.GetOptions{})
194+
if err != nil {
195+
return nil, err
196+
}
197+
status, err := networkStatus(updatedPod.Annotations)
198+
if err != nil {
199+
return nil, err
200+
}
201+
return status, nil
202+
}).Should(BeEmpty())
203+
})
174204
})
175205
})
176206
})
177207
})
178208

179-
func networkConfig(cmd, ifaceName, networkName, mac string) fakemultusclient.NetworkConfig {
209+
func networkConfig(cmd, ifaceName, mac string) fakemultusclient.NetworkConfig {
180210
const cniVersion = "1.0.0"
181211
return fakemultusclient.NetworkConfig{
182212
Cmd: cmd,
@@ -185,7 +215,7 @@ func networkConfig(cmd, ifaceName, networkName, mac string) fakemultusclient.Net
185215
Result: &cni100.Result{
186216
CNIVersion: cniVersion,
187217
Interfaces: []*cni100.Interface{
188-
{Name: networkName, Mac: mac},
218+
{Name: ifaceName, Mac: mac, Sandbox: "asd"},
189219
},
190220
}},
191221
}
@@ -406,3 +436,11 @@ func dummyMultusConfig() string {
406436
}
407437
}`
408438
}
439+
440+
func ifaceStatus(namespace, networkName, ifaceName, macAddress string) nad.NetworkStatus {
441+
return nad.NetworkStatus{
442+
Name: fmt.Sprintf("%s/%s", namespace, networkName),
443+
Interface: ifaceName,
444+
Mac: macAddress,
445+
}
446+
}

0 commit comments

Comments
 (0)