From b31836f2e2b1efa641cff7bd1e1e70464f59fd73 Mon Sep 17 00:00:00 2001 From: HuangWei Date: Tue, 23 Jan 2024 22:58:35 +0800 Subject: [PATCH] try fix fip not work for default vpc Signed-off-by: HuangWei --- pkg/controller/ovn_fip.go | 28 ++++++++++++++++++++++++++++ pkg/util/const.go | 1 + 2 files changed, 29 insertions(+) diff --git a/pkg/controller/ovn_fip.go b/pkg/controller/ovn_fip.go index 0ecce7e5f36..f110f0bab73 100644 --- a/pkg/controller/ovn_fip.go +++ b/pkg/controller/ovn_fip.go @@ -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 { @@ -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 diff --git a/pkg/util/const.go b/pkg/util/const.go index 9d92ea2d9b8..02d07356d96 100644 --- a/pkg/util/const.go +++ b/pkg/util/const.go @@ -204,6 +204,7 @@ const ( OvnICPolicyPriority = 29500 NodeRouterPolicyPriority = 30000 NodeLocalDNSPolicyPriority = 30100 + DefaultVpcFipPolicyPriority = 30500 SubnetRouterPolicyPriority = 31000 OffloadType = "offload-port"