Skip to content

Commit

Permalink
clean up legacy u2o implement (#2248)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Jan 18, 2023
1 parent 5e684e9 commit 486e8ee
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 59 deletions.
2 changes: 0 additions & 2 deletions dist/images/install.sh
Expand Up @@ -1412,8 +1412,6 @@ spec:
type: string
natOutgoing:
type: boolean
u2oRouting:
type: boolean
externalEgressGateway:
type: string
policyRoutingPriority:
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/kubeovn/v1/types.go
Expand Up @@ -113,7 +113,6 @@ type SubnetSpec struct {
GatewayType string `json:"gatewayType,omitempty"`
GatewayNode string `json:"gatewayNode"`
NatOutgoing bool `json:"natOutgoing"`
U2oRouting bool `json:"u2oRouting,omitempty"`

ExternalEgressGateway string `json:"externalEgressGateway,omitempty"`
PolicyRoutingPriority uint32 `json:"policyRoutingPriority,omitempty"`
Expand Down
58 changes: 5 additions & 53 deletions pkg/daemon/handler.go
Expand Up @@ -229,9 +229,9 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
}

var mtu int
var node *v1.Node
if providerNetwork != "" {
if node, err = csh.Controller.nodesLister.Get(csh.Config.NodeName); err != nil {
node, err := csh.Controller.nodesLister.Get(csh.Config.NodeName)
if err != nil {
errMsg := fmt.Errorf("failed to get node %s: %v", csh.Config.NodeName, err)
klog.Error(errMsg)
if err = resp.WriteHeaderAndEntity(http.StatusInternalServerError, request.CniResponse{Err: errMsg.Error()}); err != nil {
Expand All @@ -254,63 +254,15 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
mtu = csh.Config.MTU
}

// routes used for access from underlay to overlay
var u2oRoutes []request.Route
if podSubnet.Spec.U2oRouting && podSubnet.Spec.Vlan != "" &&
!podSubnet.Spec.LogicalGateway && podSubnet.Spec.Vpc == util.DefaultVpc {
subnets, err := csh.Controller.subnetsLister.List(labels.Everything())
if err != nil {
errMsg := fmt.Errorf("failed to list subnets: %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)
}
return
}

if node == nil {
if node, err = csh.Controller.nodesLister.Get(csh.Config.NodeName); err != nil {
errMsg := fmt.Errorf("failed to get node %s: %v", csh.Config.NodeName, 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)
}
return
}
}

podCidrV4, podCidrV6 := util.SplitStringIP(cidr)
nodeIPv4, nodeIPv6 := util.GetNodeInternalIP(*node)
v4Routing := util.CIDRContainIP(podCidrV4, nodeIPv4)
v6Routing := util.CIDRContainIP(podCidrV6, nodeIPv6)
for _, subnet := range subnets {
if subnet.Spec.Vpc == util.DefaultVpc && (subnet.Spec.Vlan == "" || subnet.Spec.LogicalGateway) {
if !subnet.Status.IsReady() {
klog.V(5).Infof("subnet %s is not ready, skip", subnet.Name)
continue
}

cidrV4, cidrV6 := util.SplitStringIP(subnet.Spec.CIDRBlock)
if v4Routing && cidrV4 != "" {
u2oRoutes = append(u2oRoutes, request.Route{Destination: cidrV4, Gateway: nodeIPv4})
}
if v6Routing && cidrV6 != "" {
u2oRoutes = append(u2oRoutes, request.Route{Destination: cidrV6, Gateway: nodeIPv6})
}
}
}
}

klog.Infof("create container interface %s mac %s, ip %s, cidr %s, gw %s, u2o routes %v, custom routes %v", ifName, macAddr, ipAddr, cidr, gw, u2oRoutes, podRequest.Routes)
klog.Infof("create container interface %s mac %s, ip %s, cidr %s, gw %s, custom routes %v", ifName, macAddr, ipAddr, cidr, gw, podRequest.Routes)
detectIPConflict := podSubnet.Spec.Vlan != ""
allRoutes := append(u2oRoutes, podRequest.Routes...)
if nicType == util.InternalType {
podNicName, err = csh.configureNicWithInternalPort(podRequest.PodName, podRequest.PodNamespace, podRequest.Provider, podRequest.NetNs, podRequest.ContainerID, ifName, macAddr, mtu, ipAddr, gw, isDefaultRoute, detectIPConflict, allRoutes, podRequest.DNS.Nameservers, podRequest.DNS.Search, ingress, egress, priority, podRequest.DeviceID, nicType, latency, limit, loss, gatewayCheckMode, u2oInterconnectionIP)
podNicName, err = csh.configureNicWithInternalPort(podRequest.PodName, podRequest.PodNamespace, podRequest.Provider, podRequest.NetNs, podRequest.ContainerID, ifName, macAddr, mtu, ipAddr, gw, isDefaultRoute, detectIPConflict, podRequest.Routes, podRequest.DNS.Nameservers, podRequest.DNS.Search, ingress, egress, priority, podRequest.DeviceID, nicType, latency, limit, loss, gatewayCheckMode, u2oInterconnectionIP)
} else if nicType == util.DpdkType {
err = csh.configureDpdkNic(podRequest.PodName, podRequest.PodNamespace, podRequest.Provider, podRequest.NetNs, podRequest.ContainerID, ifName, macAddr, mtu, ipAddr, gw, ingress, egress, priority, getShortSharedDir(pod.UID, podRequest.VhostUserSocketVolumeName), podRequest.VhostUserSocketName)
} else {
podNicName = ifName
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, priority, podRequest.DeviceID, nicType, latency, limit, loss, gatewayCheckMode, u2oInterconnectionIP)
err = csh.configureNic(podRequest.PodName, podRequest.PodNamespace, podRequest.Provider, podRequest.NetNs, podRequest.ContainerID, podRequest.VfDriver, ifName, macAddr, mtu, ipAddr, gw, isDefaultRoute, detectIPConflict, podRequest.Routes, podRequest.DNS.Nameservers, podRequest.DNS.Search, ingress, egress, priority, podRequest.DeviceID, nicType, latency, limit, loss, gatewayCheckMode, u2oInterconnectionIP)
}
if err != nil {
errMsg := fmt.Errorf("configure nic failed %v", err)
Expand Down
1 change: 0 additions & 1 deletion pkg/util/validator_test.go
Expand Up @@ -50,7 +50,6 @@ func TestValidateSubnet(t *testing.T) {
GatewayType: "distributed",
GatewayNode: "",
NatOutgoing: false,
U2oRouting: false,
ExternalEgressGateway: "",
PolicyRoutingPriority: 0,
PolicyRoutingTableID: 0,
Expand Down
2 changes: 0 additions & 2 deletions yamls/crd.yaml
Expand Up @@ -789,8 +789,6 @@ spec:
type: string
natOutgoing:
type: boolean
u2oRouting:
type: boolean
externalEgressGateway:
type: string
policyRoutingPriority:
Expand Down

0 comments on commit 486e8ee

Please sign in to comment.