Skip to content

Commit

Permalink
fix: response has no gw when create nic without default route (#1703)
Browse files Browse the repository at this point in the history
  • Loading branch information
xujunjie-cover committed Jul 18, 2022
1 parent b52655f commit c9d9923
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ func generateCNIResult(cniResponse *request.CniResponse) current.Result {
result.Interfaces = []*current.Interface{&podIface}
case kubeovnv1.ProtocolDual:
var netMask *net.IPNet
var gwStr string
for _, cidrBlock := range strings.Split(cniResponse.CIDR, ",") {
_, netMask, _ = net.ParseCIDR(cidrBlock)
gwStr = ""
if util.CheckProtocol(cidrBlock) == kubeovnv1.ProtocolIPv4 {
ipStr := strings.Split(cniResponse.IpAddress, ",")[0]
gwStr := strings.Split(cniResponse.Gateway, ",")[0]
if cniResponse.Gateway != "" {
gwStr = strings.Split(cniResponse.Gateway, ",")[0]
}

ip, route := assignV4Address(ipStr, gwStr, netMask)
result.IPs = append(result.IPs, ip)
Expand All @@ -109,7 +113,9 @@ func generateCNIResult(cniResponse *request.CniResponse) current.Result {
}
} else if util.CheckProtocol(cidrBlock) == kubeovnv1.ProtocolIPv6 {
ipStr := strings.Split(cniResponse.IpAddress, ",")[1]
gwStr := strings.Split(cniResponse.Gateway, ",")[1]
if cniResponse.Gateway != "" {
gwStr = strings.Split(cniResponse.Gateway, ",")[1]
}

ip, route := assignV6Address(ipStr, gwStr, netMask)
result.IPs = append(result.IPs, ip)
Expand Down

0 comments on commit c9d9923

Please sign in to comment.