Skip to content

Commit

Permalink
controller, e2e: allow missing network-selection-elements
Browse files Browse the repository at this point in the history
This commit fixes the hotplug scenario where the running pod does
**not** feature any attachments other than the default cluster network.

Signed-off-by: Miguel Duarte Barroso <[email protected]>
  • Loading branch information
maiqueb committed Oct 25, 2022
1 parent bd4db6f commit f0267bd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
14 changes: 7 additions & 7 deletions e2e/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ func podMeta(podName string, namespace string, label map[string]string, annotati
}

func dynamicNetworksAnnotation(pod *corev1.Pod, newIfaceConfigs ...*nettypes.NetworkSelectionElement) string {
var currentNetworkSelectionElements []*nettypes.NetworkSelectionElement
currentNetworkSelectionElementsString, wasFound := pod.ObjectMeta.Annotations[nettypes.NetworkAttachmentAnnot]
if !wasFound {
return ""
}

currentNetworkSelectionElements, err := annotations.ParsePodNetworkAnnotations(currentNetworkSelectionElementsString, pod.GetNamespace())
if err != nil {
return ""
if wasFound {
var err error
currentNetworkSelectionElements, err = annotations.ParsePodNetworkAnnotations(currentNetworkSelectionElementsString, pod.GetNamespace())
if err != nil {
return ""
}
}

updatedNetworkSelectionElements := append(
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ var _ = Describe("Multus dynamic networks controller", func() {
})
})

XContext("a provisioned pod featuring *only* the cluster's default network", func() {
Context("a provisioned pod featuring *only* the cluster's default network", func() {
var pod *corev1.Pod

BeforeEach(func() {
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ func (pnc *PodNetworksController) updatePodNetworkStatus(pod *corev1.Pod, newIfa
func networkSelectionElements(podAnnotations map[string]string, podNamespace string) ([]*nadv1.NetworkSelectionElement, error) {
podNetworks, ok := podAnnotations[nadv1.NetworkAttachmentAnnot]
if !ok {
return nil, fmt.Errorf("the pod is missing the \"%s\" annotation on its annotations: %+v", nadv1.NetworkAttachmentAnnot, podAnnotations)
return []*nadv1.NetworkSelectionElement{}, nil
}
if podNetworks == "" {
podNetworks = "[]"
}
podNetworkSelectionElements, err := annotations.ParsePodNetworkAnnotations(podNetworks, podNamespace)
if err != nil {
Expand Down

0 comments on commit f0267bd

Please sign in to comment.