Skip to content

Commit 8b6f5dd

Browse files
authored
Merge pull request kubernetes#90001 from chendotjs/automated-cherry-pick-of-#82508-upstream-release-1.16
Automated cherry pick of kubernetes#82508: dockershim/network: fix panic for cni plugins in IPv4/IPv6 dual-stack mode
2 parents e3a38cb + e813a45 commit 8b6f5dd

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

pkg/kubelet/dockershim/network/cni/cni_others.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ func (plugin *cniNetworkPlugin) GetPodNetworkStatus(namespace string, name strin
7474
return nil, err
7575
}
7676

77+
if len(ips) == 0 {
78+
return nil, fmt.Errorf("cannot find pod IPs in the network namespace, skipping pod network status for container %q", id)
79+
}
80+
7781
return &network.PodNetworkStatus{
7882
IP: ips[0],
7983
IPs: ips,

pkg/kubelet/dockershim/network/plugins.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,20 @@ func GetPodIPs(execer utilexec.Interface, nsenterPath, netnsPath, interfaceName
271271
return []net.IP{ip}, nil
272272
}
273273

274-
list := make([]net.IP, 0)
275-
var err4, err6 error
276-
if ipv4, err4 := getOnePodIP(execer, nsenterPath, netnsPath, interfaceName, "-4"); err4 != nil {
277-
list = append(list, ipv4)
278-
}
279-
280-
if ipv6, err6 := getOnePodIP(execer, nsenterPath, netnsPath, interfaceName, "-6"); err6 != nil {
281-
list = append(list, ipv6)
274+
var (
275+
list []net.IP
276+
errs []error
277+
)
278+
for _, addrType := range []string{"-4", "-6"} {
279+
if ip, err := getOnePodIP(execer, nsenterPath, netnsPath, interfaceName, addrType); err == nil {
280+
list = append(list, ip)
281+
} else {
282+
errs = append(errs, err)
283+
}
282284
}
283285

284286
if len(list) == 0 {
285-
return nil, utilerrors.NewAggregate([]error{err4, err6})
287+
return nil, utilerrors.NewAggregate(errs)
286288
}
287289
return list, nil
288290

0 commit comments

Comments
 (0)