Skip to content

Commit

Permalink
fix(storage-network): incompatible with Multus version above 4.0.0
Browse files Browse the repository at this point in the history
ref: 6953

Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
  • Loading branch information
c3y1huang committed Oct 25, 2023
1 parent 87ed482 commit 09fcd70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 10 additions & 2 deletions datastore/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,18 @@ func (s *DataStore) GetStorageIPFromPod(pod *corev1.Pod) string {
return pod.Status.PodIP
}

// Check if the network-status annotation exists.
status, ok := pod.Annotations[string(types.CNIAnnotationNetworkStatus)]
if !ok {
logrus.Warnf("Missing %v annotation, use %v pod IP %v", types.CNIAnnotationNetworkStatus, pod.Name, pod.Status.PodIP)
return pod.Status.PodIP
// If the network-status annotation is missing, check the deprecated annotation.
logrus.Debugf("Missing %v annotation, checking deprecated %v annotation", types.CNIAnnotationNetworkStatus, types.CNIAnnotationNetworksStatus)
status, ok = pod.Annotations[string(types.CNIAnnotationNetworksStatus)]

// If the deprecated annotation is also missing, use the pod IP.
if !ok {
logrus.Warnf("Missing %v annotation, use %v pod IP %v", types.CNIAnnotationNetworkStatus, pod.Name, pod.Status.PodIP)
return pod.Status.PodIP
}
}

nets := []types.CniNetwork{}
Expand Down
7 changes: 6 additions & 1 deletion types/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,12 @@ type CNIAnnotation string

const (
CNIAnnotationNetworks = CNIAnnotation("k8s.v1.cni.cncf.io/networks")
CNIAnnotationNetworkStatus = CNIAnnotation("k8s.v1.cni.cncf.io/networks-status")
CNIAnnotationNetworkStatus = CNIAnnotation("k8s.v1.cni.cncf.io/network-status")

// Deprecated: This is deprecated since Multus v3.6 and completely removed in v4.0.0.
// This exists to support older Multus versions.
// Ref: https://github.com/longhorn/longhorn/issues/6953
CNIAnnotationNetworksStatus = CNIAnnotation("k8s.v1.cni.cncf.io/networks-status")
)

const (
Expand Down

0 comments on commit 09fcd70

Please sign in to comment.