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

dockershim/network: fix panic for cni plugins in IPv4/IPv6 dual-stack mode #82508

Merged
merged 1 commit into from Sep 18, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/kubelet/dockershim/network/cni/cni_others.go
Expand Up @@ -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,
Expand Down
20 changes: 11 additions & 9 deletions pkg/kubelet/dockershim/network/plugins.go
Expand Up @@ -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

Expand Down