mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-20 17:38:50 +00:00
run hack/update-netparse-cve.sh
This commit is contained in:
@@ -37,7 +37,7 @@ import (
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
utilnet "k8s.io/utils/net"
|
||||
netutils "k8s.io/utils/net"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -103,7 +103,7 @@ func GetNodeHostIPs(node *v1.Node) ([]net.IP, error) {
|
||||
allIPs := make([]net.IP, 0, len(node.Status.Addresses))
|
||||
for _, addr := range node.Status.Addresses {
|
||||
if addr.Type == v1.NodeInternalIP {
|
||||
ip := net.ParseIP(addr.Address)
|
||||
ip := netutils.ParseIPSloppy(addr.Address)
|
||||
if ip != nil {
|
||||
allIPs = append(allIPs, ip)
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func GetNodeHostIPs(node *v1.Node) ([]net.IP, error) {
|
||||
}
|
||||
for _, addr := range node.Status.Addresses {
|
||||
if addr.Type == v1.NodeExternalIP {
|
||||
ip := net.ParseIP(addr.Address)
|
||||
ip := netutils.ParseIPSloppy(addr.Address)
|
||||
if ip != nil {
|
||||
allIPs = append(allIPs, ip)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func GetNodeHostIPs(node *v1.Node) ([]net.IP, error) {
|
||||
nodeIPs := []net.IP{allIPs[0]}
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.IPv6DualStack) {
|
||||
for _, ip := range allIPs {
|
||||
if utilnet.IsIPv6(ip) != utilnet.IsIPv6(nodeIPs[0]) {
|
||||
if netutils.IsIPv6(ip) != netutils.IsIPv6(nodeIPs[0]) {
|
||||
nodeIPs = append(nodeIPs, ip)
|
||||
break
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ import (
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
netutils "k8s.io/utils/net"
|
||||
)
|
||||
|
||||
func TestGetPreferredAddress(t *testing.T) {
|
||||
@@ -120,7 +121,7 @@ func TestGetNodeHostIPs(t *testing.T) {
|
||||
{Type: v1.NodeExternalIP, Address: "4.3.2.1"},
|
||||
{Type: v1.NodeExternalIP, Address: "4.3.2.2"},
|
||||
},
|
||||
expectIPs: []net.IP{net.ParseIP("1.2.3.4")},
|
||||
expectIPs: []net.IP{netutils.ParseIPSloppy("1.2.3.4")},
|
||||
},
|
||||
{
|
||||
name: "IPv4-only, external-first",
|
||||
@@ -129,7 +130,7 @@ func TestGetNodeHostIPs(t *testing.T) {
|
||||
{Type: v1.NodeExternalIP, Address: "4.3.2.2"},
|
||||
{Type: v1.NodeInternalIP, Address: "1.2.3.4"},
|
||||
},
|
||||
expectIPs: []net.IP{net.ParseIP("1.2.3.4")},
|
||||
expectIPs: []net.IP{netutils.ParseIPSloppy("1.2.3.4")},
|
||||
},
|
||||
{
|
||||
name: "IPv4-only, no internal",
|
||||
@@ -137,7 +138,7 @@ func TestGetNodeHostIPs(t *testing.T) {
|
||||
{Type: v1.NodeExternalIP, Address: "4.3.2.1"},
|
||||
{Type: v1.NodeExternalIP, Address: "4.3.2.2"},
|
||||
},
|
||||
expectIPs: []net.IP{net.ParseIP("4.3.2.1")},
|
||||
expectIPs: []net.IP{netutils.ParseIPSloppy("4.3.2.1")},
|
||||
},
|
||||
{
|
||||
name: "dual-stack node, single-stack cluster",
|
||||
@@ -148,7 +149,7 @@ func TestGetNodeHostIPs(t *testing.T) {
|
||||
{Type: v1.NodeInternalIP, Address: "a:b::c:d"},
|
||||
{Type: v1.NodeExternalIP, Address: "d:c::b:a"},
|
||||
},
|
||||
expectIPs: []net.IP{net.ParseIP("1.2.3.4")},
|
||||
expectIPs: []net.IP{netutils.ParseIPSloppy("1.2.3.4")},
|
||||
},
|
||||
{
|
||||
name: "dual-stack node, dual-stack cluster",
|
||||
@@ -160,7 +161,7 @@ func TestGetNodeHostIPs(t *testing.T) {
|
||||
{Type: v1.NodeExternalIP, Address: "d:c::b:a"},
|
||||
},
|
||||
dualStack: true,
|
||||
expectIPs: []net.IP{net.ParseIP("1.2.3.4"), net.ParseIP("a:b::c:d")},
|
||||
expectIPs: []net.IP{netutils.ParseIPSloppy("1.2.3.4"), netutils.ParseIPSloppy("a:b::c:d")},
|
||||
},
|
||||
{
|
||||
name: "dual-stack node, different order, single-stack cluster",
|
||||
@@ -171,7 +172,7 @@ func TestGetNodeHostIPs(t *testing.T) {
|
||||
{Type: v1.NodeExternalIP, Address: "4.3.2.2"},
|
||||
{Type: v1.NodeExternalIP, Address: "d:c::b:a"},
|
||||
},
|
||||
expectIPs: []net.IP{net.ParseIP("1.2.3.4")},
|
||||
expectIPs: []net.IP{netutils.ParseIPSloppy("1.2.3.4")},
|
||||
},
|
||||
{
|
||||
name: "dual-stack node, different order, dual-stack cluster",
|
||||
@@ -183,7 +184,7 @@ func TestGetNodeHostIPs(t *testing.T) {
|
||||
{Type: v1.NodeExternalIP, Address: "d:c::b:a"},
|
||||
},
|
||||
dualStack: true,
|
||||
expectIPs: []net.IP{net.ParseIP("1.2.3.4"), net.ParseIP("a:b::c:d")},
|
||||
expectIPs: []net.IP{netutils.ParseIPSloppy("1.2.3.4"), netutils.ParseIPSloppy("a:b::c:d")},
|
||||
},
|
||||
{
|
||||
name: "dual-stack node, IPv6-first, no internal IPv4, single-stack cluster",
|
||||
@@ -193,7 +194,7 @@ func TestGetNodeHostIPs(t *testing.T) {
|
||||
{Type: v1.NodeExternalIP, Address: "4.3.2.1"},
|
||||
{Type: v1.NodeExternalIP, Address: "4.3.2.2"},
|
||||
},
|
||||
expectIPs: []net.IP{net.ParseIP("a:b::c:d")},
|
||||
expectIPs: []net.IP{netutils.ParseIPSloppy("a:b::c:d")},
|
||||
},
|
||||
{
|
||||
name: "dual-stack node, IPv6-first, no internal IPv4, dual-stack cluster",
|
||||
@@ -204,7 +205,7 @@ func TestGetNodeHostIPs(t *testing.T) {
|
||||
{Type: v1.NodeExternalIP, Address: "4.3.2.2"},
|
||||
},
|
||||
dualStack: true,
|
||||
expectIPs: []net.IP{net.ParseIP("a:b::c:d"), net.ParseIP("4.3.2.1")},
|
||||
expectIPs: []net.IP{netutils.ParseIPSloppy("a:b::c:d"), netutils.ParseIPSloppy("4.3.2.1")},
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user