Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support kube-ovn as cni to provide static ip address #660

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/v1alpha1/observer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ func (s *OBServer) SupportStaticIP() bool {
switch s.Status.CNI {
case oceanbaseconst.CNICalico:
return true
case oceanbaseconst.CNIKubeOvn:
return true
default:
annos := s.GetAnnotations()
if annos == nil {
Expand Down
7 changes: 5 additions & 2 deletions internal/const/oceanbase/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ See the Mulan PSL v2 for more details.
package oceanbase

const (
AnnotationCalicoValidate = "cni.projectcalico.org/podIP"
AnnotationCalicoIpAddrs = "cni.projectcalico.org/ipAddrs"
AnnotationCalicoValidate = "cni.projectcalico.org/podIP"
AnnotationCalicoIpAddrs = "cni.projectcalico.org/ipAddrs"
AnnotationKubeOvnValidate = "ovn.kubernetes.io/ip_address"
AnnotationKubeOvnIpAddrs = "ovn.kubernetes.io/ip_address"
)

const (
Expand All @@ -35,5 +37,6 @@ const (

const (
CNICalico = "calico"
CNIKubeOvn = "kube-ovn"
CNIUnknown = "unknown"
)
2 changes: 2 additions & 0 deletions internal/resource/observer/observer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ func (m *OBServerManager) UpdateStatus() error {
m.OBServer.Status.PodIp = pod.Status.PodIP
m.OBServer.Status.NodeIp = pod.Status.HostIP
// TODO update from obcluster
m.Logger.V(oceanbaseconst.LogLevelDebug).Info("OBServer pod info", "pod", pod)
m.OBServer.Status.CNI = resourceutils.GetCNIFromAnnotation(pod)
m.Logger.V(oceanbaseconst.LogLevelDebug).Info("Get CNI", "cni", m.OBServer.Status.CNI)

if m.OBServer.Status.ServiceIp == "" {
mode, modeAnnoExist := resourceutils.GetAnnotationField(m.OBServer, oceanbaseconst.AnnotationsMode)
Expand Down
4 changes: 4 additions & 0 deletions internal/resource/observer/observer_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ func AnnotateOBServerPod(m *OBServerManager) tasktypes.TaskError {
m.Logger.Info("Update pod annotation, cni is calico")
observerPod.Annotations[oceanbaseconst.AnnotationCalicoIpAddrs] = fmt.Sprintf("[\"%s\"]", m.OBServer.Status.PodIp)
}
if m.OBServer.Status.CNI == oceanbaseconst.CNIKubeOvn {
m.Logger.Info("Update pod annotation, cni is kube-ovn")
observerPod.Annotations[oceanbaseconst.AnnotationKubeOvnIpAddrs] = m.OBServer.Status.PodIp
}
err = m.K8sResClient.Update(m.Ctx, observerPod)
if err != nil {
return errors.Wrapf(err, "Failed to update pod annotation of observer %s", m.OBServer.Name)
Expand Down
4 changes: 4 additions & 0 deletions internal/resource/observer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@ func (m *OBServerManager) generateStaticIpAnnotation() map[string]string {
if m.OBServer.Status.PodIp != "" {
annotations[oceanbaseconst.AnnotationCalicoIpAddrs] = fmt.Sprintf("[\"%s\"]", m.OBServer.Status.PodIp)
}
case oceanbaseconst.CNIKubeOvn:
if m.OBServer.Status.PodIp != "" {
annotations[oceanbaseconst.AnnotationKubeOvnIpAddrs] = m.OBServer.Status.PodIp
}
default:
m.Logger.Info("No CNI is configured, set empty annotation")
}
Expand Down
9 changes: 9 additions & 0 deletions internal/resource/utils/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ import (
)

func GetCNIFromAnnotation(pod *corev1.Pod) string {
// check annotation for calico
_, found := pod.Annotations[oceanbaseconst.AnnotationCalicoValidate]
if found {
return oceanbaseconst.CNICalico
}
// check annotation for kube-ovn
_, found = pod.Annotations[oceanbaseconst.AnnotationKubeOvnValidate]
if found {
return oceanbaseconst.CNIKubeOvn
}
return oceanbaseconst.CNIUnknown
}

Expand All @@ -31,6 +37,9 @@ func NeedAnnotation(pod *corev1.Pod, cni string) bool {
case oceanbaseconst.CNICalico:
_, found := pod.Annotations[oceanbaseconst.AnnotationCalicoIpAddrs]
return !found
case oceanbaseconst.CNIKubeOvn:
_, found := pod.Annotations[oceanbaseconst.AnnotationKubeOvnIpAddrs]
return !found
default:
return false
}
Expand Down