Merge pull request #82508 from aanm/fix-get-pod-ip-panic

dockershim/network: fix panic for cni plugins in IPv4/IPv6 dual-stack mode
This commit is contained in:
Kubernetes Prow Robot 2019-09-17 19:43:32 -07:00 committed by GitHub
commit cfa3e2c499
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View File

@ -74,6 +74,10 @@ func (plugin *cniNetworkPlugin) GetPodNetworkStatus(namespace string, name strin
return nil, err
}
if len(ips) == 0 {
return nil, fmt.Errorf("cannot find pod IPs in the network namespace, skipping pod network status for container %q", id)
}
return &network.PodNetworkStatus{
IP: ips[0],
IPs: ips,

View File

@ -271,18 +271,20 @@ func GetPodIPs(execer utilexec.Interface, nsenterPath, netnsPath, interfaceName
return []net.IP{ip}, nil
}
list := make([]net.IP, 0)
var err4, err6 error
if ipv4, err4 := getOnePodIP(execer, nsenterPath, netnsPath, interfaceName, "-4"); err4 != nil {
list = append(list, ipv4)
}
if ipv6, err6 := getOnePodIP(execer, nsenterPath, netnsPath, interfaceName, "-6"); err6 != nil {
list = append(list, ipv6)
var (
list []net.IP
errs []error
)
for _, addrType := range []string{"-4", "-6"} {
if ip, err := getOnePodIP(execer, nsenterPath, netnsPath, interfaceName, addrType); err == nil {
list = append(list, ip)
} else {
errs = append(errs, err)
}
}
if len(list) == 0 {
return nil, utilerrors.NewAggregate([]error{err4, err6})
return nil, utilerrors.NewAggregate(errs)
}
return list, nil