Skip to content

Commit

Permalink
add vm pod to ipam by ip when initIPAM (#1974)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Oct 18, 2022
1 parent ffa0498 commit f56bb0b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
8 changes: 5 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,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)
}
Expand All @@ -514,9 +519,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)
}
Expand Down
18 changes: 15 additions & 3 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1613,5 +1613,9 @@ func getPodType(pod *v1.Pod) string {
if ok, _ := isStatefulSetPod(pod); ok {
return "StatefulSet"
}

if isVmPod, _ := isVmPod(pod); isVmPod {
return util.Vm
}
return ""
}

0 comments on commit f56bb0b

Please sign in to comment.