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

ip trigger subnet delete #3703

Merged
merged 6 commits into from
Feb 18, 2024
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
16 changes: 16 additions & 0 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,22 @@ func (c *Controller) handleUpdateSubnetStatus(key string) error {
klog.Error(err)
return err
}

if !subnet.DeletionTimestamp.IsZero() {
// subnet is being deleted
cachedSubnet, err = c.subnetsLister.Get(key)
if err != nil {
if k8serrors.IsNotFound(err) {
return nil
}
return err
}
subnet = cachedSubnet.DeepCopy()
if _, err = c.handleSubnetFinalizer(subnet); err != nil {
klog.Errorf("faile to handle finalizer for subnet %s, %v", key, err)
return err
}
}
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/daemon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
}

if err := csh.UpdateIPCr(podRequest, subnet, ip, macAddr); err != nil {
klog.Error(err)
if err := resp.WriteHeaderAndEntity(http.StatusInternalServerError, request.CniResponse{Err: err.Error()}); err != nil {
klog.Errorf("failed to write response, %v", err)
}
Expand Down Expand Up @@ -333,7 +334,7 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
err = csh.configureNic(podRequest.PodName, podRequest.PodNamespace, podRequest.Provider, podRequest.NetNs, podRequest.ContainerID, podRequest.VfDriver, ifName, macAddr, mtu, ipAddr, gw, isDefaultRoute, detectIPConflict, allRoutes, podRequest.DNS.Nameservers, podRequest.DNS.Search, ingress, egress, podRequest.DeviceID, nicType, latency, limit, loss, gatewayCheckMode, u2oInterconnectionIP)
}
if err != nil {
errMsg := fmt.Errorf("configure nic failed %v", err)
errMsg := fmt.Errorf("configure nic failed, %v", err)
klog.Error(errMsg)
if err := resp.WriteHeaderAndEntity(http.StatusInternalServerError, request.CniResponse{Err: errMsg.Error()}); err != nil {
klog.Errorf("failed to write response, %v", err)
Expand Down
31 changes: 29 additions & 2 deletions pkg/daemon/ovs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,27 @@ func (csh cniServerHandler) configureNic(podName, podNamespace, provider, netns,
fmt.Sprintf("external_ids:ip=%s", ipStr),
fmt.Sprintf("external_ids:pod_netns=%s", netns))
if err != nil {
klog.Error(err)
return fmt.Errorf("add nic to ovs failed %v: %q", err, output)
}

// lsp and container nic must use same mac address, otherwise ovn will reject these packets by default
macAddr, err := net.ParseMAC(mac)
if err != nil {
klog.Error(err)
return fmt.Errorf("failed to parse mac %s %v", macAddr, err)
}
if err = configureHostNic(hostNicName); err != nil {
klog.Error(err)
return err
}
if err = ovs.SetInterfaceBandwidth(podName, podNamespace, ifaceID, egress, ingress); err != nil {
klog.Error(err)
return err
}

if err = ovs.SetNetemQos(podName, podNamespace, ifaceID, latency, limit, loss); err != nil {
klog.Error(err)
return err
}

Expand All @@ -107,20 +112,24 @@ func (csh cniServerHandler) configureNic(podName, podNamespace, provider, netns,
}
isUserspaceDP, err := ovs.IsUserspaceDataPath()
if err != nil {
klog.Error(err)
return err
}
if isUserspaceDP {
// turn off tx checksum
if err = turnOffNicTxChecksum(containerNicName); err != nil {
klog.Error(err)
return err
}
}

podNS, err := ns.GetNS(netns)
if err != nil {
klog.Error(err)
return fmt.Errorf("failed to open netns %q: %v", netns, err)
}
if err = configureContainerNic(containerNicName, ifName, ip, gateway, isDefaultRoute, detectIPConflict, routes, macAddr, podNS, mtu, nicType, gwCheckMode, u2oInterconnectionIP); err != nil {
klog.Error(err)
return err
}
return nil
Expand Down Expand Up @@ -214,6 +223,7 @@ func configureHostNic(nicName string) error {
func configureContainerNic(nicName, ifName string, ipAddr, gateway string, isDefaultRoute, detectIPConflict bool, routes []request.Route, macAddr net.HardwareAddr, netns ns.NetNS, mtu int, nicType string, gwCheckMode int, u2oInterconnectionIP string) error {
containerLink, err := netlink.LinkByName(nicName)
if err != nil {
klog.Error(err)
return fmt.Errorf("can not find container nic %s: %v", nicName, err)
}

Expand All @@ -224,13 +234,15 @@ func configureContainerNic(nicName, ifName string, ipAddr, gateway string, isDef
}

if err = netlink.LinkSetNsFd(containerLink, int(netns.Fd())); err != nil {
klog.Error(err)
return fmt.Errorf("failed to move link to netns: %v", err)
}

return ns.WithNetNSPath(netns.Path(), func(_ ns.NetNS) error {

if nicType != util.InternalType {
if err = netlink.LinkSetName(containerLink, ifName); err != nil {
klog.Error(err)
return err
}
}
Expand All @@ -241,27 +253,33 @@ func configureContainerNic(nicName, ifName string, ipAddr, gateway string, isDef
// See https://github.com/containernetworking/cni/issues/531
value, err := sysctl.Sysctl("net.ipv6.conf.all.disable_ipv6")
if err != nil {
klog.Error(err)
return fmt.Errorf("failed to get sysctl net.ipv6.conf.all.disable_ipv6: %v", err)
}
if value != "0" {
if _, err = sysctl.Sysctl("net.ipv6.conf.all.disable_ipv6", "0"); err != nil {
klog.Error(err)
return fmt.Errorf("failed to enable ipv6 on all nic: %v", err)
}
}
}

if nicType == util.InternalType {
if err = addAdditionalNic(ifName); err != nil {
klog.Error(err)
return err
}
if err = configureAdditionalNic(ifName, ipAddr); err != nil {
klog.Error(err)
return err
}
if err = configureNic(nicName, ipAddr, macAddr, mtu, detectIPConflict); err != nil {
klog.Error(err)
return err
}
} else {
if err = configureNic(ifName, ipAddr, macAddr, mtu, detectIPConflict); err != nil {
klog.Error(err)
return err
}
}
Expand Down Expand Up @@ -354,6 +372,7 @@ func configureContainerNic(nicName, ifName string, ipAddr, gateway string, isDef

if u2oInterconnectionIP != "" {
if err := checkGatewayReady(gwCheckMode, interfaceName, ipAddr, u2oInterconnectionIP, false, true); err != nil {
klog.Error(err)
return err
}
}
Expand All @@ -368,21 +387,27 @@ func checkGatewayReady(gwCheckMode int, intr, ipAddr, gateway string, underlayGa
var err error

if gwCheckMode == gatewayCheckModeArpingNotConcerned || gwCheckMode == gatewayCheckModePingNotConcerned {
// ignore error while disableGatewayCheck=true
// ignore error while disableGatewayCheck is true
if err = waitNetworkReady(intr, ipAddr, gateway, underlayGateway, verbose, 1); err != nil {
klog.Warningf("network %s with gateway %s is not ready for interface %s: %v", ipAddr, gateway, intr, err)
err = nil
}
} else {
err = waitNetworkReady(intr, ipAddr, gateway, underlayGateway, verbose, gatewayCheckMaxRetry)
}
return err
if err != nil {
klog.Error(err)
return err
}
return nil
}

func waitNetworkReady(nic, ipAddr, gateway string, underlayGateway, verbose bool, maxRetry int) error {
ips := strings.Split(ipAddr, ",")
for i, gw := range strings.Split(gateway, ",") {
src := strings.Split(ips[i], "/")[0]
if underlayGateway && util.CheckProtocol(gw) == kubeovnv1.ProtocolIPv4 {
// v4 underlay gateway check use arping
mac, count, err := util.ArpResolve(nic, src, gw, time.Second, maxRetry)
cniConnectivityResult.WithLabelValues(nodeName).Add(float64(count))
if err != nil {
Expand All @@ -395,7 +420,9 @@ func waitNetworkReady(nic, ipAddr, gateway string, underlayGateway, verbose bool
klog.Infof("network %s with gateway %s is ready for interface %s after %d checks", ips[i], gw, nic, count)
}
} else {
// v6 or vpc gateway check use ping
if err := pingGateway(gw, src, verbose, maxRetry); err != nil {
klog.Error(err)
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/request/cniserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (csc CniServerClient) Add(podRequest CniRequest) (*CniResponse, error) {
return nil, errors[0]
}
if res.StatusCode != 200 {
return nil, fmt.Errorf("request ip return %d %s", res.StatusCode, resp.Err)
return nil, fmt.Errorf("request ip return %d, %s", res.StatusCode, resp.Err)
}
return &resp, nil
}
Expand Down
Loading