Unverified Commit 15f676f6 authored by hzma's avatar hzma Committed by GitHub
Browse files

add vm pod to ipam by ip when initIPAM (#1974)

parent afe06d81
Showing with 24 additions and 6 deletions
+24 -6
......@@ -540,6 +540,11 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
klog.Fatalf("failed to init ovn resource: %v", err)
}
// sync ip crd before initIPAM since ip crd will be used to restore vm and statefulset pod in initIPAM
if err := c.initSyncCrdIPs(); err != nil {
klog.Errorf("failed to sync crd ips: %v", err)
}
if err := c.InitIPAM(); err != nil {
klog.Fatalf("failed to init ipam: %v", err)
}
......@@ -562,9 +567,6 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
}
c.registerSubnetMetrics()
if err := c.initSyncCrdIPs(); err != nil {
klog.Errorf("failed to sync crd ips: %v", err)
}
if err := c.initSyncCrdSubnets(); err != nil {
klog.Errorf("failed to sync crd subnets: %v", err)
}
......
......@@ -330,8 +330,8 @@ func (c *Controller) InitIPAM() error {
ipsMap := make(map[string]*kubeovnv1.IP, len(ips))
for _, ip := range ips {
ipsMap[ip.Name] = ip
// just recover sts ip, old sts ip with empty pod type and other ip recover in later pod loop
if ip.Spec.PodType != "StatefulSet" {
// recover sts and kubevirt vm ip, other ip recover in later pod loop
if ip.Spec.PodType != "StatefulSet" && ip.Spec.PodType != util.Vm {
continue
}
......@@ -582,10 +582,22 @@ func (c *Controller) initSyncCrdIPs() error {
return err
}
vmLsps := c.getVmLsps()
ipMap := make(map[string]struct{}, len(vmLsps))
for _, vmLsp := range vmLsps {
ipMap[vmLsp] = struct{}{}
}
for _, ipCr := range ips.Items {
ip := ipCr.DeepCopy()
changed := false
if _, ok := ipMap[ip.Name]; ok && ip.Spec.PodType == "" {
ip.Spec.PodType = util.Vm
changed = true
}
v4IP, v6IP := util.SplitStringIP(ip.Spec.IPAddress)
if ip.Spec.V4IPAddress == v4IP && ip.Spec.V6IPAddress == v6IP {
if ip.Spec.V4IPAddress == v4IP && ip.Spec.V6IPAddress == v6IP && !changed {
continue
}
ip.Spec.V4IPAddress = v4IP
......
......@@ -1632,5 +1632,9 @@ func getPodType(pod *v1.Pod) string {
if ok, _ := isStatefulSetPod(pod); ok {
return "StatefulSet"
}
if isVmPod, _ := isVmPod(pod); isVmPod {
return util.Vm
}
return ""
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment