mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Port k8s.io/endpointslice from utils/pointer to utils/ptr
This commit is contained in:
parent
940e6bd357
commit
fdddd8d18c
@ -25,17 +25,14 @@ import (
|
|||||||
discovery "k8s.io/api/discovery/v1"
|
discovery "k8s.io/api/discovery/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
endpointsliceutil "k8s.io/endpointslice/util"
|
endpointsliceutil "k8s.io/endpointslice/util"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNumEndpointsAndSlices(t *testing.T) {
|
func TestNumEndpointsAndSlices(t *testing.T) {
|
||||||
c := NewCache(int32(100))
|
c := NewCache(int32(100))
|
||||||
|
|
||||||
p80 := int32(80)
|
pmKey80443 := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: ptr.To[int32](80)}, {Port: ptr.To[int32](443)}})
|
||||||
p443 := int32(443)
|
pmKey80 := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: ptr.To[int32](80)}})
|
||||||
|
|
||||||
pmKey80443 := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: &p80}, {Port: &p443}})
|
|
||||||
pmKey80 := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: &p80}})
|
|
||||||
|
|
||||||
spCacheEfficient := NewServicePortCache()
|
spCacheEfficient := NewServicePortCache()
|
||||||
spCacheEfficient.Set(pmKey80, EfficiencyInfo{Endpoints: 45, Slices: 1})
|
spCacheEfficient.Set(pmKey80, EfficiencyInfo{Endpoints: 45, Slices: 1})
|
||||||
@ -64,11 +61,8 @@ func TestNumEndpointsAndSlices(t *testing.T) {
|
|||||||
func TestPlaceHolderSlice(t *testing.T) {
|
func TestPlaceHolderSlice(t *testing.T) {
|
||||||
c := NewCache(int32(100))
|
c := NewCache(int32(100))
|
||||||
|
|
||||||
p80 := int32(80)
|
pmKey80443 := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: ptr.To[int32](80)}, {Port: ptr.To[int32](443)}})
|
||||||
p443 := int32(443)
|
pmKey80 := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: ptr.To[int32](80)}})
|
||||||
|
|
||||||
pmKey80443 := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: &p80}, {Port: &p443}})
|
|
||||||
pmKey80 := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: &p80}})
|
|
||||||
|
|
||||||
sp := NewServicePortCache()
|
sp := NewServicePortCache()
|
||||||
sp.Set(pmKey80, EfficiencyInfo{Endpoints: 0, Slices: 1})
|
sp.Set(pmKey80, EfficiencyInfo{Endpoints: 0, Slices: 1})
|
||||||
@ -113,25 +107,25 @@ func TestCache_ServicesByTrafficDistribution(t *testing.T) {
|
|||||||
// Mutate and make assertions
|
// Mutate and make assertions
|
||||||
|
|
||||||
desc := "service1 starts using trafficDistribution=PreferClose"
|
desc := "service1 starts using trafficDistribution=PreferClose"
|
||||||
cache.UpdateTrafficDistributionForService(service1, ptrTo(corev1.ServiceTrafficDistributionPreferClose))
|
cache.UpdateTrafficDistributionForService(service1, ptr.To(corev1.ServiceTrafficDistributionPreferClose))
|
||||||
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{
|
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{
|
||||||
corev1.ServiceTrafficDistributionPreferClose: {service1: true},
|
corev1.ServiceTrafficDistributionPreferClose: {service1: true},
|
||||||
}, desc)
|
}, desc)
|
||||||
|
|
||||||
desc = "service1 starts using trafficDistribution=PreferClose, retries of similar mutation should be idempotent"
|
desc = "service1 starts using trafficDistribution=PreferClose, retries of similar mutation should be idempotent"
|
||||||
cache.UpdateTrafficDistributionForService(service1, ptrTo(corev1.ServiceTrafficDistributionPreferClose))
|
cache.UpdateTrafficDistributionForService(service1, ptr.To(corev1.ServiceTrafficDistributionPreferClose))
|
||||||
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{ // No delta
|
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{ // No delta
|
||||||
corev1.ServiceTrafficDistributionPreferClose: {service1: true},
|
corev1.ServiceTrafficDistributionPreferClose: {service1: true},
|
||||||
}, desc)
|
}, desc)
|
||||||
|
|
||||||
desc = "service2 starts using trafficDistribution=PreferClose"
|
desc = "service2 starts using trafficDistribution=PreferClose"
|
||||||
cache.UpdateTrafficDistributionForService(service2, ptrTo(corev1.ServiceTrafficDistributionPreferClose))
|
cache.UpdateTrafficDistributionForService(service2, ptr.To(corev1.ServiceTrafficDistributionPreferClose))
|
||||||
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{
|
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{
|
||||||
corev1.ServiceTrafficDistributionPreferClose: {service1: true, service2: true}, // Delta
|
corev1.ServiceTrafficDistributionPreferClose: {service1: true, service2: true}, // Delta
|
||||||
}, desc)
|
}, desc)
|
||||||
|
|
||||||
desc = "service3 starts using trafficDistribution=InvalidValue"
|
desc = "service3 starts using trafficDistribution=InvalidValue"
|
||||||
cache.UpdateTrafficDistributionForService(service3, ptrTo("InvalidValue"))
|
cache.UpdateTrafficDistributionForService(service3, ptr.To("InvalidValue"))
|
||||||
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{
|
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{
|
||||||
corev1.ServiceTrafficDistributionPreferClose: {service1: true, service2: true},
|
corev1.ServiceTrafficDistributionPreferClose: {service1: true, service2: true},
|
||||||
trafficDistributionImplementationSpecific: {service3: true}, // Delta
|
trafficDistributionImplementationSpecific: {service3: true}, // Delta
|
||||||
@ -145,7 +139,7 @@ func TestCache_ServicesByTrafficDistribution(t *testing.T) {
|
|||||||
}, desc)
|
}, desc)
|
||||||
|
|
||||||
desc = "service2 transitions trafficDistribution: PreferClose -> InvalidValue"
|
desc = "service2 transitions trafficDistribution: PreferClose -> InvalidValue"
|
||||||
cache.UpdateTrafficDistributionForService(service2, ptrTo("InvalidValue"))
|
cache.UpdateTrafficDistributionForService(service2, ptr.To("InvalidValue"))
|
||||||
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{
|
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{
|
||||||
corev1.ServiceTrafficDistributionPreferClose: {service1: true}, // Delta
|
corev1.ServiceTrafficDistributionPreferClose: {service1: true}, // Delta
|
||||||
trafficDistributionImplementationSpecific: {service3: true, service2: true}, // Delta
|
trafficDistributionImplementationSpecific: {service3: true, service2: true}, // Delta
|
||||||
@ -159,7 +153,7 @@ func TestCache_ServicesByTrafficDistribution(t *testing.T) {
|
|||||||
}, desc)
|
}, desc)
|
||||||
|
|
||||||
desc = "service1 transitions trafficDistribution: PreferClose -> empty"
|
desc = "service1 transitions trafficDistribution: PreferClose -> empty"
|
||||||
cache.UpdateTrafficDistributionForService(service1, ptrTo(""))
|
cache.UpdateTrafficDistributionForService(service1, ptr.To(""))
|
||||||
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{
|
mustHaveServicesByTrafficDistribution(map[string]map[types.NamespacedName]bool{
|
||||||
corev1.ServiceTrafficDistributionPreferClose: {}, // Delta
|
corev1.ServiceTrafficDistributionPreferClose: {}, // Delta
|
||||||
trafficDistributionImplementationSpecific: {service1: true, service2: true}, // Delta
|
trafficDistributionImplementationSpecific: {service1: true, service2: true}, // Delta
|
||||||
@ -184,8 +178,8 @@ func TestCache_ServicesByTrafficDistribution(t *testing.T) {
|
|||||||
func benchmarkUpdateServicePortCache(b *testing.B, num int) {
|
func benchmarkUpdateServicePortCache(b *testing.B, num int) {
|
||||||
c := NewCache(int32(100))
|
c := NewCache(int32(100))
|
||||||
ns := "benchmark"
|
ns := "benchmark"
|
||||||
httpKey := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: pointer.Int32(80)}})
|
httpKey := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: ptr.To[int32](80)}})
|
||||||
httpsKey := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: pointer.Int32(443)}})
|
httpsKey := endpointsliceutil.NewPortMapKey([]discovery.EndpointPort{{Port: ptr.To[int32](443)}})
|
||||||
spCache := &ServicePortCache{items: map[endpointsliceutil.PortMapKey]EfficiencyInfo{
|
spCache := &ServicePortCache{items: map[endpointsliceutil.PortMapKey]EfficiencyInfo{
|
||||||
httpKey: {
|
httpKey: {
|
||||||
Endpoints: 182,
|
Endpoints: 182,
|
||||||
@ -224,7 +218,3 @@ func BenchmarkUpdateServicePortCache10000(b *testing.B) {
|
|||||||
func BenchmarkUpdateServicePortCache100000(b *testing.B) {
|
func BenchmarkUpdateServicePortCache100000(b *testing.B) {
|
||||||
benchmarkUpdateServicePortCache(b, 100000)
|
benchmarkUpdateServicePortCache(b, 100000)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ptrTo[T any](obj T) *T {
|
|
||||||
return &obj
|
|
||||||
}
|
|
||||||
|
@ -44,7 +44,7 @@ import (
|
|||||||
"k8s.io/endpointslice/topologycache"
|
"k8s.io/endpointslice/topologycache"
|
||||||
endpointsliceutil "k8s.io/endpointslice/util"
|
endpointsliceutil "k8s.io/endpointslice/util"
|
||||||
"k8s.io/klog/v2/ktesting"
|
"k8s.io/klog/v2/ktesting"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -189,12 +189,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Addresses: []string{"1.2.3.4"},
|
Addresses: []string{"1.2.3.4"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -215,12 +215,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Addresses: []string{"1.2.3.4"},
|
Addresses: []string{"1.2.3.4"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -242,12 +242,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Addresses: []string{"1.2.3.4"},
|
Addresses: []string{"1.2.3.4"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -260,12 +260,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.4"},
|
Addresses: []string{"1.2.3.4"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -284,12 +284,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Addresses: []string{"1.2.3.4"},
|
Addresses: []string{"1.2.3.4"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -302,12 +302,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.4"},
|
Addresses: []string{"1.2.3.4"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -328,12 +328,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Addresses: []string{"1.2.3.4"},
|
Addresses: []string{"1.2.3.4"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -346,12 +346,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.4"},
|
Addresses: []string{"1.2.3.4"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -372,12 +372,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Addresses: []string{"1234::5678:0:0:9abc:def0"},
|
Addresses: []string{"1234::5678:0:0:9abc:def0"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -400,12 +400,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Addresses: []string{"1234::5678:0:0:9abc:def0"},
|
Addresses: []string{"1234::5678:0:0:9abc:def0"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -427,12 +427,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Addresses: []string{"1234::5678:0:0:9abc:def0"},
|
Addresses: []string{"1234::5678:0:0:9abc:def0"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -444,12 +444,12 @@ func TestReconcile1Pod(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Addresses: []string{"1.2.3.4"},
|
Addresses: []string{"1.2.3.4"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &corev1.ObjectReference{
|
TargetRef: &corev1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -1252,14 +1252,13 @@ func TestReconcileEndpointSlicesNamedPorts(t *testing.T) {
|
|||||||
expectUnorderedSlicesWithLengths(t, fetchedSlices, []int{60, 60, 60, 60, 60})
|
expectUnorderedSlicesWithLengths(t, fetchedSlices, []int{60, 60, 60, 60, 60})
|
||||||
|
|
||||||
// generate data structures for expected slice ports and address types
|
// generate data structures for expected slice ports and address types
|
||||||
protoTCP := corev1.ProtocolTCP
|
|
||||||
expectedSlices := []discovery.EndpointSlice{}
|
expectedSlices := []discovery.EndpointSlice{}
|
||||||
for i := range fetchedSlices {
|
for i := range fetchedSlices {
|
||||||
expectedSlices = append(expectedSlices, discovery.EndpointSlice{
|
expectedSlices = append(expectedSlices, discovery.EndpointSlice{
|
||||||
Ports: []discovery.EndpointPort{{
|
Ports: []discovery.EndpointPort{{
|
||||||
Name: pointer.String(""),
|
Name: ptr.To(""),
|
||||||
Protocol: &protoTCP,
|
Protocol: ptr.To(corev1.ProtocolTCP),
|
||||||
Port: pointer.Int32(int32(8080 + i)),
|
Port: ptr.To[int32](int32(8080 + i)),
|
||||||
}},
|
}},
|
||||||
AddressType: discovery.AddressTypeIPv4,
|
AddressType: discovery.AddressTypeIPv4,
|
||||||
})
|
})
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
discovery "k8s.io/api/discovery/v1"
|
discovery "k8s.io/api/discovery/v1"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_getTotalReadyEndpoints(t *testing.T) {
|
func Test_getTotalReadyEndpoints(t *testing.T) {
|
||||||
@ -93,14 +93,14 @@ func sliceWithNEndpoints(ready, unready int) *discovery.EndpointSlice {
|
|||||||
for i := 0; i < ready; i++ {
|
for i := 0; i < ready; i++ {
|
||||||
endpoints[i] = discovery.Endpoint{
|
endpoints[i] = discovery.Endpoint{
|
||||||
Addresses: []string{fmt.Sprintf("10.1.2.%d", i)},
|
Addresses: []string{fmt.Sprintf("10.1.2.%d", i)},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < unready; i++ {
|
for i := 0; i < unready; i++ {
|
||||||
endpoints[ready+i] = discovery.Endpoint{
|
endpoints[ready+i] = discovery.Endpoint{
|
||||||
Addresses: []string{fmt.Sprintf("10.1.2.%d", ready+i)},
|
Addresses: []string{fmt.Sprintf("10.1.2.%d", ready+i)},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(false)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(false)},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/klog/v2/ktesting"
|
"k8s.io/klog/v2/ktesting"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAddHints(t *testing.T) {
|
func TestAddHints(t *testing.T) {
|
||||||
@ -66,8 +66,8 @@ func TestAddHints(t *testing.T) {
|
|||||||
ToCreate: []*discovery.EndpointSlice{{
|
ToCreate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.2.3"},
|
Addresses: []string{"10.1.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@ -75,8 +75,8 @@ func TestAddHints(t *testing.T) {
|
|||||||
expectedSlicesToCreate: []*discovery.EndpointSlice{{
|
expectedSlicesToCreate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.2.3"},
|
Addresses: []string{"10.1.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
expectedSlicesToUpdate: []*discovery.EndpointSlice{},
|
expectedSlicesToUpdate: []*discovery.EndpointSlice{},
|
||||||
@ -100,12 +100,12 @@ func TestAddHints(t *testing.T) {
|
|||||||
ToCreate: []*discovery.EndpointSlice{{
|
ToCreate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.2.3"},
|
Addresses: []string{"10.1.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.4"},
|
Addresses: []string{"10.1.2.4"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@ -113,12 +113,12 @@ func TestAddHints(t *testing.T) {
|
|||||||
expectedSlicesToCreate: []*discovery.EndpointSlice{{
|
expectedSlicesToCreate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.2.3"},
|
Addresses: []string{"10.1.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.4"},
|
Addresses: []string{"10.1.2.4"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
expectedSlicesToUpdate: []*discovery.EndpointSlice{},
|
expectedSlicesToUpdate: []*discovery.EndpointSlice{},
|
||||||
@ -141,12 +141,12 @@ func TestAddHints(t *testing.T) {
|
|||||||
ToCreate: []*discovery.EndpointSlice{{
|
ToCreate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.2.3"},
|
Addresses: []string{"10.1.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.4"},
|
Addresses: []string{"10.1.2.4"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@ -159,14 +159,14 @@ func TestAddHints(t *testing.T) {
|
|||||||
expectedSlicesToCreate: []*discovery.EndpointSlice{{
|
expectedSlicesToCreate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.2.3"},
|
Addresses: []string{"10.1.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.4"},
|
Addresses: []string{"10.1.2.4"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
expectedSlicesToUpdate: []*discovery.EndpointSlice{},
|
expectedSlicesToUpdate: []*discovery.EndpointSlice{},
|
||||||
@ -189,19 +189,19 @@ func TestAddHints(t *testing.T) {
|
|||||||
ToCreate: []*discovery.EndpointSlice{{
|
ToCreate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.2.3"},
|
Addresses: []string{"10.1.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.4"},
|
Addresses: []string{"10.1.2.4"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.5"},
|
Addresses: []string{"10.1.2.5"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(false)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(false)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.6"},
|
Addresses: []string{"10.1.2.6"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@ -214,22 +214,22 @@ func TestAddHints(t *testing.T) {
|
|||||||
expectedSlicesToCreate: []*discovery.EndpointSlice{{
|
expectedSlicesToCreate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.2.3"},
|
Addresses: []string{"10.1.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.4"},
|
Addresses: []string{"10.1.2.4"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.5"},
|
Addresses: []string{"10.1.2.5"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Hints: nil,
|
Hints: nil,
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(false)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(false)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.6"},
|
Addresses: []string{"10.1.2.6"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Hints: nil,
|
Hints: nil,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
@ -254,51 +254,51 @@ func TestAddHints(t *testing.T) {
|
|||||||
ToCreate: []*discovery.EndpointSlice{{
|
ToCreate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.2.3"},
|
Addresses: []string{"10.1.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.4"},
|
Addresses: []string{"10.1.2.4"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.3.3"},
|
Addresses: []string{"10.1.3.3"},
|
||||||
Zone: pointer.String("zone-c"),
|
Zone: ptr.To("zone-c"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.3.4"},
|
Addresses: []string{"10.1.3.4"},
|
||||||
Zone: pointer.String("zone-c"),
|
Zone: ptr.To("zone-c"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.3.4"},
|
Addresses: []string{"10.1.3.4"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ToUpdate: []*discovery.EndpointSlice{{
|
ToUpdate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.2.2.3"},
|
Addresses: []string{"10.2.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.2.2.4"},
|
Addresses: []string{"10.2.2.4"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.2.3.3"},
|
Addresses: []string{"10.2.3.3"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.2.3.4"},
|
Addresses: []string{"10.2.3.4"},
|
||||||
Zone: pointer.String("zone-c"),
|
Zone: ptr.To("zone-c"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.2.3.4"},
|
Addresses: []string{"10.2.3.4"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@ -312,61 +312,61 @@ func TestAddHints(t *testing.T) {
|
|||||||
expectedSlicesToCreate: []*discovery.EndpointSlice{{
|
expectedSlicesToCreate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.2.3"},
|
Addresses: []string{"10.1.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.4"},
|
Addresses: []string{"10.1.2.4"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.3.3"},
|
Addresses: []string{"10.1.3.3"},
|
||||||
Zone: pointer.String("zone-c"),
|
Zone: ptr.To("zone-c"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-c"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-c"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.3.4"},
|
Addresses: []string{"10.1.3.4"},
|
||||||
Zone: pointer.String("zone-c"),
|
Zone: ptr.To("zone-c"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-c"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-c"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.3.4"},
|
Addresses: []string{"10.1.3.4"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
expectedSlicesToUpdate: []*discovery.EndpointSlice{{
|
expectedSlicesToUpdate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.2.2.3"},
|
Addresses: []string{"10.2.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.2.2.4"},
|
Addresses: []string{"10.2.2.4"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.2.3.3"},
|
Addresses: []string{"10.2.3.3"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.2.3.4"},
|
Addresses: []string{"10.2.3.4"},
|
||||||
Zone: pointer.String("zone-c"),
|
Zone: ptr.To("zone-c"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-c"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-c"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.2.3.4"},
|
Addresses: []string{"10.2.3.4"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
expectedEvents: []*EventBuilder{
|
expectedEvents: []*EventBuilder{
|
||||||
@ -635,12 +635,12 @@ func TestTopologyCacheRace(t *testing.T) {
|
|||||||
ToCreate: []*discovery.EndpointSlice{{
|
ToCreate: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Addresses: []string{"10.1.2.3"},
|
Addresses: []string{"10.1.2.3"},
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Addresses: []string{"10.1.2.4"},
|
Addresses: []string{"10.1.2.4"},
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}}}
|
}}}
|
||||||
type nodeInfo struct {
|
type nodeInfo struct {
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
|
|
||||||
discovery "k8s.io/api/discovery/v1"
|
discovery "k8s.io/api/discovery/v1"
|
||||||
"k8s.io/klog/v2/ktesting"
|
"k8s.io/klog/v2/ktesting"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_redistributeHints(t *testing.T) {
|
func Test_redistributeHints(t *testing.T) {
|
||||||
@ -42,9 +42,9 @@ func Test_redistributeHints(t *testing.T) {
|
|||||||
name: "single endpoint",
|
name: "single endpoint",
|
||||||
slices: []*discovery.EndpointSlice{{
|
slices: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
givingZones: map[string]int{"zone-a": 1},
|
givingZones: map[string]int{"zone-a": 1},
|
||||||
@ -54,17 +54,17 @@ func Test_redistributeHints(t *testing.T) {
|
|||||||
name: "endpoints from 1 zone redistributed to 2 other zones",
|
name: "endpoints from 1 zone redistributed to 2 other zones",
|
||||||
slices: []*discovery.EndpointSlice{{
|
slices: []*discovery.EndpointSlice{{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
givingZones: map[string]int{"zone-a": 2},
|
givingZones: map[string]int{"zone-a": 2},
|
||||||
@ -217,9 +217,9 @@ func Test_getHintsByZone(t *testing.T) {
|
|||||||
name: "single zone hint",
|
name: "single zone hint",
|
||||||
slice: discovery.EndpointSlice{
|
slice: discovery.EndpointSlice{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
allocations: map[string]allocation{
|
allocations: map[string]allocation{
|
||||||
@ -233,15 +233,15 @@ func Test_getHintsByZone(t *testing.T) {
|
|||||||
name: "single zone hint with 1 unready endpoint and 1 unknown endpoint",
|
name: "single zone hint with 1 unready endpoint and 1 unknown endpoint",
|
||||||
slice: discovery.EndpointSlice{
|
slice: discovery.EndpointSlice{
|
||||||
Endpoints: []discovery.Endpoint{{
|
Endpoints: []discovery.Endpoint{{
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
}, {
|
}, {
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(false)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(false)},
|
||||||
}, {
|
}, {
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@ -257,19 +257,19 @@ func Test_getHintsByZone(t *testing.T) {
|
|||||||
slice: discovery.EndpointSlice{
|
slice: discovery.EndpointSlice{
|
||||||
Endpoints: []discovery.Endpoint{
|
Endpoints: []discovery.Endpoint{
|
||||||
{
|
{
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Zone: pointer.String("zone-b"),
|
Zone: ptr.To("zone-b"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-b"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -288,9 +288,9 @@ func Test_getHintsByZone(t *testing.T) {
|
|||||||
slice: discovery.EndpointSlice{
|
slice: discovery.EndpointSlice{
|
||||||
Endpoints: []discovery.Endpoint{
|
Endpoints: []discovery.Endpoint{
|
||||||
{
|
{
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-non-existent"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-non-existent"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -304,9 +304,9 @@ func Test_getHintsByZone(t *testing.T) {
|
|||||||
slice: discovery.EndpointSlice{
|
slice: discovery.EndpointSlice{
|
||||||
Endpoints: []discovery.Endpoint{
|
Endpoints: []discovery.Endpoint{
|
||||||
{
|
{
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: nil,
|
Hints: nil,
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -320,9 +320,9 @@ func Test_getHintsByZone(t *testing.T) {
|
|||||||
slice: discovery.EndpointSlice{
|
slice: discovery.EndpointSlice{
|
||||||
Endpoints: []discovery.Endpoint{
|
Endpoints: []discovery.Endpoint{
|
||||||
{
|
{
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -336,14 +336,14 @@ func Test_getHintsByZone(t *testing.T) {
|
|||||||
slice: discovery.EndpointSlice{
|
slice: discovery.EndpointSlice{
|
||||||
Endpoints: []discovery.Endpoint{
|
Endpoints: []discovery.Endpoint{
|
||||||
{
|
{
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Zone: pointer.String("zone-a"),
|
Zone: ptr.To("zone-a"),
|
||||||
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
Hints: &discovery.EndpointHints{ForZones: []discovery.ForZone{{Name: "zone-a"}}},
|
||||||
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)},
|
Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -41,7 +41,7 @@ func TestReconcileHints_trafficDistribution_is_PreferClose(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "should set same zone hints",
|
name: "should set same zone hints",
|
||||||
trafficDistribution: ptrTo(corev1.ServiceTrafficDistributionPreferClose),
|
trafficDistribution: ptr.To(corev1.ServiceTrafficDistributionPreferClose),
|
||||||
slicesToCreate: []*discoveryv1.EndpointSlice{
|
slicesToCreate: []*discoveryv1.EndpointSlice{
|
||||||
{
|
{
|
||||||
Endpoints: []discoveryv1.Endpoint{
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
@ -173,7 +173,7 @@ func TestReconcileHints_trafficDistribution_is_PreferClose(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "incorrect hints should be corrected",
|
name: "incorrect hints should be corrected",
|
||||||
trafficDistribution: ptrTo(corev1.ServiceTrafficDistributionPreferClose),
|
trafficDistribution: ptr.To(corev1.ServiceTrafficDistributionPreferClose),
|
||||||
slicesToUpdate: []*discoveryv1.EndpointSlice{
|
slicesToUpdate: []*discoveryv1.EndpointSlice{
|
||||||
{
|
{
|
||||||
Endpoints: []discoveryv1.Endpoint{
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
@ -242,7 +242,7 @@ func TestReconcileHints_trafficDistribution_is_PreferClose(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "unready endpoints should not trigger updates",
|
name: "unready endpoints should not trigger updates",
|
||||||
trafficDistribution: ptrTo(corev1.ServiceTrafficDistributionPreferClose),
|
trafficDistribution: ptr.To(corev1.ServiceTrafficDistributionPreferClose),
|
||||||
slicesUnchanged: []*discoveryv1.EndpointSlice{
|
slicesUnchanged: []*discoveryv1.EndpointSlice{
|
||||||
{
|
{
|
||||||
Endpoints: []discoveryv1.Endpoint{
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
@ -300,7 +300,7 @@ func TestReconcileHints_trafficDistribution_is_nil_or_empty(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "trafficDistribution='' should remove zone hints",
|
name: "trafficDistribution='' should remove zone hints",
|
||||||
trafficDistribution: ptrTo(""),
|
trafficDistribution: ptr.To(""),
|
||||||
slicesToCreate: []*discoveryv1.EndpointSlice{
|
slicesToCreate: []*discoveryv1.EndpointSlice{
|
||||||
{
|
{
|
||||||
Endpoints: []discoveryv1.Endpoint{
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
@ -459,12 +459,8 @@ func TestReconcileHints_doesNotMutateUnchangedSlices(t *testing.T) {
|
|||||||
clonedEps := originalEps.DeepCopy()
|
clonedEps := originalEps.DeepCopy()
|
||||||
|
|
||||||
// originalEps should not get modified.
|
// originalEps should not get modified.
|
||||||
ReconcileHints(ptrTo(corev1.ServiceTrafficDistributionPreferClose), nil, nil, []*discoveryv1.EndpointSlice{originalEps})
|
ReconcileHints(ptr.To(corev1.ServiceTrafficDistributionPreferClose), nil, nil, []*discoveryv1.EndpointSlice{originalEps})
|
||||||
if diff := cmp.Diff(clonedEps, originalEps); diff != "" {
|
if diff := cmp.Diff(clonedEps, originalEps); diff != "" {
|
||||||
t.Errorf("ReconcileHints(...) modified objects within slicesUnchanged, want objects within slicesUnchanged to remain unmodified: (-want, +got)\n%v", diff)
|
t.Errorf("ReconcileHints(...) modified objects within slicesUnchanged, want objects within slicesUnchanged to remain unmodified: (-want, +got)\n%v", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ptrTo[T any](obj T) *T {
|
|
||||||
return &obj
|
|
||||||
}
|
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/client-go/informers"
|
"k8s.io/client-go/informers"
|
||||||
"k8s.io/client-go/kubernetes/fake"
|
"k8s.io/client-go/kubernetes/fake"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDetermineNeededServiceUpdates(t *testing.T) {
|
func TestDetermineNeededServiceUpdates(t *testing.T) {
|
||||||
@ -621,19 +621,19 @@ func TestEndpointsEqualBeyondHash(t *testing.T) {
|
|||||||
name: "No change",
|
name: "No change",
|
||||||
ep1: &discovery.Endpoint{
|
ep1: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
ep2: &discovery.Endpoint{
|
ep2: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
@ -641,19 +641,19 @@ func TestEndpointsEqualBeyondHash(t *testing.T) {
|
|||||||
name: "NodeName changed",
|
name: "NodeName changed",
|
||||||
ep1: &discovery.Endpoint{
|
ep1: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
ep2: &discovery.Endpoint{
|
ep2: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
NodeName: pointer.String("node-2"),
|
NodeName: ptr.To("node-2"),
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
@ -661,19 +661,19 @@ func TestEndpointsEqualBeyondHash(t *testing.T) {
|
|||||||
name: "Zone changed",
|
name: "Zone changed",
|
||||||
ep1: &discovery.Endpoint{
|
ep1: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
},
|
},
|
||||||
ep2: &discovery.Endpoint{
|
ep2: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
Zone: pointer.String("zone-2"),
|
Zone: ptr.To("zone-2"),
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
@ -681,21 +681,21 @@ func TestEndpointsEqualBeyondHash(t *testing.T) {
|
|||||||
name: "Ready condition changed",
|
name: "Ready condition changed",
|
||||||
ep1: &discovery.Endpoint{
|
ep1: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
ep2: &discovery.Endpoint{
|
ep2: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(false),
|
Ready: ptr.To(false),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
@ -703,25 +703,25 @@ func TestEndpointsEqualBeyondHash(t *testing.T) {
|
|||||||
name: "Serving condition changed from nil to true",
|
name: "Serving condition changed from nil to true",
|
||||||
ep1: &discovery.Endpoint{
|
ep1: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: nil,
|
Serving: nil,
|
||||||
Terminating: nil,
|
Terminating: nil,
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
ep2: &discovery.Endpoint{
|
ep2: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
@ -729,25 +729,25 @@ func TestEndpointsEqualBeyondHash(t *testing.T) {
|
|||||||
name: "Serving condition changed from false to true",
|
name: "Serving condition changed from false to true",
|
||||||
ep1: &discovery.Endpoint{
|
ep1: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(false),
|
Serving: ptr.To(false),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
ep2: &discovery.Endpoint{
|
ep2: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
@ -755,21 +755,21 @@ func TestEndpointsEqualBeyondHash(t *testing.T) {
|
|||||||
name: "Pod name changed",
|
name: "Pod name changed",
|
||||||
ep1: &discovery.Endpoint{
|
ep1: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
ep2: &discovery.Endpoint{
|
ep2: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod1"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod1"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
@ -777,21 +777,21 @@ func TestEndpointsEqualBeyondHash(t *testing.T) {
|
|||||||
name: "Pod resourceVersion changed",
|
name: "Pod resourceVersion changed",
|
||||||
ep1: &discovery.Endpoint{
|
ep1: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0", ResourceVersion: "1"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0", ResourceVersion: "1"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
ep2: &discovery.Endpoint{
|
ep2: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0", ResourceVersion: "2"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0", ResourceVersion: "2"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
@ -799,21 +799,21 @@ func TestEndpointsEqualBeyondHash(t *testing.T) {
|
|||||||
name: "Pod resourceVersion removed",
|
name: "Pod resourceVersion removed",
|
||||||
ep1: &discovery.Endpoint{
|
ep1: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0", ResourceVersion: "1"},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0", ResourceVersion: "1"},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
ep2: &discovery.Endpoint{
|
ep2: &discovery.Endpoint{
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
},
|
},
|
||||||
Addresses: []string{"10.0.0.1"},
|
Addresses: []string{"10.0.0.1"},
|
||||||
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0", ResourceVersion: ""},
|
TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0", ResourceVersion: ""},
|
||||||
Zone: pointer.String("zone-1"),
|
Zone: ptr.To("zone-1"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
},
|
},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
discovery "k8s.io/api/discovery/v1"
|
discovery "k8s.io/api/discovery/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEndpointSliceTrackerUpdate(t *testing.T) {
|
func TestEndpointSliceTrackerUpdate(t *testing.T) {
|
||||||
@ -125,8 +126,7 @@ func TestEndpointSliceTrackerStaleSlices(t *testing.T) {
|
|||||||
epSlice1NewerGen.Generation = 2
|
epSlice1NewerGen.Generation = 2
|
||||||
|
|
||||||
epTerminatingSlice := epSlice1.DeepCopy()
|
epTerminatingSlice := epSlice1.DeepCopy()
|
||||||
now := metav1.Now()
|
epTerminatingSlice.DeletionTimestamp = ptr.To(metav1.Now())
|
||||||
epTerminatingSlice.DeletionTimestamp = &now
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
endpointutil "k8s.io/endpointslice/util"
|
endpointutil "k8s.io/endpointslice/util"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
utilnet "k8s.io/utils/net"
|
utilnet "k8s.io/utils/net"
|
||||||
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
// podToEndpoint returns an Endpoint object generated from a Pod, a Node, and a Service for a particular addressType.
|
// podToEndpoint returns an Endpoint object generated from a Pod, a Node, and a Service for a particular addressType.
|
||||||
@ -60,8 +61,7 @@ func podToEndpoint(pod *v1.Pod, node *v1.Node, service *v1.Service, addressType
|
|||||||
}
|
}
|
||||||
|
|
||||||
if node != nil && node.Labels[v1.LabelTopologyZone] != "" {
|
if node != nil && node.Labels[v1.LabelTopologyZone] != "" {
|
||||||
zone := node.Labels[v1.LabelTopologyZone]
|
ep.Zone = ptr.To(node.Labels[v1.LabelTopologyZone])
|
||||||
ep.Zone = &zone
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if endpointutil.ShouldSetHostname(pod, service) {
|
if endpointutil.ShouldSetHostname(pod, service) {
|
||||||
@ -84,19 +84,16 @@ func getEndpointPorts(logger klog.Logger, service *v1.Service, pod *v1.Pod) []di
|
|||||||
for i := range service.Spec.Ports {
|
for i := range service.Spec.Ports {
|
||||||
servicePort := &service.Spec.Ports[i]
|
servicePort := &service.Spec.Ports[i]
|
||||||
|
|
||||||
portName := servicePort.Name
|
|
||||||
portProto := servicePort.Protocol
|
|
||||||
portNum, err := findPort(pod, servicePort)
|
portNum, err := findPort(pod, servicePort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.V(4).Info("Failed to find port for service", "service", klog.KObj(service), "err", err)
|
logger.V(4).Info("Failed to find port for service", "service", klog.KObj(service), "err", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
i32PortNum := int32(portNum)
|
|
||||||
endpointPorts = append(endpointPorts, discovery.EndpointPort{
|
endpointPorts = append(endpointPorts, discovery.EndpointPort{
|
||||||
Name: &portName,
|
Name: ptr.To(servicePort.Name),
|
||||||
Port: &i32PortNum,
|
Port: ptr.To(int32(portNum)),
|
||||||
Protocol: &portProto,
|
Protocol: ptr.To(servicePort.Protocol),
|
||||||
AppProtocol: servicePort.AppProtocol,
|
AppProtocol: servicePort.AppProtocol,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -34,15 +34,17 @@ import (
|
|||||||
"k8s.io/client-go/kubernetes/fake"
|
"k8s.io/client-go/kubernetes/fake"
|
||||||
k8stesting "k8s.io/client-go/testing"
|
k8stesting "k8s.io/client-go/testing"
|
||||||
"k8s.io/klog/v2/ktesting"
|
"k8s.io/klog/v2/ktesting"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewEndpointSlice(t *testing.T) {
|
func TestNewEndpointSlice(t *testing.T) {
|
||||||
ipAddressType := discovery.AddressTypeIPv4
|
ipAddressType := discovery.AddressTypeIPv4
|
||||||
portName := "foo"
|
portName := "foo"
|
||||||
protocol := v1.ProtocolTCP
|
|
||||||
endpointMeta := endpointMeta{
|
endpointMeta := endpointMeta{
|
||||||
ports: []discovery.EndpointPort{{Name: &portName, Protocol: &protocol}},
|
ports: []discovery.EndpointPort{{
|
||||||
|
Name: &portName,
|
||||||
|
Protocol: ptr.To(v1.ProtocolTCP),
|
||||||
|
}},
|
||||||
addressType: ipAddressType,
|
addressType: ipAddressType,
|
||||||
}
|
}
|
||||||
service := v1.Service{
|
service := v1.Service{
|
||||||
@ -258,11 +260,11 @@ func TestPodToEndpoint(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.5"},
|
Addresses: []string{"1.2.3.5"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &v1.ObjectReference{
|
TargetRef: &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
@ -278,11 +280,11 @@ func TestPodToEndpoint(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.5"},
|
Addresses: []string{"1.2.3.5"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &v1.ObjectReference{
|
TargetRef: &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
@ -298,11 +300,11 @@ func TestPodToEndpoint(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.5"},
|
Addresses: []string{"1.2.3.5"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(false),
|
Ready: ptr.To(false),
|
||||||
Serving: pointer.Bool(false),
|
Serving: ptr.To(false),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &v1.ObjectReference{
|
TargetRef: &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
@ -318,11 +320,11 @@ func TestPodToEndpoint(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.5"},
|
Addresses: []string{"1.2.3.5"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(false),
|
Serving: ptr.To(false),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &v1.ObjectReference{
|
TargetRef: &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
@ -339,12 +341,12 @@ func TestPodToEndpoint(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.5"},
|
Addresses: []string{"1.2.3.5"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &v1.ObjectReference{
|
TargetRef: &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
@ -361,12 +363,12 @@ func TestPodToEndpoint(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.4"},
|
Addresses: []string{"1.2.3.4"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &v1.ObjectReference{
|
TargetRef: &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
@ -383,13 +385,13 @@ func TestPodToEndpoint(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.5"},
|
Addresses: []string{"1.2.3.5"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
Hostname: &readyPodHostname.Spec.Hostname,
|
Hostname: &readyPodHostname.Spec.Hostname,
|
||||||
Zone: pointer.String("us-central1-a"),
|
Zone: ptr.To("us-central1-a"),
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &v1.ObjectReference{
|
TargetRef: &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
@ -405,11 +407,11 @@ func TestPodToEndpoint(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.5"},
|
Addresses: []string{"1.2.3.5"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(true),
|
Ready: ptr.To(true),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(false),
|
Terminating: ptr.To(false),
|
||||||
},
|
},
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &v1.ObjectReference{
|
TargetRef: &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
@ -425,11 +427,11 @@ func TestPodToEndpoint(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.5"},
|
Addresses: []string{"1.2.3.5"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(false),
|
Ready: ptr.To(false),
|
||||||
Serving: pointer.Bool(true),
|
Serving: ptr.To(true),
|
||||||
Terminating: pointer.Bool(true),
|
Terminating: ptr.To(true),
|
||||||
},
|
},
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &v1.ObjectReference{
|
TargetRef: &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
@ -445,11 +447,11 @@ func TestPodToEndpoint(t *testing.T) {
|
|||||||
expectedEndpoint: discovery.Endpoint{
|
expectedEndpoint: discovery.Endpoint{
|
||||||
Addresses: []string{"1.2.3.5"},
|
Addresses: []string{"1.2.3.5"},
|
||||||
Conditions: discovery.EndpointConditions{
|
Conditions: discovery.EndpointConditions{
|
||||||
Ready: pointer.Bool(false),
|
Ready: ptr.To(false),
|
||||||
Serving: pointer.Bool(false),
|
Serving: ptr.To(false),
|
||||||
Terminating: pointer.Bool(true),
|
Terminating: ptr.To(true),
|
||||||
},
|
},
|
||||||
NodeName: pointer.String("node-1"),
|
NodeName: ptr.To("node-1"),
|
||||||
TargetRef: &v1.ObjectReference{
|
TargetRef: &v1.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
@ -514,7 +516,6 @@ func TestServiceControllerKey(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetEndpointPorts(t *testing.T) {
|
func TestGetEndpointPorts(t *testing.T) {
|
||||||
protoTCP := v1.ProtocolTCP
|
|
||||||
restartPolicyAlways := v1.ContainerRestartPolicyAlways
|
restartPolicyAlways := v1.ContainerRestartPolicyAlways
|
||||||
|
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
@ -529,8 +530,8 @@ func TestGetEndpointPorts(t *testing.T) {
|
|||||||
Name: "http",
|
Name: "http",
|
||||||
Port: 80,
|
Port: 80,
|
||||||
TargetPort: intstr.FromInt32(80),
|
TargetPort: intstr.FromInt32(80),
|
||||||
Protocol: protoTCP,
|
Protocol: v1.ProtocolTCP,
|
||||||
AppProtocol: pointer.String("example.com/custom-protocol"),
|
AppProtocol: ptr.To("example.com/custom-protocol"),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -542,10 +543,10 @@ func TestGetEndpointPorts(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPorts: []*discovery.EndpointPort{{
|
expectedPorts: []*discovery.EndpointPort{{
|
||||||
Name: pointer.String("http"),
|
Name: ptr.To("http"),
|
||||||
Port: pointer.Int32(80),
|
Port: ptr.To[int32](80),
|
||||||
Protocol: &protoTCP,
|
Protocol: ptr.To(v1.ProtocolTCP),
|
||||||
AppProtocol: pointer.String("example.com/custom-protocol"),
|
AppProtocol: ptr.To("example.com/custom-protocol"),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
"service with named port and AppProtocol on one port": {
|
"service with named port and AppProtocol on one port": {
|
||||||
@ -555,12 +556,12 @@ func TestGetEndpointPorts(t *testing.T) {
|
|||||||
Name: "http",
|
Name: "http",
|
||||||
Port: 80,
|
Port: 80,
|
||||||
TargetPort: intstr.FromInt32(80),
|
TargetPort: intstr.FromInt32(80),
|
||||||
Protocol: protoTCP,
|
Protocol: v1.ProtocolTCP,
|
||||||
}, {
|
}, {
|
||||||
Name: "https",
|
Name: "https",
|
||||||
Protocol: protoTCP,
|
Protocol: v1.ProtocolTCP,
|
||||||
TargetPort: intstr.FromString("https"),
|
TargetPort: intstr.FromString("https"),
|
||||||
AppProtocol: pointer.String("https"),
|
AppProtocol: ptr.To("https"),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -570,20 +571,20 @@ func TestGetEndpointPorts(t *testing.T) {
|
|||||||
Ports: []v1.ContainerPort{{
|
Ports: []v1.ContainerPort{{
|
||||||
Name: "https",
|
Name: "https",
|
||||||
ContainerPort: int32(443),
|
ContainerPort: int32(443),
|
||||||
Protocol: protoTCP,
|
Protocol: v1.ProtocolTCP,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPorts: []*discovery.EndpointPort{{
|
expectedPorts: []*discovery.EndpointPort{{
|
||||||
Name: pointer.String("http"),
|
Name: ptr.To("http"),
|
||||||
Port: pointer.Int32(80),
|
Port: ptr.To[int32](80),
|
||||||
Protocol: &protoTCP,
|
Protocol: ptr.To(v1.ProtocolTCP),
|
||||||
}, {
|
}, {
|
||||||
Name: pointer.String("https"),
|
Name: ptr.To("https"),
|
||||||
Port: pointer.Int32(443),
|
Port: ptr.To[int32](443),
|
||||||
Protocol: &protoTCP,
|
Protocol: ptr.To(v1.ProtocolTCP),
|
||||||
AppProtocol: pointer.String("https"),
|
AppProtocol: ptr.To("https"),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
"service with named port for restartable init container": {
|
"service with named port for restartable init container": {
|
||||||
@ -593,12 +594,12 @@ func TestGetEndpointPorts(t *testing.T) {
|
|||||||
Name: "http-sidecar",
|
Name: "http-sidecar",
|
||||||
Port: 8080,
|
Port: 8080,
|
||||||
TargetPort: intstr.FromInt32(8080),
|
TargetPort: intstr.FromInt32(8080),
|
||||||
Protocol: protoTCP,
|
Protocol: v1.ProtocolTCP,
|
||||||
}, {
|
}, {
|
||||||
Name: "http",
|
Name: "http",
|
||||||
Port: 8090,
|
Port: 8090,
|
||||||
TargetPort: intstr.FromString("http"),
|
TargetPort: intstr.FromString("http"),
|
||||||
Protocol: protoTCP,
|
Protocol: v1.ProtocolTCP,
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -608,7 +609,7 @@ func TestGetEndpointPorts(t *testing.T) {
|
|||||||
Ports: []v1.ContainerPort{{
|
Ports: []v1.ContainerPort{{
|
||||||
Name: "http-sidecar",
|
Name: "http-sidecar",
|
||||||
ContainerPort: int32(8080),
|
ContainerPort: int32(8080),
|
||||||
Protocol: protoTCP,
|
Protocol: v1.ProtocolTCP,
|
||||||
}},
|
}},
|
||||||
RestartPolicy: &restartPolicyAlways,
|
RestartPolicy: &restartPolicyAlways,
|
||||||
}},
|
}},
|
||||||
@ -616,19 +617,19 @@ func TestGetEndpointPorts(t *testing.T) {
|
|||||||
Ports: []v1.ContainerPort{{
|
Ports: []v1.ContainerPort{{
|
||||||
Name: "http",
|
Name: "http",
|
||||||
ContainerPort: int32(8090),
|
ContainerPort: int32(8090),
|
||||||
Protocol: protoTCP,
|
Protocol: v1.ProtocolTCP,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPorts: []*discovery.EndpointPort{{
|
expectedPorts: []*discovery.EndpointPort{{
|
||||||
Name: pointer.String("http-sidecar"),
|
Name: ptr.To("http-sidecar"),
|
||||||
Port: pointer.Int32(8080),
|
Port: ptr.To[int32](8080),
|
||||||
Protocol: &protoTCP,
|
Protocol: ptr.To(v1.ProtocolTCP),
|
||||||
}, {
|
}, {
|
||||||
Name: pointer.String("http"),
|
Name: ptr.To("http"),
|
||||||
Port: pointer.Int32(8090),
|
Port: ptr.To[int32](8090),
|
||||||
Protocol: &protoTCP,
|
Protocol: ptr.To(v1.ProtocolTCP),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
"service with same named port for regular and restartable init container": {
|
"service with same named port for regular and restartable init container": {
|
||||||
@ -639,7 +640,7 @@ func TestGetEndpointPorts(t *testing.T) {
|
|||||||
Name: "http",
|
Name: "http",
|
||||||
Port: 80,
|
Port: 80,
|
||||||
TargetPort: intstr.FromString("http"),
|
TargetPort: intstr.FromString("http"),
|
||||||
Protocol: protoTCP,
|
Protocol: v1.ProtocolTCP,
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -649,7 +650,7 @@ func TestGetEndpointPorts(t *testing.T) {
|
|||||||
Ports: []v1.ContainerPort{{
|
Ports: []v1.ContainerPort{{
|
||||||
Name: "http",
|
Name: "http",
|
||||||
ContainerPort: int32(8080),
|
ContainerPort: int32(8080),
|
||||||
Protocol: protoTCP,
|
Protocol: v1.ProtocolTCP,
|
||||||
}},
|
}},
|
||||||
RestartPolicy: &restartPolicyAlways,
|
RestartPolicy: &restartPolicyAlways,
|
||||||
}},
|
}},
|
||||||
@ -657,15 +658,15 @@ func TestGetEndpointPorts(t *testing.T) {
|
|||||||
Ports: []v1.ContainerPort{{
|
Ports: []v1.ContainerPort{{
|
||||||
Name: "http",
|
Name: "http",
|
||||||
ContainerPort: int32(8090),
|
ContainerPort: int32(8090),
|
||||||
Protocol: protoTCP,
|
Protocol: v1.ProtocolTCP,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPorts: []*discovery.EndpointPort{{
|
expectedPorts: []*discovery.EndpointPort{{
|
||||||
Name: pointer.String("http"),
|
Name: ptr.To("http"),
|
||||||
Port: pointer.Int32(8090),
|
Port: ptr.To[int32](8090),
|
||||||
Protocol: &protoTCP,
|
Protocol: ptr.To(v1.ProtocolTCP),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1042,10 +1043,9 @@ func newClientset() *fake.Clientset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newServiceAndEndpointMeta(name, namespace string) (v1.Service, endpointMeta) {
|
func newServiceAndEndpointMeta(name, namespace string) (v1.Service, endpointMeta) {
|
||||||
portNum := int32(80)
|
|
||||||
portNameIntStr := intstr.IntOrString{
|
portNameIntStr := intstr.IntOrString{
|
||||||
Type: intstr.Int,
|
Type: intstr.Int,
|
||||||
IntVal: portNum,
|
IntVal: 80,
|
||||||
}
|
}
|
||||||
|
|
||||||
svc := v1.Service{
|
svc := v1.Service{
|
||||||
@ -1065,11 +1065,13 @@ func newServiceAndEndpointMeta(name, namespace string) (v1.Service, endpointMeta
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
addressType := discovery.AddressTypeIPv4
|
|
||||||
protocol := v1.ProtocolTCP
|
|
||||||
endpointMeta := endpointMeta{
|
endpointMeta := endpointMeta{
|
||||||
addressType: addressType,
|
addressType: discovery.AddressTypeIPv4,
|
||||||
ports: []discovery.EndpointPort{{Name: &name, Port: &portNum, Protocol: &protocol}},
|
ports: []discovery.EndpointPort{{
|
||||||
|
Name: &name,
|
||||||
|
Port: &portNameIntStr.IntVal,
|
||||||
|
Protocol: ptr.To(v1.ProtocolTCP),
|
||||||
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
return svc, endpointMeta
|
return svc, endpointMeta
|
||||||
|
Loading…
Reference in New Issue
Block a user