Skip to content

Commit

Permalink
try fix fip not work for default vpc
Browse files Browse the repository at this point in the history
Signed-off-by: HuangWei <[email protected]>
  • Loading branch information
a180285 committed Jan 24, 2024
1 parent 01aabdb commit b31836f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/controller/ovn_fip.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,28 @@ func (c *Controller) handleUpdateOvnFip(key string) error {
return err
}
// ovn add fip
if vpcName == util.DefaultVpc {
// fix issue https://github.com/kubeovn/kube-ovn/issues/3502
// Where ovn fip is not work for default vpc
match := fmt.Sprintf("ip4.src == %s", internalV4Ip)
cm, err := c.configMapsLister.ConfigMaps(c.config.ExternalGatewayConfigNS).Get(util.ExternalGatewayConfig)
if err != nil {
klog.Errorf("failed to create config map %s, %v", util.ExternalGatewayConfig, err)
return err
}
externalGwAddr := cm.Data["external-gw-addr"]
if externalGwAddr == "" {
err = fmt.Errorf("external-gw-addr should not be empty in config map %s", util.ExternalGatewayConfig)
klog.Errorf("%v", err)
return err
}

if err = c.OVNNbClient.AddLogicalRouterPolicy(vpcName, util.DefaultVpcFipPolicyPriority, match,
ovnnb.LogicalRouterPolicyActionReroute, []string{externalGwAddr}, nil); err != nil {
klog.Errorf("failed to create LogicalRouterPolicy for fip: %s, %v", fip.Name, err)
return err
}
}
options := map[string]string{"staleless": strconv.FormatBool(c.ExternalGatewayType == kubeovnv1.GWDistributedType)}
if err = c.OVNNbClient.AddNat(vpcName, ovnnb.NATTypeDNATAndSNAT, cachedEip.Status.V4Ip,
internalV4Ip, mac, cachedFip.Spec.IPName, options); err != nil {
Expand Down Expand Up @@ -457,6 +479,12 @@ func (c *Controller) handleDelOvnFip(key string) error {
}
// ovn delete fip nat
if cachedFip.Status.Vpc != "" && cachedFip.Status.V4Eip != "" && cachedFip.Status.V4Ip != "" {
if cachedFip.Status.Vpc == util.DefaultVpc {
match := fmt.Sprintf("ip4.src == %s", cachedFip.Status.V4Ip)
if err = c.OVNNbClient.DeleteLogicalRouterPolicy(cachedFip.Status.Vpc, util.DefaultVpcFipPolicyPriority, match); err != nil {
klog.Errorf("failed to delete LogicalRouterPolicy for fip: %s, %v", cachedFip.Name, err)
}
}
if err = c.OVNNbClient.DeleteNat(cachedFip.Status.Vpc, ovnnb.NATTypeDNATAndSNAT, cachedFip.Status.V4Eip, cachedFip.Status.V4Ip); err != nil {
klog.Errorf("failed to delete fip %s, %v", key, err)
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/util/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const (
OvnICPolicyPriority = 29500
NodeRouterPolicyPriority = 30000
NodeLocalDNSPolicyPriority = 30100
DefaultVpcFipPolicyPriority = 30500
SubnetRouterPolicyPriority = 31000

OffloadType = "offload-port"
Expand Down

0 comments on commit b31836f

Please sign in to comment.