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

add vm pod to ipam by ip when initIPAM #1974

Merged
merged 1 commit into from
Oct 18, 2022
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
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 ""
}