Skip to content

Commit

Permalink
fix: add pod not update vip virtual port
Browse files Browse the repository at this point in the history
  • Loading branch information
h807892124 authored and oilbeater committed Sep 22, 2022
1 parent 596741b commit 474206b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
4 changes: 4 additions & 0 deletions pkg/controller/pod.go
Expand Up @@ -581,6 +581,10 @@ func (c *Controller) handleAddPod(key string) error {
c.syncSgPortsQueue.Add(sgName)
}
}

if vips != "" {
c.syncVirtualPortsQueue.Add(podNet.Subnet.Name)
}
}
}

Expand Down
29 changes: 17 additions & 12 deletions pkg/controller/subnet.go
Expand Up @@ -933,24 +933,29 @@ func (c *Controller) syncVirtualPort(key string) error {
klog.Errorf("failed to list logical_switch_port, %v", err)
return err
}
vipVirtualParentsMap := map[string][]string{}
for _, ret := range results {
var associatedVips []string
for _, value := range ret["external_ids"] {
if strings.HasPrefix(value, "vips") {
vips := strings.Split(value, "=")[1]
associatedVips = strings.Split(strings.ReplaceAll(vips, " ", ""), "/")
}
}
klog.Infof("associatedVips %v", associatedVips)
for _, vip := range associatedVips {
vipVirtualParentsMap[vip] = append(vipVirtualParentsMap[vip], ret["name"][0])
}
}

for _, vip := range subnet.Spec.Vips {
if !util.CIDRContainIP(subnet.Spec.CIDRBlock, vip) {
klog.Errorf("vip %s is out of range to subnet %s", vip, subnet.Name)
continue
}
var virtualParents []string
for _, ret := range results {
var associatedVips []string
for _, value := range ret["external_ids"] {
if strings.HasPrefix(value, "vips") {
vips := strings.Split(value, "=")[1]
associatedVips = strings.Split(strings.ReplaceAll(vips, " ", ""), "/")
}
}
klog.Infof("associatedVips %v", associatedVips)
if util.ContainsString(associatedVips, vip) {
virtualParents = append(virtualParents, ret["name"][0])
}
if value, exist := vipVirtualParentsMap[vip]; exist {
virtualParents = value
}
if err = c.ovnLegacyClient.SetVirtualParents(subnet.Name, vip, strings.Join(virtualParents, ",")); err != nil {
klog.Errorf("failed to set vip %s virtual parents, %v", vip, err)
Expand Down
1 change: 1 addition & 0 deletions pkg/ovs/ovn-nbctl-legacy.go
Expand Up @@ -230,6 +230,7 @@ func (c LegacyClient) CreateVirtualPort(ls, ip string) error {
}

func (c LegacyClient) SetVirtualParents(ls, ip, parents string) error {
klog.Infof("set virtual parents: ls='%s', vip='%s', parents='%s'", ls, ip, parents)
portName := fmt.Sprintf("%s-vip-%s", ls, ip)
var cmdArg []string
if parents != "" {
Expand Down

0 comments on commit 474206b

Please sign in to comment.