Skip to content

Commit 5fdfb68

Browse files
committed
controller: report default network after network deletion
When converging the desired / current state differences we must always omit the default network, but when we are computing the current state **after** deleting interfaces, the default network's state must always be present. Signed-off-by: Miguel Duarte Barroso <[email protected]>
1 parent 0ad6a39 commit 5fdfb68

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

pkg/annotations/dynamic-network-status.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,19 @@ func NamespacedName(podNamespace string, podName string) string {
7373
}
7474

7575
func IndexNetworkStatus(pod *corev1.Pod) map[string]nettypes.NetworkStatus {
76+
return indexNetworkStatusWithIgnorePredicate(pod, func(status nettypes.NetworkStatus) bool {
77+
return false
78+
})
79+
}
80+
81+
func indexNetworkStatusWithIgnorePredicate(pod *corev1.Pod, p IgnoreStatusPredicate) map[string]nettypes.NetworkStatus {
7682
currentPodNetworkStatus, err := PodDynamicNetworkStatus(pod)
7783
if err != nil {
7884
return map[string]nettypes.NetworkStatus{}
7985
}
8086
indexedNetworkStatus := map[string]nettypes.NetworkStatus{}
8187
for i := range currentPodNetworkStatus {
82-
if !currentPodNetworkStatus[i].Default {
88+
if !p(currentPodNetworkStatus[i]) {
8389
indexedNetworkStatus[networkStatusIndexKey(currentPodNetworkStatus[i])] = currentPodNetworkStatus[i]
8490
}
8591
}
@@ -92,3 +98,11 @@ func networkStatusIndexKey(networkStatus nettypes.NetworkStatus) string {
9298
networkStatus.Name,
9399
networkStatus.Interface)
94100
}
101+
102+
type IgnoreStatusPredicate func(status nettypes.NetworkStatus) bool
103+
104+
func IndexNetworkStatusIgnoringDefaultNetwork(pod *corev1.Pod) map[string]nettypes.NetworkStatus {
105+
return indexNetworkStatusWithIgnorePredicate(pod, func(status nettypes.NetworkStatus) bool {
106+
return status.Default
107+
})
108+
}

pkg/annotations/dynamic-network-status_test.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,35 @@ var _ = Describe("NetworkStatusFromResponse", func() {
212212
attachmentInfo{
213213
ifaceName: "iface2",
214214
networkName: "net2",
215-
}))
215+
}),
216+
Entry(
217+
"the default interface is reported when we delete another interface",
218+
[]nadv1.NetworkStatus{
219+
{
220+
Name: annotations.NamespacedName(namespace, networkName),
221+
Interface: "iface1",
222+
Mac: "00:00:00:20:10:00",
223+
Default: true,
224+
},
225+
{
226+
Name: annotations.NamespacedName(namespace, "net2"),
227+
Interface: "iface2",
228+
Mac: "aa:bb:cc:20:10:00",
229+
},
230+
},
231+
[]nadv1.NetworkStatus{
232+
{
233+
Name: annotations.NamespacedName(namespace, networkName),
234+
Interface: "iface1",
235+
Mac: "00:00:00:20:10:00",
236+
Default: true,
237+
},
238+
},
239+
attachmentInfo{
240+
ifaceName: "iface2",
241+
networkName: "net2",
242+
},
243+
))
216244
})
217245

218246
func newPod(podName string, namespace string, netStatus ...nadv1.NetworkStatus) *corev1.Pod {

pkg/controller/pod.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (pnc *PodNetworksController) processNextWorkItem() bool {
154154
}
155155

156156
indexedNetworkSelectionElements := annotations.IndexPodNetworkSelectionElements(pod)
157-
indexedNetworkStatus := annotations.IndexNetworkStatus(pod)
157+
indexedNetworkStatus := annotations.IndexNetworkStatusIgnoringDefaultNetwork(pod)
158158

159159
netnsPath, err := pnc.netnsPath(pod)
160160
if err != nil {

0 commit comments

Comments
 (0)