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 authored Oct 18, 2022
1 parent afe06d8 commit 15f676f
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 @@ -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)
}
Expand All @@ -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)
}
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 @@ -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 ""
}

0 comments on commit 15f676f

Please sign in to comment.