@@ -22,6 +22,7 @@ import (
22
22
goerrors "errors"
23
23
"fmt"
24
24
"io"
25
+ "net"
25
26
"net/http"
26
27
"net/url"
27
28
"os"
@@ -1988,23 +1989,27 @@ func (kl *Kubelet) generateAPIPodStatus(pod *v1.Pod, podStatus *kubecontainer.Po
1988
1989
// and use them for the Pod.Status.PodIPs and the Downward API environment variables
1989
1990
func (kl * Kubelet ) sortPodIPs (podIPs []string ) []string {
1990
1991
ips := make ([]string , 0 , 2 )
1991
- var validPrimaryIP , validSecondaryIP func (ip string ) bool
1992
+ var validPrimaryIP , validSecondaryIP func (ip net. IP ) bool
1992
1993
if len (kl .nodeIPs ) == 0 || utilnet .IsIPv4 (kl .nodeIPs [0 ]) {
1993
- validPrimaryIP = utilnet .IsIPv4String
1994
- validSecondaryIP = utilnet .IsIPv6String
1994
+ validPrimaryIP = utilnet .IsIPv4
1995
+ validSecondaryIP = utilnet .IsIPv6
1995
1996
} else {
1996
- validPrimaryIP = utilnet .IsIPv6String
1997
- validSecondaryIP = utilnet .IsIPv4String
1997
+ validPrimaryIP = utilnet .IsIPv6
1998
+ validSecondaryIP = utilnet .IsIPv4
1998
1999
}
1999
- for _ , ip := range podIPs {
2000
+
2001
+ // We parse and re-stringify the IPs in case the values from CRI use an irregular format.
2002
+ for _ , ipStr := range podIPs {
2003
+ ip := utilnet .ParseIPSloppy (ipStr )
2000
2004
if validPrimaryIP (ip ) {
2001
- ips = append (ips , ip )
2005
+ ips = append (ips , ip . String () )
2002
2006
break
2003
2007
}
2004
2008
}
2005
- for _ , ip := range podIPs {
2009
+ for _ , ipStr := range podIPs {
2010
+ ip := utilnet .ParseIPSloppy (ipStr )
2006
2011
if validSecondaryIP (ip ) {
2007
- ips = append (ips , ip )
2012
+ ips = append (ips , ip . String () )
2008
2013
break
2009
2014
}
2010
2015
}
0 commit comments