Skip to content

Commit

Permalink
fix ic
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
zbb88888 committed Feb 6, 2024
1 parent 2500f70 commit a1e29d2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 76 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (c *Controller) handleUpdateIP(key string) error {
}
}
}
if cleanIPAM {
if cleanIPAM && cachedIP.Spec.PodName != "" && cachedIP.Spec.Namespace != "" {
podKey := fmt.Sprintf("%s/%s", cachedIP.Spec.Namespace, cachedIP.Spec.PodName)
klog.Infof("ip cr %s release ipam pod key %s from subnet %s", cachedIP.Name, podKey, cachedIP.Spec.Subnet)
c.ipam.ReleaseAddressByPod(podKey, cachedIP.Spec.Subnet)
Expand Down
97 changes: 30 additions & 67 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func formatSubnet(subnet *kubeovnv1.Subnet, c *Controller) error {
subnet.Spec.GatewayType = kubeovnv1.GWDistributedType
changed = true
}
if subnet.Spec.Vpc == "" && isOvnSubnet(subnet) {
if subnet.Spec.Vpc == "" {
changed = true
subnet.Spec.Vpc = util.DefaultVpc

Expand Down Expand Up @@ -527,40 +527,37 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
return err
}

var vpc *kubeovnv1.Vpc
if subnet.Spec.Vpc != "" {
vpc, err := c.vpcsLister.Get(subnet.Spec.Vpc)
if err != nil {
klog.Errorf("failed to get subnet's vpc '%s', %v", subnet.Spec.Vpc, err)
return err
vpc, err := c.vpcsLister.Get(subnet.Spec.Vpc)
if err != nil {
klog.Errorf("failed to get subnet's vpc '%s', %v", subnet.Spec.Vpc, err)
return err
}
if !vpc.Status.Standby {
err = fmt.Errorf("the vpc '%s' not standby yet", vpc.Name)
klog.Error(err)
return err
}

if !vpc.Status.Default {
for _, ns := range subnet.Spec.Namespaces {
if !util.ContainsString(vpc.Spec.Namespaces, ns) {
err = fmt.Errorf("namespace '%s' is out of range to custom vpc '%s'", ns, vpc.Name)
klog.Error(err)
return err
}
}
if !vpc.Status.Standby {
err = fmt.Errorf("the vpc '%s' not standby yet", vpc.Name)
klog.Error(err)
} else {
vpcs, err := c.vpcsLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list vpc, %v", err)
return err
}

if !vpc.Status.Default {
for _, ns := range subnet.Spec.Namespaces {
if !util.ContainsString(vpc.Spec.Namespaces, ns) {
err = fmt.Errorf("namespace '%s' is out of range to custom vpc '%s'", ns, vpc.Name)
klog.Error(err)
return err
}
}
} else {
vpcs, err := c.vpcsLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list vpc, %v", err)
for _, vpc := range vpcs {
if subnet.Spec.Vpc != vpc.Name && !vpc.Status.Default && util.IsStringsOverlap(vpc.Spec.Namespaces, subnet.Spec.Namespaces) {
err = fmt.Errorf("namespaces %v are overlap with vpc '%s'", subnet.Spec.Namespaces, vpc.Name)
klog.Error(err)
return err
}
for _, vpc := range vpcs {
if subnet.Spec.Vpc != vpc.Name && !vpc.Status.Default && util.IsStringsOverlap(vpc.Spec.Namespaces, subnet.Spec.Namespaces) {
err = fmt.Errorf("namespaces %v are overlap with vpc '%s'", subnet.Spec.Namespaces, vpc.Name)
klog.Error(err)
return err
}
}
}
}

Expand Down Expand Up @@ -668,11 +665,6 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
}
needRouter := subnet.Spec.Vlan == "" || subnet.Spec.LogicalGateway ||
(subnet.Status.U2OInterconnectionIP != "" && subnet.Spec.U2OInterconnection)
vpc, err = c.vpcsLister.Get(subnet.Spec.Vpc)
if err != nil {
klog.Errorf("failed to get subnet's vpc '%s', %v", subnet.Spec.Vpc, err)
return err
}
// 1. overlay subnet, should add lrp, lrp ip is subnet gw
// 2. underlay subnet use logical gw, should add lrp, lrp ip is subnet gw
randomAllocateGW := !subnet.Spec.LogicalGateway && vpc.Spec.EnableExternal && subnet.Name == c.config.ExternalGatewaySwitch
Expand Down Expand Up @@ -847,21 +839,15 @@ func (c *Controller) handleUpdateSubnetStatus(key string) error {
klog.Error(err)
return err
}
deleted, err := c.handleSubnetFinalizer(key)
_, err = c.handleSubnetFinalizer(key)
if err != nil {
klog.Errorf("faile to handle finalizer for subnet %s, %v", key, err)
return err
}
if deleted {
return nil
}
return nil
}

func (c *Controller) handleDeleteRoute(subnet *kubeovnv1.Subnet) error {
if subnet.Spec.Vpc == "" {
return nil
}
vpc, err := c.vpcsLister.Get(subnet.Spec.Vpc)
if err != nil {
if k8serrors.IsNotFound(err) {
Expand Down Expand Up @@ -1633,11 +1619,6 @@ func (c *Controller) reconcileVlan(subnet *kubeovnv1.Subnet) error {
}

func (c *Controller) reconcileU2OInterconnectionIP(subnet *kubeovnv1.Subnet) error {
if subnet.Spec.Vpc == "" {
err := fmt.Errorf("subnet %s spec should set vpc", subnet.Name)
klog.Error(err)
return err
}
needCalcIP := false
klog.Infof("reconcile underlay subnet %s to overlay interconnection with U2OInterconnection %v U2OInterconnectionIP %s ",
subnet.Name, subnet.Spec.U2OInterconnection, subnet.Status.U2OInterconnectionIP)
Expand Down Expand Up @@ -1791,7 +1772,7 @@ func calcDualSubnetStatusIP(subnet *kubeovnv1.Subnet, c *Controller) error {
klog.Errorf("failed to marshal subnet %s status, %v", subnet.Name, err)
return err
}
subnet, err = c.config.KubeOvnClient.KubeovnV1().Subnets().Patch(context.Background(), subnet.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status")
_, err = c.config.KubeOvnClient.KubeovnV1().Subnets().Patch(context.Background(), subnet.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status")
if err != nil {
klog.Errorf("failed to patch subnet %s status, %v", subnet.Name, err)
return err
Expand Down Expand Up @@ -1881,7 +1862,7 @@ func calcSubnetStatusIP(subnet *kubeovnv1.Subnet, c *Controller) error {
klog.Errorf("failed to marshal subnet %s status, %v", subnet.Name, err)
return err
}
subnet, err = c.config.KubeOvnClient.KubeovnV1().Subnets().Patch(context.Background(), subnet.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status")
_, err = c.config.KubeOvnClient.KubeovnV1().Subnets().Patch(context.Background(), subnet.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status")
if err != nil {
klog.Errorf("failed to patch subnet %s status, %v", subnet.Name, err)
return err
Expand Down Expand Up @@ -2268,12 +2249,6 @@ func (c *Controller) deletePolicyRouteByGatewayType(subnet *kubeovnv1.Subnet, ga
}

func (c *Controller) addPolicyRouteForU2OInterconn(subnet *kubeovnv1.Subnet) error {
if subnet.Spec.Vpc == "" {
err := fmt.Errorf("subnet %s spec should set vpc", subnet.Name)
klog.Error(err)
return err
}

var v4Gw, v6Gw string
for _, gw := range strings.Split(subnet.Spec.Gateway, ",") {
switch util.CheckProtocol(gw) {
Expand Down Expand Up @@ -2387,10 +2362,6 @@ func (c *Controller) addPolicyRouteForU2OInterconn(subnet *kubeovnv1.Subnet) err
}

func (c *Controller) deletePolicyRouteForU2OInterconn(subnet *kubeovnv1.Subnet) error {
if subnet.Spec.Vpc == "" {
return nil
}

results, err := c.ovnLegacyClient.CustomFindEntity("Logical_Router_Policy", []string{"_uuid", "match", "priority"},
"external_ids:isU2ORoutePolicy=\"true\"",
fmt.Sprintf("external_ids:vendor=\"%s\"", util.CniTypeName),
Expand Down Expand Up @@ -2442,10 +2413,6 @@ func (c *Controller) addCustomVPCPolicyRoutesForSubnet(subnet *kubeovnv1.Subnet)
}

func (c *Controller) deleteCustomVPCPolicyRoutesForSubnet(subnet *kubeovnv1.Subnet) error {
if subnet.Spec.Vpc == "" {
return nil
}

for _, cidr := range strings.Split(subnet.Spec.CIDRBlock, ",") {
af := 4
if util.CheckProtocol(cidr) == kubeovnv1.ProtocolIPv6 {
Expand All @@ -2462,10 +2429,6 @@ func (c *Controller) deleteCustomVPCPolicyRoutesForSubnet(subnet *kubeovnv1.Subn
}

func (c *Controller) clearOldU2OResource(subnet *kubeovnv1.Subnet) error {
if subnet.Spec.Vpc == "" {
return nil
}

if subnet.Status.U2OInterconnectionVPC != "" &&
(!subnet.Spec.U2OInterconnection || (subnet.Spec.U2OInterconnection && subnet.Status.U2OInterconnectionVPC != subnet.Spec.Vpc)) {
// remove old u2o lsp and lrp first
Expand Down
8 changes: 0 additions & 8 deletions pkg/ovs/ovn-nbctl-legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,11 +1035,6 @@ func (c LegacyClient) AddStaticRoute(policy, cidr, nextHop, router string, route

// AddPolicyRoute add a policy route rule in ovn
func (c LegacyClient) AddPolicyRoute(router string, priority int32, match, action, nextHop string, externalIDs map[string]string) error {
if router == "" {
err := fmt.Errorf("router name is empty")
klog.Error(err)
return err
}
consistent, err := c.CheckPolicyRouteNexthopConsistent(router, match, nextHop, priority)
if err != nil {
klog.Errorf("failed to check policy route nexthop consistent: %v", err)
Expand Down Expand Up @@ -1090,9 +1085,6 @@ func (c LegacyClient) AddPolicyRoute(router string, priority int32, match, actio

// DeletePolicyRoute delete a policy route rule in ovn
func (c LegacyClient) DeletePolicyRoute(router string, priority int32, match string) error {
if router == "" {
return nil
}
exist, err := c.IsPolicyRouteExist(router, priority, match)
if err != nil {
klog.Errorf("failed to check policy route exist: %v", err)
Expand Down

0 comments on commit a1e29d2

Please sign in to comment.