mirror of https://github.com/k3s-io/k3s
Merge pull request #73645 from andrewsykim/remove-dep-node-addresses
move AddToNodeAddresses to k8s.io/cloud-provider/node/helperspull/564/head
commit
30566b990a
|
@ -280,23 +280,6 @@ func IsStandardFinalizerName(str string) bool {
|
||||||
return standardFinalizers.Has(str)
|
return standardFinalizers.Has(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddToNodeAddresses appends the NodeAddresses to the passed-by-pointer slice,
|
|
||||||
// only if they do not already exist
|
|
||||||
func AddToNodeAddresses(addresses *[]core.NodeAddress, addAddresses ...core.NodeAddress) {
|
|
||||||
for _, add := range addAddresses {
|
|
||||||
exists := false
|
|
||||||
for _, existing := range *addresses {
|
|
||||||
if existing.Address == add.Address && existing.Type == add.Type {
|
|
||||||
exists = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !exists {
|
|
||||||
*addresses = append(*addresses, add)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: make method on LoadBalancerStatus?
|
// TODO: make method on LoadBalancerStatus?
|
||||||
func LoadBalancerStatusEqual(l, r *core.LoadBalancerStatus) bool {
|
func LoadBalancerStatusEqual(l, r *core.LoadBalancerStatus) bool {
|
||||||
return ingressSliceEqual(l.Ingress, r.Ingress)
|
return ingressSliceEqual(l.Ingress, r.Ingress)
|
||||||
|
|
|
@ -85,63 +85,6 @@ func TestIsStandardContainerResource(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddToNodeAddresses(t *testing.T) {
|
|
||||||
testCases := []struct {
|
|
||||||
existing []core.NodeAddress
|
|
||||||
toAdd []core.NodeAddress
|
|
||||||
expected []core.NodeAddress
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
existing: []core.NodeAddress{},
|
|
||||||
toAdd: []core.NodeAddress{},
|
|
||||||
expected: []core.NodeAddress{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
existing: []core.NodeAddress{},
|
|
||||||
toAdd: []core.NodeAddress{
|
|
||||||
{Type: core.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: core.NodeHostName, Address: "localhost"},
|
|
||||||
},
|
|
||||||
expected: []core.NodeAddress{
|
|
||||||
{Type: core.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: core.NodeHostName, Address: "localhost"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
existing: []core.NodeAddress{},
|
|
||||||
toAdd: []core.NodeAddress{
|
|
||||||
{Type: core.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: core.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
},
|
|
||||||
expected: []core.NodeAddress{
|
|
||||||
{Type: core.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
existing: []core.NodeAddress{
|
|
||||||
{Type: core.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: core.NodeInternalIP, Address: "10.1.1.1"},
|
|
||||||
},
|
|
||||||
toAdd: []core.NodeAddress{
|
|
||||||
{Type: core.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: core.NodeHostName, Address: "localhost"},
|
|
||||||
},
|
|
||||||
expected: []core.NodeAddress{
|
|
||||||
{Type: core.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: core.NodeInternalIP, Address: "10.1.1.1"},
|
|
||||||
{Type: core.NodeHostName, Address: "localhost"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, tc := range testCases {
|
|
||||||
AddToNodeAddresses(&tc.existing, tc.toAdd...)
|
|
||||||
if !Semantic.DeepEqual(tc.expected, tc.existing) {
|
|
||||||
t.Errorf("case[%d], expected: %v, got: %v", i, tc.expected, tc.existing)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetAccessModesFromString(t *testing.T) {
|
func TestGetAccessModesFromString(t *testing.T) {
|
||||||
modes := GetAccessModesFromString("ROX")
|
modes := GetAccessModesFromString("ROX")
|
||||||
if !containsAccessMode(modes, core.ReadOnlyMany) {
|
if !containsAccessMode(modes, core.ReadOnlyMany) {
|
||||||
|
|
|
@ -108,23 +108,6 @@ func IsServiceIPSet(service *v1.Service) bool {
|
||||||
return service.Spec.ClusterIP != v1.ClusterIPNone && service.Spec.ClusterIP != ""
|
return service.Spec.ClusterIP != v1.ClusterIPNone && service.Spec.ClusterIP != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddToNodeAddresses appends the NodeAddresses to the passed-by-pointer slice,
|
|
||||||
// only if they do not already exist
|
|
||||||
func AddToNodeAddresses(addresses *[]v1.NodeAddress, addAddresses ...v1.NodeAddress) {
|
|
||||||
for _, add := range addAddresses {
|
|
||||||
exists := false
|
|
||||||
for _, existing := range *addresses {
|
|
||||||
if existing.Address == add.Address && existing.Type == add.Type {
|
|
||||||
exists = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !exists {
|
|
||||||
*addresses = append(*addresses, add)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: make method on LoadBalancerStatus?
|
// TODO: make method on LoadBalancerStatus?
|
||||||
func LoadBalancerStatusEqual(l, r *v1.LoadBalancerStatus) bool {
|
func LoadBalancerStatusEqual(l, r *v1.LoadBalancerStatus) bool {
|
||||||
return ingressSliceEqual(l.Ingress, r.Ingress)
|
return ingressSliceEqual(l.Ingress, r.Ingress)
|
||||||
|
|
|
@ -147,63 +147,6 @@ func TestIsOvercommitAllowed(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddToNodeAddresses(t *testing.T) {
|
|
||||||
testCases := []struct {
|
|
||||||
existing []v1.NodeAddress
|
|
||||||
toAdd []v1.NodeAddress
|
|
||||||
expected []v1.NodeAddress
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
existing: []v1.NodeAddress{},
|
|
||||||
toAdd: []v1.NodeAddress{},
|
|
||||||
expected: []v1.NodeAddress{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
existing: []v1.NodeAddress{},
|
|
||||||
toAdd: []v1.NodeAddress{
|
|
||||||
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: v1.NodeHostName, Address: "localhost"},
|
|
||||||
},
|
|
||||||
expected: []v1.NodeAddress{
|
|
||||||
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: v1.NodeHostName, Address: "localhost"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
existing: []v1.NodeAddress{},
|
|
||||||
toAdd: []v1.NodeAddress{
|
|
||||||
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
},
|
|
||||||
expected: []v1.NodeAddress{
|
|
||||||
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
existing: []v1.NodeAddress{
|
|
||||||
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: v1.NodeInternalIP, Address: "10.1.1.1"},
|
|
||||||
},
|
|
||||||
toAdd: []v1.NodeAddress{
|
|
||||||
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: v1.NodeHostName, Address: "localhost"},
|
|
||||||
},
|
|
||||||
expected: []v1.NodeAddress{
|
|
||||||
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
|
||||||
{Type: v1.NodeInternalIP, Address: "10.1.1.1"},
|
|
||||||
{Type: v1.NodeHostName, Address: "localhost"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, tc := range testCases {
|
|
||||||
AddToNodeAddresses(&tc.existing, tc.toAdd...)
|
|
||||||
if !apiequality.Semantic.DeepEqual(tc.expected, tc.existing) {
|
|
||||||
t.Errorf("case[%d], expected: %v, got: %v", i, tc.expected, tc.existing)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetAccessModesFromString(t *testing.T) {
|
func TestGetAccessModesFromString(t *testing.T) {
|
||||||
modes := GetAccessModesFromString("ROX")
|
modes := GetAccessModesFromString("ROX")
|
||||||
if !containsAccessMode(modes, v1.ReadOnlyMany) {
|
if !containsAccessMode(modes, v1.ReadOnlyMany) {
|
||||||
|
|
|
@ -21,7 +21,6 @@ go_library(
|
||||||
importpath = "k8s.io/kubernetes/pkg/cloudprovider/providers/openstack",
|
importpath = "k8s.io/kubernetes/pkg/cloudprovider/providers/openstack",
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/api/v1/service:go_default_library",
|
"//pkg/api/v1/service:go_default_library",
|
||||||
"//pkg/apis/core/v1/helper:go_default_library",
|
|
||||||
"//pkg/kubelet/apis:go_default_library",
|
"//pkg/kubelet/apis:go_default_library",
|
||||||
"//pkg/util/mount:go_default_library",
|
"//pkg/util/mount:go_default_library",
|
||||||
"//pkg/volume:go_default_library",
|
"//pkg/volume:go_default_library",
|
||||||
|
@ -34,6 +33,7 @@ go_library(
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/util/cert:go_default_library",
|
"//staging/src/k8s.io/client-go/util/cert:go_default_library",
|
||||||
"//staging/src/k8s.io/cloud-provider:go_default_library",
|
"//staging/src/k8s.io/cloud-provider:go_default_library",
|
||||||
|
"//staging/src/k8s.io/cloud-provider/node/helpers:go_default_library",
|
||||||
"//vendor/github.com/gophercloud/gophercloud:go_default_library",
|
"//vendor/github.com/gophercloud/gophercloud:go_default_library",
|
||||||
"//vendor/github.com/gophercloud/gophercloud/openstack:go_default_library",
|
"//vendor/github.com/gophercloud/gophercloud/openstack:go_default_library",
|
||||||
"//vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions:go_default_library",
|
"//vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions:go_default_library",
|
||||||
|
|
|
@ -46,8 +46,8 @@ import (
|
||||||
netutil "k8s.io/apimachinery/pkg/util/net"
|
netutil "k8s.io/apimachinery/pkg/util/net"
|
||||||
certutil "k8s.io/client-go/util/cert"
|
certutil "k8s.io/client-go/util/cert"
|
||||||
cloudprovider "k8s.io/cloud-provider"
|
cloudprovider "k8s.io/cloud-provider"
|
||||||
|
nodehelpers "k8s.io/cloud-provider/node/helpers"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -476,7 +476,7 @@ func nodeAddresses(srv *servers.Server) ([]v1.NodeAddress, error) {
|
||||||
addressType = v1.NodeInternalIP
|
addressType = v1.NodeInternalIP
|
||||||
}
|
}
|
||||||
|
|
||||||
v1helper.AddToNodeAddresses(&addrs,
|
nodehelpers.AddToNodeAddresses(&addrs,
|
||||||
v1.NodeAddress{
|
v1.NodeAddress{
|
||||||
Type: addressType,
|
Type: addressType,
|
||||||
Address: props.Addr,
|
Address: props.Addr,
|
||||||
|
@ -487,7 +487,7 @@ func nodeAddresses(srv *servers.Server) ([]v1.NodeAddress, error) {
|
||||||
|
|
||||||
// AccessIPs are usually duplicates of "public" addresses.
|
// AccessIPs are usually duplicates of "public" addresses.
|
||||||
if srv.AccessIPv4 != "" {
|
if srv.AccessIPv4 != "" {
|
||||||
v1helper.AddToNodeAddresses(&addrs,
|
nodehelpers.AddToNodeAddresses(&addrs,
|
||||||
v1.NodeAddress{
|
v1.NodeAddress{
|
||||||
Type: v1.NodeExternalIP,
|
Type: v1.NodeExternalIP,
|
||||||
Address: srv.AccessIPv4,
|
Address: srv.AccessIPv4,
|
||||||
|
@ -496,7 +496,7 @@ func nodeAddresses(srv *servers.Server) ([]v1.NodeAddress, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if srv.AccessIPv6 != "" {
|
if srv.AccessIPv6 != "" {
|
||||||
v1helper.AddToNodeAddresses(&addrs,
|
nodehelpers.AddToNodeAddresses(&addrs,
|
||||||
v1.NodeAddress{
|
v1.NodeAddress{
|
||||||
Type: v1.NodeExternalIP,
|
Type: v1.NodeExternalIP,
|
||||||
Address: srv.AccessIPv6,
|
Address: srv.AccessIPv6,
|
||||||
|
@ -505,7 +505,7 @@ func nodeAddresses(srv *servers.Server) ([]v1.NodeAddress, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if srv.Metadata[TypeHostName] != "" {
|
if srv.Metadata[TypeHostName] != "" {
|
||||||
v1helper.AddToNodeAddresses(&addrs,
|
nodehelpers.AddToNodeAddresses(&addrs,
|
||||||
v1.NodeAddress{
|
v1.NodeAddress{
|
||||||
Type: v1.NodeHostName,
|
Type: v1.NodeHostName,
|
||||||
Address: srv.Metadata[TypeHostName],
|
Address: srv.Metadata[TypeHostName],
|
||||||
|
|
|
@ -11,10 +11,10 @@ go_library(
|
||||||
srcs = ["photon.go"],
|
srcs = ["photon.go"],
|
||||||
importpath = "k8s.io/kubernetes/pkg/cloudprovider/providers/photon",
|
importpath = "k8s.io/kubernetes/pkg/cloudprovider/providers/photon",
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/apis/core/v1/helper:go_default_library",
|
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||||
"//staging/src/k8s.io/cloud-provider:go_default_library",
|
"//staging/src/k8s.io/cloud-provider:go_default_library",
|
||||||
|
"//staging/src/k8s.io/cloud-provider/node/helpers:go_default_library",
|
||||||
"//vendor/github.com/vmware/photon-controller-go-sdk/photon:go_default_library",
|
"//vendor/github.com/vmware/photon-controller-go-sdk/photon:go_default_library",
|
||||||
"//vendor/gopkg.in/gcfg.v1:go_default_library",
|
"//vendor/gopkg.in/gcfg.v1:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
|
|
|
@ -39,8 +39,8 @@ import (
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
k8stypes "k8s.io/apimachinery/pkg/types"
|
k8stypes "k8s.io/apimachinery/pkg/types"
|
||||||
cloudprovider "k8s.io/cloud-provider"
|
cloudprovider "k8s.io/cloud-provider"
|
||||||
|
nodehelpers "k8s.io/cloud-provider/node/helpers"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -326,14 +326,14 @@ func (pc *PCCloud) NodeAddresses(ctx context.Context, nodeName k8stypes.NodeName
|
||||||
// Filter external IP by MAC address OUIs from vCenter and from ESX
|
// Filter external IP by MAC address OUIs from vCenter and from ESX
|
||||||
if strings.HasPrefix(i.HardwareAddr.String(), MAC_OUI_VC) ||
|
if strings.HasPrefix(i.HardwareAddr.String(), MAC_OUI_VC) ||
|
||||||
strings.HasPrefix(i.HardwareAddr.String(), MAC_OUI_ESX) {
|
strings.HasPrefix(i.HardwareAddr.String(), MAC_OUI_ESX) {
|
||||||
v1helper.AddToNodeAddresses(&nodeAddrs,
|
nodehelpers.AddToNodeAddresses(&nodeAddrs,
|
||||||
v1.NodeAddress{
|
v1.NodeAddress{
|
||||||
Type: v1.NodeExternalIP,
|
Type: v1.NodeExternalIP,
|
||||||
Address: ipnet.IP.String(),
|
Address: ipnet.IP.String(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
v1helper.AddToNodeAddresses(&nodeAddrs,
|
nodehelpers.AddToNodeAddresses(&nodeAddrs,
|
||||||
v1.NodeAddress{
|
v1.NodeAddress{
|
||||||
Type: v1.NodeInternalIP,
|
Type: v1.NodeInternalIP,
|
||||||
Address: ipnet.IP.String(),
|
Address: ipnet.IP.String(),
|
||||||
|
@ -396,14 +396,14 @@ func (pc *PCCloud) NodeAddresses(ctx context.Context, nodeName k8stypes.NodeName
|
||||||
if ipAddr != "-" {
|
if ipAddr != "-" {
|
||||||
if strings.HasPrefix(macAddr, MAC_OUI_VC) ||
|
if strings.HasPrefix(macAddr, MAC_OUI_VC) ||
|
||||||
strings.HasPrefix(macAddr, MAC_OUI_ESX) {
|
strings.HasPrefix(macAddr, MAC_OUI_ESX) {
|
||||||
v1helper.AddToNodeAddresses(&nodeAddrs,
|
nodehelpers.AddToNodeAddresses(&nodeAddrs,
|
||||||
v1.NodeAddress{
|
v1.NodeAddress{
|
||||||
Type: v1.NodeExternalIP,
|
Type: v1.NodeExternalIP,
|
||||||
Address: ipAddr,
|
Address: ipAddr,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
v1helper.AddToNodeAddresses(&nodeAddrs,
|
nodehelpers.AddToNodeAddresses(&nodeAddrs,
|
||||||
v1.NodeAddress{
|
v1.NodeAddress{
|
||||||
Type: v1.NodeInternalIP,
|
Type: v1.NodeInternalIP,
|
||||||
Address: ipAddr,
|
Address: ipAddr,
|
||||||
|
|
|
@ -16,7 +16,6 @@ go_library(
|
||||||
],
|
],
|
||||||
importpath = "k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere",
|
importpath = "k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere",
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/apis/core/v1/helper:go_default_library",
|
|
||||||
"//pkg/cloudprovider/providers/vsphere/vclib:go_default_library",
|
"//pkg/cloudprovider/providers/vsphere/vclib:go_default_library",
|
||||||
"//pkg/cloudprovider/providers/vsphere/vclib/diskmanagers:go_default_library",
|
"//pkg/cloudprovider/providers/vsphere/vclib/diskmanagers:go_default_library",
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
|
@ -27,6 +26,7 @@ go_library(
|
||||||
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
|
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
|
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
|
||||||
"//staging/src/k8s.io/cloud-provider:go_default_library",
|
"//staging/src/k8s.io/cloud-provider:go_default_library",
|
||||||
|
"//staging/src/k8s.io/cloud-provider/node/helpers:go_default_library",
|
||||||
"//vendor/github.com/vmware/govmomi/vapi/rest:go_default_library",
|
"//vendor/github.com/vmware/govmomi/vapi/rest:go_default_library",
|
||||||
"//vendor/github.com/vmware/govmomi/vapi/tags:go_default_library",
|
"//vendor/github.com/vmware/govmomi/vapi/tags:go_default_library",
|
||||||
"//vendor/github.com/vmware/govmomi/vim25:go_default_library",
|
"//vendor/github.com/vmware/govmomi/vim25:go_default_library",
|
||||||
|
|
|
@ -41,8 +41,8 @@ import (
|
||||||
"k8s.io/client-go/informers"
|
"k8s.io/client-go/informers"
|
||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
cloudprovider "k8s.io/cloud-provider"
|
cloudprovider "k8s.io/cloud-provider"
|
||||||
|
nodehelpers "k8s.io/cloud-provider/node/helpers"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere/vclib"
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere/vclib"
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere/vclib/diskmanagers"
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere/vclib/diskmanagers"
|
||||||
)
|
)
|
||||||
|
@ -551,7 +551,7 @@ func getLocalIP() ([]v1.NodeAddress, error) {
|
||||||
var addressType v1.NodeAddressType
|
var addressType v1.NodeAddressType
|
||||||
if strings.HasPrefix(i.HardwareAddr.String(), MacOuiVC) ||
|
if strings.HasPrefix(i.HardwareAddr.String(), MacOuiVC) ||
|
||||||
strings.HasPrefix(i.HardwareAddr.String(), MacOuiEsx) {
|
strings.HasPrefix(i.HardwareAddr.String(), MacOuiEsx) {
|
||||||
v1helper.AddToNodeAddresses(&addrs,
|
nodehelpers.AddToNodeAddresses(&addrs,
|
||||||
v1.NodeAddress{
|
v1.NodeAddress{
|
||||||
Type: v1.NodeExternalIP,
|
Type: v1.NodeExternalIP,
|
||||||
Address: ipnet.IP.String(),
|
Address: ipnet.IP.String(),
|
||||||
|
@ -614,7 +614,7 @@ func (vs *VSphere) NodeAddresses(ctx context.Context, nodeName k8stypes.NodeName
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// add the hostname address
|
// add the hostname address
|
||||||
v1helper.AddToNodeAddresses(&addrs, v1.NodeAddress{Type: v1.NodeHostName, Address: vs.hostName})
|
nodehelpers.AddToNodeAddresses(&addrs, v1.NodeAddress{Type: v1.NodeHostName, Address: vs.hostName})
|
||||||
return addrs, nil
|
return addrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,7 +652,7 @@ func (vs *VSphere) NodeAddresses(ctx context.Context, nodeName k8stypes.NodeName
|
||||||
if vs.cfg.Network.PublicNetwork == v.Network {
|
if vs.cfg.Network.PublicNetwork == v.Network {
|
||||||
for _, ip := range v.IpAddress {
|
for _, ip := range v.IpAddress {
|
||||||
if net.ParseIP(ip).To4() != nil {
|
if net.ParseIP(ip).To4() != nil {
|
||||||
v1helper.AddToNodeAddresses(&addrs,
|
nodehelpers.AddToNodeAddresses(&addrs,
|
||||||
v1.NodeAddress{
|
v1.NodeAddress{
|
||||||
Type: v1.NodeExternalIP,
|
Type: v1.NodeExternalIP,
|
||||||
Address: ip,
|
Address: ip,
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = ["taints.go"],
|
srcs = [
|
||||||
|
"address.go",
|
||||||
|
"taints.go",
|
||||||
|
],
|
||||||
importmap = "k8s.io/kubernetes/vendor/k8s.io/cloud-provider/node/helpers",
|
importmap = "k8s.io/kubernetes/vendor/k8s.io/cloud-provider/node/helpers",
|
||||||
importpath = "k8s.io/cloud-provider/node/helpers",
|
importpath = "k8s.io/cloud-provider/node/helpers",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
|
@ -31,3 +34,13 @@ filegroup(
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
go_test(
|
||||||
|
name = "go_default_test",
|
||||||
|
srcs = ["address_test.go"],
|
||||||
|
embed = [":go_default_library"],
|
||||||
|
deps = [
|
||||||
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package helpers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/api/core/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddToNodeAddresses appends the NodeAddresses to the passed-by-pointer slice,
|
||||||
|
// only if they do not already exist
|
||||||
|
func AddToNodeAddresses(addresses *[]v1.NodeAddress, addAddresses ...v1.NodeAddress) {
|
||||||
|
for _, add := range addAddresses {
|
||||||
|
exists := false
|
||||||
|
for _, existing := range *addresses {
|
||||||
|
if existing.Address == add.Address && existing.Type == add.Type {
|
||||||
|
exists = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
*addresses = append(*addresses, add)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package helpers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/api/core/v1"
|
||||||
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAddToNodeAddresses(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
existing []v1.NodeAddress
|
||||||
|
toAdd []v1.NodeAddress
|
||||||
|
expected []v1.NodeAddress
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "add no addresses to empty node addresses",
|
||||||
|
existing: []v1.NodeAddress{},
|
||||||
|
toAdd: []v1.NodeAddress{},
|
||||||
|
expected: []v1.NodeAddress{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "add new node addresses to empty existing addresses",
|
||||||
|
existing: []v1.NodeAddress{},
|
||||||
|
toAdd: []v1.NodeAddress{
|
||||||
|
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
||||||
|
{Type: v1.NodeHostName, Address: "localhost"},
|
||||||
|
},
|
||||||
|
expected: []v1.NodeAddress{
|
||||||
|
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
||||||
|
{Type: v1.NodeHostName, Address: "localhost"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "add a duplicate node address",
|
||||||
|
existing: []v1.NodeAddress{},
|
||||||
|
toAdd: []v1.NodeAddress{
|
||||||
|
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
||||||
|
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
||||||
|
},
|
||||||
|
expected: []v1.NodeAddress{
|
||||||
|
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "add 1 new and 1 duplicate address",
|
||||||
|
existing: []v1.NodeAddress{
|
||||||
|
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
||||||
|
{Type: v1.NodeInternalIP, Address: "10.1.1.1"},
|
||||||
|
},
|
||||||
|
toAdd: []v1.NodeAddress{
|
||||||
|
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
||||||
|
{Type: v1.NodeHostName, Address: "localhost"},
|
||||||
|
},
|
||||||
|
expected: []v1.NodeAddress{
|
||||||
|
{Type: v1.NodeExternalIP, Address: "1.1.1.1"},
|
||||||
|
{Type: v1.NodeInternalIP, Address: "10.1.1.1"},
|
||||||
|
{Type: v1.NodeHostName, Address: "localhost"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
AddToNodeAddresses(&tc.existing, tc.toAdd...)
|
||||||
|
if !apiequality.Semantic.DeepEqual(tc.expected, tc.existing) {
|
||||||
|
t.Errorf("expected: %v, got: %v", tc.expected, tc.existing)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue