Use k8s.io/utils/ptr in pkg/proxy (#121154)

* Use k8s.io/utils/ptr in pkg/proxy

* Replace pointer.String(), pointer.StringPtr(), and pointer.Bool() with ptr.To()

* Replace pointer.Int32(constexpr) with ptr.To[int32](constexpr)

* Replace pointer.Int32(int32(var)) with ptr.To(int32(var))

* Replace remaining pointer.Int32() cases with ptr.To

* Replace 'tcpProtocol := v1.ProtocolTCP; ... &tcpProtocol', etc with ptr.To(v1.ProtocolTCP)

* Replace 'nodeName = testHostname; ... &nodeName' with ptr.To(testHostname)

* Use ptr.To for SessionAffinityConfig.ClientIP.TimeoutSeconds

* Use ptr.To for InternalTrafficPolicy

* Use ptr.To for LoadBalancer.Ingress.IPMode
This commit is contained in:
Dan Winship 2023-10-26 14:56:39 -04:00 committed by GitHub
parent 801d460296
commit fcc55280b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 1062 additions and 1153 deletions

View File

@ -25,7 +25,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config" kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config"
"k8s.io/utils/pointer" "k8s.io/utils/ptr"
) )
// Funcs returns the fuzzer functions for the kube-proxy apis. // Funcs returns the fuzzer functions for the kube-proxy apis.
@ -35,16 +35,16 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
c.FuzzNoCustom(obj) c.FuzzNoCustom(obj)
obj.BindAddress = fmt.Sprintf("%d.%d.%d.%d", c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(256)) obj.BindAddress = fmt.Sprintf("%d.%d.%d.%d", c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(256))
obj.ClientConnection.ContentType = c.RandString() obj.ClientConnection.ContentType = c.RandString()
obj.Conntrack.MaxPerCore = pointer.Int32(c.Int31()) obj.Conntrack.MaxPerCore = ptr.To(c.Int31())
obj.Conntrack.Min = pointer.Int32(c.Int31()) obj.Conntrack.Min = ptr.To(c.Int31())
obj.Conntrack.TCPCloseWaitTimeout = &metav1.Duration{Duration: time.Duration(c.Int63()) * time.Hour} obj.Conntrack.TCPCloseWaitTimeout = &metav1.Duration{Duration: time.Duration(c.Int63()) * time.Hour}
obj.Conntrack.TCPEstablishedTimeout = &metav1.Duration{Duration: time.Duration(c.Int63()) * time.Hour} obj.Conntrack.TCPEstablishedTimeout = &metav1.Duration{Duration: time.Duration(c.Int63()) * time.Hour}
obj.FeatureGates = map[string]bool{c.RandString(): true} obj.FeatureGates = map[string]bool{c.RandString(): true}
obj.HealthzBindAddress = fmt.Sprintf("%d.%d.%d.%d:%d", c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(65536)) obj.HealthzBindAddress = fmt.Sprintf("%d.%d.%d.%d:%d", c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(65536))
obj.IPTables.MasqueradeBit = pointer.Int32(c.Int31()) obj.IPTables.MasqueradeBit = ptr.To(c.Int31())
obj.IPTables.LocalhostNodePorts = pointer.Bool(c.RandBool()) obj.IPTables.LocalhostNodePorts = ptr.To(c.RandBool())
obj.MetricsBindAddress = fmt.Sprintf("%d.%d.%d.%d:%d", c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(65536)) obj.MetricsBindAddress = fmt.Sprintf("%d.%d.%d.%d:%d", c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(65536))
obj.OOMScoreAdj = pointer.Int32(c.Int31()) obj.OOMScoreAdj = ptr.To(c.Int31())
obj.ClientConnection.ContentType = "bar" obj.ClientConnection.ContentType = "bar"
obj.NodePortAddresses = []string{"1.2.3.0/24"} obj.NodePortAddresses = []string{"1.2.3.0/24"}
if obj.Logging.Format == "" { if obj.Logging.Format == "" {

View File

@ -29,7 +29,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet/qos" "k8s.io/kubernetes/pkg/kubelet/qos"
proxyutil "k8s.io/kubernetes/pkg/proxy/util" proxyutil "k8s.io/kubernetes/pkg/proxy/util"
netutils "k8s.io/utils/net" netutils "k8s.io/utils/net"
"k8s.io/utils/pointer" "k8s.io/utils/ptr"
) )
func addDefaultingFuncs(scheme *kruntime.Scheme) error { func addDefaultingFuncs(scheme *kruntime.Scheme) error {
@ -66,17 +66,17 @@ func SetDefaults_KubeProxyConfiguration(obj *kubeproxyconfigv1alpha1.KubeProxyCo
obj.IPTables.MinSyncPeriod = metav1.Duration{Duration: 1 * time.Second} obj.IPTables.MinSyncPeriod = metav1.Duration{Duration: 1 * time.Second}
} }
if obj.IPTables.LocalhostNodePorts == nil { if obj.IPTables.LocalhostNodePorts == nil {
obj.IPTables.LocalhostNodePorts = pointer.Bool(true) obj.IPTables.LocalhostNodePorts = ptr.To(true)
} }
if obj.IPVS.SyncPeriod.Duration == 0 { if obj.IPVS.SyncPeriod.Duration == 0 {
obj.IPVS.SyncPeriod = metav1.Duration{Duration: 30 * time.Second} obj.IPVS.SyncPeriod = metav1.Duration{Duration: 30 * time.Second}
} }
if obj.Conntrack.MaxPerCore == nil { if obj.Conntrack.MaxPerCore == nil {
obj.Conntrack.MaxPerCore = pointer.Int32(32 * 1024) obj.Conntrack.MaxPerCore = ptr.To[int32](32 * 1024)
} }
if obj.Conntrack.Min == nil { if obj.Conntrack.Min == nil {
obj.Conntrack.Min = pointer.Int32(128 * 1024) obj.Conntrack.Min = ptr.To[int32](128 * 1024)
} }
if obj.IPTables.MasqueradeBit == nil { if obj.IPTables.MasqueradeBit == nil {

View File

@ -20,7 +20,7 @@ import (
"testing" "testing"
"time" "time"
"k8s.io/utils/pointer" "k8s.io/utils/ptr"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
@ -53,9 +53,9 @@ func TestDefaultsKubeProxyConfiguration(t *testing.T) {
Burst: 10, Burst: 10,
}, },
IPTables: kubeproxyconfigv1alpha1.KubeProxyIPTablesConfiguration{ IPTables: kubeproxyconfigv1alpha1.KubeProxyIPTablesConfiguration{
MasqueradeBit: pointer.Int32(14), MasqueradeBit: ptr.To[int32](14),
MasqueradeAll: false, MasqueradeAll: false,
LocalhostNodePorts: pointer.Bool(true), LocalhostNodePorts: ptr.To(true),
SyncPeriod: metav1.Duration{Duration: 30 * time.Second}, SyncPeriod: metav1.Duration{Duration: 30 * time.Second},
MinSyncPeriod: metav1.Duration{Duration: 1 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 1 * time.Second},
}, },
@ -93,9 +93,9 @@ func TestDefaultsKubeProxyConfiguration(t *testing.T) {
Burst: 10, Burst: 10,
}, },
IPTables: kubeproxyconfigv1alpha1.KubeProxyIPTablesConfiguration{ IPTables: kubeproxyconfigv1alpha1.KubeProxyIPTablesConfiguration{
MasqueradeBit: pointer.Int32(14), MasqueradeBit: ptr.To[int32](14),
MasqueradeAll: false, MasqueradeAll: false,
LocalhostNodePorts: pointer.Bool(true), LocalhostNodePorts: ptr.To(true),
SyncPeriod: metav1.Duration{Duration: 30 * time.Second}, SyncPeriod: metav1.Duration{Duration: 30 * time.Second},
MinSyncPeriod: metav1.Duration{Duration: 1 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 1 * time.Second},
}, },

View File

@ -27,7 +27,7 @@ import (
logsapi "k8s.io/component-base/logs/api/v1" logsapi "k8s.io/component-base/logs/api/v1"
kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config" kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config"
"k8s.io/utils/pointer" "k8s.io/utils/ptr"
) )
func TestValidateKubeProxyConfiguration(t *testing.T) { func TestValidateKubeProxyConfiguration(t *testing.T) {
@ -54,8 +54,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 5 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 5 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -74,8 +74,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -94,8 +94,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -114,8 +114,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -134,8 +134,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -154,8 +154,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -174,8 +174,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -194,8 +194,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -218,8 +218,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -256,8 +256,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -280,8 +280,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -304,8 +304,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -328,8 +328,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -352,8 +352,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -376,8 +376,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -402,8 +402,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
// not specifying valid period in IPVS mode. // not specifying valid period in IPVS mode.
Mode: kubeproxyconfig.ProxyModeIPVS, Mode: kubeproxyconfig.ProxyModeIPVS,
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -426,8 +426,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -454,8 +454,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -482,8 +482,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -507,8 +507,8 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
}, },
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{ Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
}, },
@ -557,7 +557,7 @@ func TestValidateKubeProxyIPTablesConfiguration(t *testing.T) {
}, },
"valid custom MasqueradeBit": { "valid custom MasqueradeBit": {
config: kubeproxyconfig.KubeProxyIPTablesConfiguration{ config: kubeproxyconfig.KubeProxyIPTablesConfiguration{
MasqueradeBit: pointer.Int32(5), MasqueradeBit: ptr.To[int32](5),
MasqueradeAll: true, MasqueradeAll: true,
SyncPeriod: metav1.Duration{Duration: 5 * time.Second}, SyncPeriod: metav1.Duration{Duration: 5 * time.Second},
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
@ -575,7 +575,7 @@ func TestValidateKubeProxyIPTablesConfiguration(t *testing.T) {
}, },
"MinSyncPeriod must be > 0": { "MinSyncPeriod must be > 0": {
config: kubeproxyconfig.KubeProxyIPTablesConfiguration{ config: kubeproxyconfig.KubeProxyIPTablesConfiguration{
MasqueradeBit: pointer.Int32(5), MasqueradeBit: ptr.To[int32](5),
MasqueradeAll: true, MasqueradeAll: true,
SyncPeriod: metav1.Duration{Duration: 5 * time.Second}, SyncPeriod: metav1.Duration{Duration: 5 * time.Second},
MinSyncPeriod: metav1.Duration{Duration: -1 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: -1 * time.Second},
@ -584,7 +584,7 @@ func TestValidateKubeProxyIPTablesConfiguration(t *testing.T) {
}, },
"MasqueradeBit cannot be < 0": { "MasqueradeBit cannot be < 0": {
config: kubeproxyconfig.KubeProxyIPTablesConfiguration{ config: kubeproxyconfig.KubeProxyIPTablesConfiguration{
MasqueradeBit: pointer.Int32(-10), MasqueradeBit: ptr.To[int32](-10),
MasqueradeAll: true, MasqueradeAll: true,
SyncPeriod: metav1.Duration{Duration: 5 * time.Second}, SyncPeriod: metav1.Duration{Duration: 5 * time.Second},
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second},
@ -593,7 +593,7 @@ func TestValidateKubeProxyIPTablesConfiguration(t *testing.T) {
}, },
"SyncPeriod must be >= MinSyncPeriod": { "SyncPeriod must be >= MinSyncPeriod": {
config: kubeproxyconfig.KubeProxyIPTablesConfiguration{ config: kubeproxyconfig.KubeProxyIPTablesConfiguration{
MasqueradeBit: pointer.Int32(5), MasqueradeBit: ptr.To[int32](5),
MasqueradeAll: true, MasqueradeAll: true,
SyncPeriod: metav1.Duration{Duration: 1 * time.Second}, SyncPeriod: metav1.Duration{Duration: 1 * time.Second},
MinSyncPeriod: metav1.Duration{Duration: 5 * time.Second}, MinSyncPeriod: metav1.Duration{Duration: 5 * time.Second},
@ -723,8 +723,8 @@ func TestValidateKubeProxyConntrackConfiguration(t *testing.T) {
}{ }{
"valid 5 second timeouts": { "valid 5 second timeouts": {
config: kubeproxyconfig.KubeProxyConntrackConfiguration{ config: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
UDPTimeout: metav1.Duration{Duration: 5 * time.Second}, UDPTimeout: metav1.Duration{Duration: 5 * time.Second},
@ -734,8 +734,8 @@ func TestValidateKubeProxyConntrackConfiguration(t *testing.T) {
}, },
"valid duration equal to 0 second timeout": { "valid duration equal to 0 second timeout": {
config: kubeproxyconfig.KubeProxyConntrackConfiguration{ config: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 0 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 0 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 0 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 0 * time.Second},
UDPTimeout: metav1.Duration{Duration: 0 * time.Second}, UDPTimeout: metav1.Duration{Duration: 0 * time.Second},
@ -745,8 +745,8 @@ func TestValidateKubeProxyConntrackConfiguration(t *testing.T) {
}, },
"invalid MaxPerCore < 0": { "invalid MaxPerCore < 0": {
config: kubeproxyconfig.KubeProxyConntrackConfiguration{ config: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(-1), MaxPerCore: ptr.To[int32](-1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
UDPTimeout: metav1.Duration{Duration: 5 * time.Second}, UDPTimeout: metav1.Duration{Duration: 5 * time.Second},
@ -756,8 +756,8 @@ func TestValidateKubeProxyConntrackConfiguration(t *testing.T) {
}, },
"invalid minimum < 0": { "invalid minimum < 0": {
config: kubeproxyconfig.KubeProxyConntrackConfiguration{ config: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(-1), Min: ptr.To[int32](-1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
UDPTimeout: metav1.Duration{Duration: 5 * time.Second}, UDPTimeout: metav1.Duration{Duration: 5 * time.Second},
@ -767,8 +767,8 @@ func TestValidateKubeProxyConntrackConfiguration(t *testing.T) {
}, },
"invalid TCPEstablishedTimeout < 0": { "invalid TCPEstablishedTimeout < 0": {
config: kubeproxyconfig.KubeProxyConntrackConfiguration{ config: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: -5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: -5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
UDPTimeout: metav1.Duration{Duration: 5 * time.Second}, UDPTimeout: metav1.Duration{Duration: 5 * time.Second},
@ -778,8 +778,8 @@ func TestValidateKubeProxyConntrackConfiguration(t *testing.T) {
}, },
"invalid TCPCloseWaitTimeout < 0": { "invalid TCPCloseWaitTimeout < 0": {
config: kubeproxyconfig.KubeProxyConntrackConfiguration{ config: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: -5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: -5 * time.Second},
UDPTimeout: metav1.Duration{Duration: 5 * time.Second}, UDPTimeout: metav1.Duration{Duration: 5 * time.Second},
@ -789,8 +789,8 @@ func TestValidateKubeProxyConntrackConfiguration(t *testing.T) {
}, },
"invalid UDPTimeout < 0": { "invalid UDPTimeout < 0": {
config: kubeproxyconfig.KubeProxyConntrackConfiguration{ config: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
UDPTimeout: metav1.Duration{Duration: -5 * time.Second}, UDPTimeout: metav1.Duration{Duration: -5 * time.Second},
@ -800,8 +800,8 @@ func TestValidateKubeProxyConntrackConfiguration(t *testing.T) {
}, },
"invalid UDPStreamTimeout < 0": { "invalid UDPStreamTimeout < 0": {
config: kubeproxyconfig.KubeProxyConntrackConfiguration{ config: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: pointer.Int32(1), MaxPerCore: ptr.To[int32](1),
Min: pointer.Int32(1), Min: ptr.To[int32](1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second},
UDPTimeout: metav1.Duration{Duration: 5 * time.Second}, UDPTimeout: metav1.Duration{Duration: 5 * time.Second},

View File

@ -30,7 +30,7 @@ import (
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
ktesting "k8s.io/client-go/testing" ktesting "k8s.io/client-go/testing"
utilpointer "k8s.io/utils/pointer" "k8s.io/utils/ptr"
) )
func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) { func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) {
@ -83,7 +83,6 @@ func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) {
} }
func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) { func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) {
tcp := v1.ProtocolTCP
endpoints1v1 := &discoveryv1.EndpointSlice{ endpoints1v1 := &discoveryv1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "e1"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "e1"},
AddressType: discoveryv1.AddressTypeIPv4, AddressType: discoveryv1.AddressTypeIPv4,
@ -93,8 +92,8 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) {
}, },
}}, }},
Ports: []discoveryv1.EndpointPort{{ Ports: []discoveryv1.EndpointPort{{
Port: utilpointer.Int32(8080), Port: ptr.To[int32](8080),
Protocol: &tcp, Protocol: ptr.To(v1.ProtocolTCP),
}}, }},
} }
endpoints1v2 := &discoveryv1.EndpointSlice{ endpoints1v2 := &discoveryv1.EndpointSlice{
@ -107,8 +106,8 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) {
}, },
}}, }},
Ports: []discoveryv1.EndpointPort{{ Ports: []discoveryv1.EndpointPort{{
Port: utilpointer.Int32(8080), Port: ptr.To[int32](8080),
Protocol: &tcp, Protocol: ptr.To(v1.ProtocolTCP),
}}, }},
} }
endpoints2 := &discoveryv1.EndpointSlice{ endpoints2 := &discoveryv1.EndpointSlice{
@ -120,8 +119,8 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) {
}, },
}}, }},
Ports: []discoveryv1.EndpointPort{{ Ports: []discoveryv1.EndpointPort{{
Port: utilpointer.Int32(8080), Port: ptr.To[int32](8080),
Protocol: &tcp, Protocol: ptr.To(v1.ProtocolTCP),
}}, }},
} }

View File

@ -32,7 +32,7 @@ import (
informers "k8s.io/client-go/informers" informers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
ktesting "k8s.io/client-go/testing" ktesting "k8s.io/client-go/testing"
utilpointer "k8s.io/utils/pointer" "k8s.io/utils/ptr"
) )
type sortedServices []*v1.Service type sortedServices []*v1.Service
@ -345,7 +345,7 @@ func TestNewEndpointsMultipleHandlersAddedAndNotified(t *testing.T) {
}, { }, {
Addresses: []string{"2.2.2.2"}, Addresses: []string{"2.2.2.2"},
}}, }},
Ports: []discoveryv1.EndpointPort{{Port: utilpointer.Int32(80)}}, Ports: []discoveryv1.EndpointPort{{Port: ptr.To[int32](80)}},
} }
endpoints2 := &discoveryv1.EndpointSlice{ endpoints2 := &discoveryv1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"},
@ -355,7 +355,7 @@ func TestNewEndpointsMultipleHandlersAddedAndNotified(t *testing.T) {
}, { }, {
Addresses: []string{"4.4.4.4"}, Addresses: []string{"4.4.4.4"},
}}, }},
Ports: []discoveryv1.EndpointPort{{Port: utilpointer.Int32(80)}}, Ports: []discoveryv1.EndpointPort{{Port: ptr.To[int32](80)}},
} }
fakeWatch.Add(endpoints1) fakeWatch.Add(endpoints1)
fakeWatch.Add(endpoints2) fakeWatch.Add(endpoints2)
@ -391,7 +391,7 @@ func TestNewEndpointsMultipleHandlersAddRemoveSetAndNotified(t *testing.T) {
}, { }, {
Addresses: []string{"2.2.2.2"}, Addresses: []string{"2.2.2.2"},
}}, }},
Ports: []discoveryv1.EndpointPort{{Port: utilpointer.Int32(80)}}, Ports: []discoveryv1.EndpointPort{{Port: ptr.To[int32](80)}},
} }
endpoints2 := &discoveryv1.EndpointSlice{ endpoints2 := &discoveryv1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"},
@ -401,7 +401,7 @@ func TestNewEndpointsMultipleHandlersAddRemoveSetAndNotified(t *testing.T) {
}, { }, {
Addresses: []string{"4.4.4.4"}, Addresses: []string{"4.4.4.4"},
}}, }},
Ports: []discoveryv1.EndpointPort{{Port: utilpointer.Int32(80)}}, Ports: []discoveryv1.EndpointPort{{Port: ptr.To[int32](80)}},
} }
fakeWatch.Add(endpoints1) fakeWatch.Add(endpoints1)
fakeWatch.Add(endpoints2) fakeWatch.Add(endpoints2)
@ -419,7 +419,7 @@ func TestNewEndpointsMultipleHandlersAddRemoveSetAndNotified(t *testing.T) {
}, { }, {
Addresses: []string{"6.6.6.6"}, Addresses: []string{"6.6.6.6"},
}}, }},
Ports: []discoveryv1.EndpointPort{{Port: utilpointer.Int32(80)}}, Ports: []discoveryv1.EndpointPort{{Port: ptr.To[int32](80)}},
} }
fakeWatch.Add(endpoints3) fakeWatch.Add(endpoints3)
endpoints = []*discoveryv1.EndpointSlice{endpoints2, endpoints1, endpoints3} endpoints = []*discoveryv1.EndpointSlice{endpoints2, endpoints1, endpoints3}
@ -433,7 +433,7 @@ func TestNewEndpointsMultipleHandlersAddRemoveSetAndNotified(t *testing.T) {
Endpoints: []discoveryv1.Endpoint{{ Endpoints: []discoveryv1.Endpoint{{
Addresses: []string{"7.7.7.7"}, Addresses: []string{"7.7.7.7"},
}}, }},
Ports: []discoveryv1.EndpointPort{{Port: utilpointer.Int32(80)}}, Ports: []discoveryv1.EndpointPort{{Port: ptr.To[int32](80)}},
} }
fakeWatch.Modify(endpoints1v2) fakeWatch.Modify(endpoints1v2)
endpoints = []*discoveryv1.EndpointSlice{endpoints2, endpoints1v2, endpoints3} endpoints = []*discoveryv1.EndpointSlice{endpoints2, endpoints1v2, endpoints3}

View File

@ -27,7 +27,7 @@ import (
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/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/pointer" "k8s.io/utils/ptr"
) )
func (proxier *FakeProxier) addEndpointSlice(slice *discovery.EndpointSlice) { func (proxier *FakeProxier) addEndpointSlice(slice *discovery.EndpointSlice) {
@ -184,9 +184,6 @@ func makeTestEndpointSlice(namespace, name string, slice int, epsFunc func(*disc
} }
func TestUpdateEndpointsMap(t *testing.T) { func TestUpdateEndpointsMap(t *testing.T) {
var nodeName = testHostname
udp := v1.ProtocolUDP
emptyEndpoint := func(eps *discovery.EndpointSlice) { emptyEndpoint := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{} eps.Endpoints = []discovery.Endpoint{}
} }
@ -195,61 +192,61 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(""), Name: ptr.To(""),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
unnamedPortReady := func(eps *discovery.EndpointSlice) { unnamedPortReady := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
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),
}, },
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(""), Name: ptr.To(""),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
unnamedPortTerminating := func(eps *discovery.EndpointSlice) { unnamedPortTerminating := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
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),
}, },
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(""), Name: ptr.To(""),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
unnamedPortLocal := func(eps *discovery.EndpointSlice) { unnamedPortLocal := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(""), Name: ptr.To(""),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
namedPortLocal := func(eps *discovery.EndpointSlice) { namedPortLocal := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p11"), Name: ptr.To("p11"),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
namedPort := func(eps *discovery.EndpointSlice) { namedPort := func(eps *discovery.EndpointSlice) {
@ -257,9 +254,9 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p11"), Name: ptr.To("p11"),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
namedPortRenamed := func(eps *discovery.EndpointSlice) { namedPortRenamed := func(eps *discovery.EndpointSlice) {
@ -267,9 +264,9 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p11-2"), Name: ptr.To("p11-2"),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
namedPortRenumbered := func(eps *discovery.EndpointSlice) { namedPortRenumbered := func(eps *discovery.EndpointSlice) {
@ -277,9 +274,9 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p11"), Name: ptr.To("p11"),
Port: pointer.Int32(22), Port: ptr.To[int32](22),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
namedPortsLocalNoLocal := func(eps *discovery.EndpointSlice) { namedPortsLocalNoLocal := func(eps *discovery.EndpointSlice) {
@ -287,16 +284,16 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
}, { }, {
Addresses: []string{"1.1.1.2"}, Addresses: []string{"1.1.1.2"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p11"), Name: ptr.To("p11"),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}, { }, {
Name: pointer.String("p12"), Name: ptr.To("p12"),
Port: pointer.Int32(12), Port: ptr.To[int32](12),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
multipleSubsets_s1 := func(eps *discovery.EndpointSlice) { multipleSubsets_s1 := func(eps *discovery.EndpointSlice) {
@ -304,9 +301,9 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p11"), Name: ptr.To("p11"),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
multipleSubsets_s2 := func(eps *discovery.EndpointSlice) { multipleSubsets_s2 := func(eps *discovery.EndpointSlice) {
@ -314,9 +311,9 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.2"}, Addresses: []string{"1.1.1.2"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p12"), Name: ptr.To("p12"),
Port: pointer.Int32(12), Port: ptr.To[int32](12),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
multipleSubsetsWithLocal_s1 := func(eps *discovery.EndpointSlice) { multipleSubsetsWithLocal_s1 := func(eps *discovery.EndpointSlice) {
@ -324,35 +321,35 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p11"), Name: ptr.To("p11"),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
multipleSubsetsWithLocal_s2 := func(eps *discovery.EndpointSlice) { multipleSubsetsWithLocal_s2 := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{"1.1.1.2"}, Addresses: []string{"1.1.1.2"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p12"), Name: ptr.To("p12"),
Port: pointer.Int32(12), Port: ptr.To[int32](12),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
multipleSubsetsMultiplePortsLocal_s1 := func(eps *discovery.EndpointSlice) { multipleSubsetsMultiplePortsLocal_s1 := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p11"), Name: ptr.To("p11"),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}, { }, {
Name: pointer.String("p12"), Name: ptr.To("p12"),
Port: pointer.Int32(12), Port: ptr.To[int32](12),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
multipleSubsetsMultiplePortsLocal_s2 := func(eps *discovery.EndpointSlice) { multipleSubsetsMultiplePortsLocal_s2 := func(eps *discovery.EndpointSlice) {
@ -360,9 +357,9 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.3"}, Addresses: []string{"1.1.1.3"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p13"), Name: ptr.To("p13"),
Port: pointer.Int32(13), Port: ptr.To[int32](13),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
multipleSubsetsIPsPorts1_s1 := func(eps *discovery.EndpointSlice) { multipleSubsetsIPsPorts1_s1 := func(eps *discovery.EndpointSlice) {
@ -370,16 +367,16 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
}, { }, {
Addresses: []string{"1.1.1.2"}, Addresses: []string{"1.1.1.2"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p11"), Name: ptr.To("p11"),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}, { }, {
Name: pointer.String("p12"), Name: ptr.To("p12"),
Port: pointer.Int32(12), Port: ptr.To[int32](12),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
multipleSubsetsIPsPorts1_s2 := func(eps *discovery.EndpointSlice) { multipleSubsetsIPsPorts1_s2 := func(eps *discovery.EndpointSlice) {
@ -387,16 +384,16 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.3"}, Addresses: []string{"1.1.1.3"},
}, { }, {
Addresses: []string{"1.1.1.4"}, Addresses: []string{"1.1.1.4"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p13"), Name: ptr.To("p13"),
Port: pointer.Int32(13), Port: ptr.To[int32](13),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}, { }, {
Name: pointer.String("p14"), Name: ptr.To("p14"),
Port: pointer.Int32(14), Port: ptr.To[int32](14),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
multipleSubsetsIPsPorts2 := func(eps *discovery.EndpointSlice) { multipleSubsetsIPsPorts2 := func(eps *discovery.EndpointSlice) {
@ -404,16 +401,16 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"2.2.2.1"}, Addresses: []string{"2.2.2.1"},
}, { }, {
Addresses: []string{"2.2.2.2"}, Addresses: []string{"2.2.2.2"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p21"), Name: ptr.To("p21"),
Port: pointer.Int32(21), Port: ptr.To[int32](21),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}, { }, {
Name: pointer.String("p22"), Name: ptr.To("p22"),
Port: pointer.Int32(22), Port: ptr.To[int32](22),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
complexBefore1 := func(eps *discovery.EndpointSlice) { complexBefore1 := func(eps *discovery.EndpointSlice) {
@ -421,59 +418,59 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p11"), Name: ptr.To("p11"),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
complexBefore2_s1 := func(eps *discovery.EndpointSlice) { complexBefore2_s1 := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{"2.2.2.2"}, Addresses: []string{"2.2.2.2"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}, { }, {
Addresses: []string{"2.2.2.22"}, Addresses: []string{"2.2.2.22"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p22"), Name: ptr.To("p22"),
Port: pointer.Int32(22), Port: ptr.To[int32](22),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
complexBefore2_s2 := func(eps *discovery.EndpointSlice) { complexBefore2_s2 := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{"2.2.2.3"}, Addresses: []string{"2.2.2.3"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p23"), Name: ptr.To("p23"),
Port: pointer.Int32(23), Port: ptr.To[int32](23),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
complexBefore4_s1 := func(eps *discovery.EndpointSlice) { complexBefore4_s1 := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{"4.4.4.4"}, Addresses: []string{"4.4.4.4"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}, { }, {
Addresses: []string{"4.4.4.5"}, Addresses: []string{"4.4.4.5"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p44"), Name: ptr.To("p44"),
Port: pointer.Int32(44), Port: ptr.To[int32](44),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
complexBefore4_s2 := func(eps *discovery.EndpointSlice) { complexBefore4_s2 := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{"4.4.4.6"}, Addresses: []string{"4.4.4.6"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p45"), Name: ptr.To("p45"),
Port: pointer.Int32(45), Port: ptr.To[int32](45),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
complexAfter1_s1 := func(eps *discovery.EndpointSlice) { complexAfter1_s1 := func(eps *discovery.EndpointSlice) {
@ -483,9 +480,9 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.11"}, Addresses: []string{"1.1.1.11"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p11"), Name: ptr.To("p11"),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
complexAfter1_s2 := func(eps *discovery.EndpointSlice) { complexAfter1_s2 := func(eps *discovery.EndpointSlice) {
@ -493,13 +490,13 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"1.1.1.2"}, Addresses: []string{"1.1.1.2"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p12"), Name: ptr.To("p12"),
Port: pointer.Int32(12), Port: ptr.To[int32](12),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}, { }, {
Name: pointer.String("p122"), Name: ptr.To("p122"),
Port: pointer.Int32(122), Port: ptr.To[int32](122),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
complexAfter3 := func(eps *discovery.EndpointSlice) { complexAfter3 := func(eps *discovery.EndpointSlice) {
@ -507,20 +504,20 @@ func TestUpdateEndpointsMap(t *testing.T) {
Addresses: []string{"3.3.3.3"}, Addresses: []string{"3.3.3.3"},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p33"), Name: ptr.To("p33"),
Port: pointer.Int32(33), Port: ptr.To[int32](33),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
complexAfter4 := func(eps *discovery.EndpointSlice) { complexAfter4 := func(eps *discovery.EndpointSlice) {
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{"4.4.4.4"}, Addresses: []string{"4.4.4.4"},
NodeName: &nodeName, NodeName: ptr.To(testHostname),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String("p44"), Name: ptr.To("p44"),
Port: pointer.Int32(44), Port: ptr.To[int32](44),
Protocol: &udp, Protocol: ptr.To(v1.ProtocolUDP),
}} }}
} }
@ -1112,7 +1109,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
for tci, tc := range testCases { for tci, tc := range testCases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
fp := newFakeProxier(v1.IPv4Protocol, time.Time{}) fp := newFakeProxier(v1.IPv4Protocol, time.Time{})
fp.hostname = nodeName fp.hostname = testHostname
// First check that after adding all previous versions of endpoints, // First check that after adding all previous versions of endpoints,
// the fp.previousEndpointsMap is as we expect. // the fp.previousEndpointsMap is as we expect.
@ -1199,7 +1196,6 @@ func TestLastChangeTriggerTime(t *testing.T) {
t3 := t2.Add(time.Second) t3 := t2.Add(time.Second)
createEndpoints := func(namespace, name string, triggerTime time.Time) *discovery.EndpointSlice { createEndpoints := func(namespace, name string, triggerTime time.Time) *discovery.EndpointSlice {
tcp := v1.ProtocolTCP
return &discovery.EndpointSlice{ return &discovery.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
@ -1216,9 +1212,9 @@ func TestLastChangeTriggerTime(t *testing.T) {
Addresses: []string{"1.1.1.1"}, Addresses: []string{"1.1.1.1"},
}}, }},
Ports: []discovery.EndpointPort{{ Ports: []discovery.EndpointPort{{
Name: pointer.String("p11"), Name: ptr.To("p11"),
Port: pointer.Int32(11), Port: ptr.To[int32](11),
Protocol: &tcp, Protocol: ptr.To(v1.ProtocolTCP),
}}, }},
} }
} }
@ -1335,7 +1331,7 @@ func TestLastChangeTriggerTime(t *testing.T) {
} }
func TestEndpointSliceUpdate(t *testing.T) { func TestEndpointSliceUpdate(t *testing.T) {
fqdnSlice := generateEndpointSlice("svc1", "ns1", 2, 5, 999, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}) fqdnSlice := generateEndpointSlice("svc1", "ns1", 2, 5, 999, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)})
fqdnSlice.AddressType = discovery.AddressTypeFQDN fqdnSlice.AddressType = discovery.AddressTypeFQDN
testCases := map[string]struct { testCases := map[string]struct {
@ -1353,7 +1349,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
startingSlices: []*discovery.EndpointSlice{}, startingSlices: []*discovery.EndpointSlice{},
endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil), endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil),
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
paramRemoveSlice: false, paramRemoveSlice: false,
expectedReturnVal: true, expectedReturnVal: true,
expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{ expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{
@ -1373,11 +1369,11 @@ func TestEndpointSliceUpdate(t *testing.T) {
// test no modification to state - current change should be nil as nothing changes // test no modification to state - current change should be nil as nothing changes
"add the same slice that already exists": { "add the same slice that already exists": {
startingSlices: []*discovery.EndpointSlice{ startingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil), endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil),
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
paramRemoveSlice: false, paramRemoveSlice: false,
expectedReturnVal: false, expectedReturnVal: false,
expectedCurrentChange: nil, expectedCurrentChange: nil,
@ -1386,7 +1382,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
// ensure that only valide address types are processed // ensure that only valide address types are processed
"add an FQDN slice (invalid address type)": { "add an FQDN slice (invalid address type)": {
startingSlices: []*discovery.EndpointSlice{ startingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil), endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil),
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
@ -1399,12 +1395,12 @@ func TestEndpointSliceUpdate(t *testing.T) {
// test additions to existing state // test additions to existing state
"add a slice that overlaps with existing state": { "add a slice that overlaps with existing state": {
startingSlices: []*discovery.EndpointSlice{ startingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
generateEndpointSlice("svc1", "ns1", 2, 2, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 2, 2, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil), endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil),
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 5, 999, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 5, 999, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
paramRemoveSlice: false, paramRemoveSlice: false,
expectedReturnVal: true, expectedReturnVal: true,
expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{ expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{
@ -1432,12 +1428,12 @@ func TestEndpointSliceUpdate(t *testing.T) {
// test additions to existing state with partially overlapping slices and ports // test additions to existing state with partially overlapping slices and ports
"add a slice that overlaps with existing state and partial ports": { "add a slice that overlaps with existing state and partial ports": {
startingSlices: []*discovery.EndpointSlice{ startingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
generateEndpointSlice("svc1", "ns1", 2, 2, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 2, 2, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil), endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil),
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
paramEndpointSlice: generateEndpointSliceWithOffset("svc1", "ns1", 3, 1, 5, 999, 999, []string{"host1"}, []*int32{pointer.Int32(80)}), paramEndpointSlice: generateEndpointSliceWithOffset("svc1", "ns1", 3, 1, 5, 999, 999, []string{"host1"}, []*int32{ptr.To[int32](80)}),
paramRemoveSlice: false, paramRemoveSlice: false,
expectedReturnVal: true, expectedReturnVal: true,
expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{ expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{
@ -1463,12 +1459,12 @@ func TestEndpointSliceUpdate(t *testing.T) {
// test deletions from existing state with partially overlapping slices and ports // test deletions from existing state with partially overlapping slices and ports
"remove a slice that overlaps with existing state": { "remove a slice that overlaps with existing state": {
startingSlices: []*discovery.EndpointSlice{ startingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
generateEndpointSlice("svc1", "ns1", 2, 2, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 2, 2, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil), endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil),
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 5, 999, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 5, 999, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
paramRemoveSlice: true, paramRemoveSlice: true,
expectedReturnVal: true, expectedReturnVal: true,
expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{ expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{
@ -1486,12 +1482,12 @@ func TestEndpointSliceUpdate(t *testing.T) {
// ensure a removal that has no effect turns into a no-op // ensure a removal that has no effect turns into a no-op
"remove a slice that doesn't even exist in current state": { "remove a slice that doesn't even exist in current state": {
startingSlices: []*discovery.EndpointSlice{ startingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 5, 999, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 5, 999, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
generateEndpointSlice("svc1", "ns1", 2, 2, 999, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 2, 2, 999, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil), endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil),
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 3, 5, 999, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 3, 5, 999, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
paramRemoveSlice: true, paramRemoveSlice: true,
expectedReturnVal: false, expectedReturnVal: false,
expectedCurrentChange: nil, expectedCurrentChange: nil,
@ -1500,11 +1496,11 @@ func TestEndpointSliceUpdate(t *testing.T) {
// start with all endpoints ready, transition to no endpoints ready // start with all endpoints ready, transition to no endpoints ready
"transition all endpoints to unready state": { "transition all endpoints to unready state": {
startingSlices: []*discovery.EndpointSlice{ startingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil), endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil),
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 3, 1, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 3, 1, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
paramRemoveSlice: false, paramRemoveSlice: false,
expectedReturnVal: true, expectedReturnVal: true,
expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{ expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{
@ -1524,11 +1520,11 @@ func TestEndpointSliceUpdate(t *testing.T) {
// start with no endpoints ready, transition to all endpoints ready // start with no endpoints ready, transition to all endpoints ready
"transition all endpoints to ready state": { "transition all endpoints to ready state": {
startingSlices: []*discovery.EndpointSlice{ startingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 2, 1, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 2, 1, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil), endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil),
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 2, 999, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 2, 999, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
paramRemoveSlice: false, paramRemoveSlice: false,
expectedReturnVal: true, expectedReturnVal: true,
expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{ expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{
@ -1546,12 +1542,12 @@ func TestEndpointSliceUpdate(t *testing.T) {
// start with some endpoints ready, transition to more endpoints ready // start with some endpoints ready, transition to more endpoints ready
"transition some endpoints to ready state": { "transition some endpoints to ready state": {
startingSlices: []*discovery.EndpointSlice{ startingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 2, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 3, 2, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
generateEndpointSlice("svc1", "ns1", 2, 2, 2, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 2, 2, 2, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil), endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil),
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 3, 3, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 3, 3, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
paramRemoveSlice: false, paramRemoveSlice: false,
expectedReturnVal: true, expectedReturnVal: true,
expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{ expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{
@ -1575,12 +1571,12 @@ func TestEndpointSliceUpdate(t *testing.T) {
// start with some endpoints ready, transition to some terminating // start with some endpoints ready, transition to some terminating
"transition some endpoints to terminating state": { "transition some endpoints to terminating state": {
startingSlices: []*discovery.EndpointSlice{ startingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 2, 2, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 3, 2, 2, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
generateEndpointSlice("svc1", "ns1", 2, 2, 2, 2, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 2, 2, 2, 2, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil), endpointsChangeTracker: NewEndpointsChangeTracker("host1", nil, v1.IPv4Protocol, nil, nil),
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 3, 3, 2, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), paramEndpointSlice: generateEndpointSlice("svc1", "ns1", 1, 3, 3, 2, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
paramRemoveSlice: false, paramRemoveSlice: false,
expectedReturnVal: true, expectedReturnVal: true,
expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{ expectedCurrentChange: map[ServicePortName][]*BaseEndpointInfo{
@ -1663,7 +1659,7 @@ func TestCheckoutChanges(t *testing.T) {
}}, }},
appliedSlices: []*discovery.EndpointSlice{}, appliedSlices: []*discovery.EndpointSlice{},
pendingSlices: []*discovery.EndpointSlice{ pendingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 3, 2, []string{"host1"}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 3, 3, 2, []string{"host1"}, []*int32{ptr.To[int32](80)}),
}, },
}, },
"removing port in update": { "removing port in update": {
@ -1690,10 +1686,10 @@ func TestCheckoutChanges(t *testing.T) {
}, },
}}, }},
appliedSlices: []*discovery.EndpointSlice{ appliedSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 3, 999, []string{"host1"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 3, 3, 999, []string{"host1"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
pendingSlices: []*discovery.EndpointSlice{ pendingSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 3, 999, []string{"host1"}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 3, 3, 999, []string{"host1"}, []*int32{ptr.To[int32](80)}),
}, },
}, },
} }

View File

@ -26,7 +26,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer" "k8s.io/utils/ptr"
) )
func TestEndpointsMapFromESC(t *testing.T) { func TestEndpointsMapFromESC(t *testing.T) {
@ -40,7 +40,7 @@ func TestEndpointsMapFromESC(t *testing.T) {
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
hostname: "host1", hostname: "host1",
endpointSlices: []*discovery.EndpointSlice{ endpointSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80), pointer.Int32(443)}), generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80), ptr.To[int32](443)}),
}, },
expectedMap: map[ServicePortName][]*BaseEndpointInfo{ expectedMap: map[ServicePortName][]*BaseEndpointInfo{
makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): { makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): {
@ -58,8 +58,8 @@ func TestEndpointsMapFromESC(t *testing.T) {
"2 slices, same port": { "2 slices, same port": {
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
endpointSlices: []*discovery.EndpointSlice{ endpointSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{}, []*int32{ptr.To[int32](80)}),
generateEndpointSlice("svc1", "ns1", 2, 3, 999, 999, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 2, 3, 999, 999, []string{}, []*int32{ptr.To[int32](80)}),
}, },
expectedMap: map[ServicePortName][]*BaseEndpointInfo{ expectedMap: map[ServicePortName][]*BaseEndpointInfo{
makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): { makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): {
@ -77,8 +77,8 @@ func TestEndpointsMapFromESC(t *testing.T) {
"2 overlapping slices, same port": { "2 overlapping slices, same port": {
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
endpointSlices: []*discovery.EndpointSlice{ endpointSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{}, []*int32{ptr.To[int32](80)}),
generateEndpointSlice("svc1", "ns1", 1, 4, 999, 999, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 4, 999, 999, []string{}, []*int32{ptr.To[int32](80)}),
}, },
expectedMap: map[ServicePortName][]*BaseEndpointInfo{ expectedMap: map[ServicePortName][]*BaseEndpointInfo{
makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): { makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): {
@ -96,8 +96,8 @@ func TestEndpointsMapFromESC(t *testing.T) {
"2 slices, overlapping endpoints, some endpoints unready in 1 or both": { "2 slices, overlapping endpoints, some endpoints unready in 1 or both": {
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
endpointSlices: []*discovery.EndpointSlice{ endpointSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 10, 3, 999, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 10, 3, 999, []string{}, []*int32{ptr.To[int32](80)}),
generateEndpointSlice("svc1", "ns1", 1, 10, 6, 999, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 10, 6, 999, []string{}, []*int32{ptr.To[int32](80)}),
}, },
expectedMap: map[ServicePortName][]*BaseEndpointInfo{ expectedMap: map[ServicePortName][]*BaseEndpointInfo{
makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): { makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): {
@ -118,8 +118,8 @@ func TestEndpointsMapFromESC(t *testing.T) {
"2 slices, overlapping endpoints, some endpoints unready and some endpoints terminating": { "2 slices, overlapping endpoints, some endpoints unready and some endpoints terminating": {
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
endpointSlices: []*discovery.EndpointSlice{ endpointSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 10, 3, 5, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 10, 3, 5, []string{}, []*int32{ptr.To[int32](80)}),
generateEndpointSlice("svc1", "ns1", 1, 10, 6, 5, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 10, 6, 5, []string{}, []*int32{ptr.To[int32](80)}),
}, },
expectedMap: map[ServicePortName][]*BaseEndpointInfo{ expectedMap: map[ServicePortName][]*BaseEndpointInfo{
makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): { makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): {
@ -139,8 +139,8 @@ func TestEndpointsMapFromESC(t *testing.T) {
"2 slices, overlapping endpoints, all unready": { "2 slices, overlapping endpoints, all unready": {
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
endpointSlices: []*discovery.EndpointSlice{ endpointSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 10, 1, 999, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 10, 1, 999, []string{}, []*int32{ptr.To[int32](80)}),
generateEndpointSlice("svc1", "ns1", 1, 10, 1, 999, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 10, 1, 999, []string{}, []*int32{ptr.To[int32](80)}),
}, },
expectedMap: map[ServicePortName][]*BaseEndpointInfo{ expectedMap: map[ServicePortName][]*BaseEndpointInfo{
makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): { makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): {
@ -160,9 +160,9 @@ func TestEndpointsMapFromESC(t *testing.T) {
"3 slices with different services and namespaces": { "3 slices with different services and namespaces": {
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
endpointSlices: []*discovery.EndpointSlice{ endpointSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{}, []*int32{ptr.To[int32](80)}),
generateEndpointSlice("svc2", "ns1", 2, 3, 999, 999, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc2", "ns1", 2, 3, 999, 999, []string{}, []*int32{ptr.To[int32](80)}),
generateEndpointSlice("svc1", "ns2", 3, 3, 999, 999, []string{}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns2", 3, 3, 999, 999, []string{}, []*int32{ptr.To[int32](80)}),
}, },
expectedMap: map[ServicePortName][]*BaseEndpointInfo{ expectedMap: map[ServicePortName][]*BaseEndpointInfo{
makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): { makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): {
@ -188,8 +188,8 @@ func TestEndpointsMapFromESC(t *testing.T) {
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
hostname: "host1", hostname: "host1",
endpointSlices: []*discovery.EndpointSlice{ endpointSlices: []*discovery.EndpointSlice{
generateEndpointSliceWithOffset("svc1", "ns1", 1, 1, 2, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80)}), generateEndpointSliceWithOffset("svc1", "ns1", 1, 1, 2, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80)}),
generateEndpointSliceWithOffset("svc1", "ns1", 2, 1, 2, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(8080)}), generateEndpointSliceWithOffset("svc1", "ns1", 2, 1, 2, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](8080)}),
}, },
expectedMap: map[ServicePortName][]*BaseEndpointInfo{ expectedMap: map[ServicePortName][]*BaseEndpointInfo{
makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): { makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): {
@ -228,7 +228,7 @@ func TestEndpointInfoByServicePort(t *testing.T) {
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
hostname: "host1", hostname: "host1",
endpointSlices: []*discovery.EndpointSlice{ endpointSlices: []*discovery.EndpointSlice{
generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80)}), generateEndpointSlice("svc1", "ns1", 1, 3, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80)}),
}, },
expectedMap: spToEndpointMap{ expectedMap: spToEndpointMap{
makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): { makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): {
@ -260,8 +260,8 @@ func TestEndpointInfoByServicePort(t *testing.T) {
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"}, namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
hostname: "host1", hostname: "host1",
endpointSlices: []*discovery.EndpointSlice{ endpointSlices: []*discovery.EndpointSlice{
generateEndpointSliceWithOffset("svc1", "ns1", 1, 1, 2, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(80)}), generateEndpointSliceWithOffset("svc1", "ns1", 1, 1, 2, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](80)}),
generateEndpointSliceWithOffset("svc1", "ns1", 2, 1, 2, 999, 999, []string{"host1", "host2"}, []*int32{pointer.Int32(8080)}), generateEndpointSliceWithOffset("svc1", "ns1", 2, 1, 2, 999, 999, []string{"host1", "host2"}, []*int32{ptr.To[int32](8080)}),
}, },
expectedMap: spToEndpointMap{ expectedMap: spToEndpointMap{
makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): { makeServicePortName("ns1", "svc1", "port-0", v1.ProtocolTCP): {
@ -317,9 +317,8 @@ func TestEndpointInfoByServicePort(t *testing.T) {
func TestEsInfoChanged(t *testing.T) { func TestEsInfoChanged(t *testing.T) {
p80 := int32(80) p80 := int32(80)
p443 := int32(443) p443 := int32(443)
tcpProto := v1.ProtocolTCP port80 := discovery.EndpointPort{Port: &p80, Name: ptr.To("http"), Protocol: ptr.To(v1.ProtocolTCP)}
port80 := discovery.EndpointPort{Port: &p80, Name: pointer.String("http"), Protocol: &tcpProto} port443 := discovery.EndpointPort{Port: &p443, Name: ptr.To("https"), Protocol: ptr.To(v1.ProtocolTCP)}
port443 := discovery.EndpointPort{Port: &p443, Name: pointer.String("https"), Protocol: &tcpProto}
endpoint1 := discovery.Endpoint{Addresses: []string{"10.0.1.0"}} endpoint1 := discovery.Endpoint{Addresses: []string{"10.0.1.0"}}
endpoint2 := discovery.Endpoint{Addresses: []string{"10.0.1.1"}} endpoint2 := discovery.Endpoint{Addresses: []string{"10.0.1.1"}}
@ -454,8 +453,6 @@ func TestEsInfoChanged(t *testing.T) {
} }
func generateEndpointSliceWithOffset(serviceName, namespace string, sliceNum, offset, numEndpoints, unreadyMod int, terminatingMod int, hosts []string, portNums []*int32) *discovery.EndpointSlice { func generateEndpointSliceWithOffset(serviceName, namespace string, sliceNum, offset, numEndpoints, unreadyMod int, terminatingMod int, hosts []string, portNums []*int32) *discovery.EndpointSlice {
tcpProtocol := v1.ProtocolTCP
endpointSlice := &discovery.EndpointSlice{ endpointSlice := &discovery.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-%d", serviceName, sliceNum), Name: fmt.Sprintf("%s-%d", serviceName, sliceNum),
@ -469,9 +466,9 @@ func generateEndpointSliceWithOffset(serviceName, namespace string, sliceNum, of
for i, portNum := range portNums { for i, portNum := range portNums {
endpointSlice.Ports = append(endpointSlice.Ports, discovery.EndpointPort{ endpointSlice.Ports = append(endpointSlice.Ports, discovery.EndpointPort{
Name: pointer.String(fmt.Sprintf("port-%d", i)), Name: ptr.To(fmt.Sprintf("port-%d", i)),
Port: portNum, Port: portNum,
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}) })
} }
@ -479,9 +476,9 @@ func generateEndpointSliceWithOffset(serviceName, namespace string, sliceNum, of
readyCondition := i%unreadyMod != 0 readyCondition := i%unreadyMod != 0
terminatingCondition := i%terminatingMod == 0 terminatingCondition := i%terminatingMod == 0
ready := pointer.Bool(readyCondition && !terminatingCondition) ready := ptr.To(readyCondition && !terminatingCondition)
serving := pointer.Bool(readyCondition) serving := ptr.To(readyCondition)
terminating := pointer.Bool(terminatingCondition) terminating := ptr.To(terminatingCondition)
endpoint := discovery.Endpoint{ endpoint := discovery.Endpoint{
Addresses: []string{fmt.Sprintf("10.0.%d.%d", offset, i)}, Addresses: []string{fmt.Sprintf("10.0.%d.%d", offset, i)},

View File

@ -27,7 +27,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
iptablestest "k8s.io/kubernetes/pkg/util/iptables/testing" iptablestest "k8s.io/kubernetes/pkg/util/iptables/testing"
netutils "k8s.io/utils/net" netutils "k8s.io/utils/net"
"k8s.io/utils/pointer" "k8s.io/utils/ptr"
) )
// kube-proxy generates iptables rules to forward traffic from Services to Endpoints // kube-proxy generates iptables rules to forward traffic from Services to Endpoints
@ -361,8 +361,6 @@ func generateServiceEndpoints(nServices, nEndpoints int, epsFunc func(eps *disco
baseEp := netutils.BigForIP(netutils.ParseIPSloppy("172.16.0.1")) baseEp := netutils.BigForIP(netutils.ParseIPSloppy("172.16.0.1"))
epPort := 8080 epPort := 8080
tcpProtocol := v1.ProtocolTCP
eps := &discovery.EndpointSlice{ eps := &discovery.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "ep", Name: "ep",
@ -371,9 +369,9 @@ func generateServiceEndpoints(nServices, nEndpoints int, epsFunc func(eps *disco
AddressType: discovery.AddressTypeIPv4, AddressType: discovery.AddressTypeIPv4,
Endpoints: []discovery.Endpoint{}, Endpoints: []discovery.Endpoint{},
Ports: []discovery.EndpointPort{{ Ports: []discovery.EndpointPort{{
Name: pointer.String(fmt.Sprintf("%d", epPort)), Name: ptr.To(fmt.Sprintf("%d", epPort)),
Port: pointer.Int32(int32(epPort)), Port: ptr.To(int32(epPort)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}}, }},
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,7 @@ import (
utilnode "k8s.io/kubernetes/pkg/util/node" utilnode "k8s.io/kubernetes/pkg/util/node"
utilexec "k8s.io/utils/exec" utilexec "k8s.io/utils/exec"
netutils "k8s.io/utils/net" netutils "k8s.io/utils/net"
utilpointer "k8s.io/utils/pointer" "k8s.io/utils/ptr"
"k8s.io/klog/v2" "k8s.io/klog/v2"
) )
@ -130,7 +130,7 @@ func NewHollowProxyOrDie(
Config: &proxyconfigapi.KubeProxyConfiguration{ Config: &proxyconfigapi.KubeProxyConfiguration{
Mode: proxyconfigapi.ProxyMode("fake"), Mode: proxyconfigapi.ProxyMode("fake"),
ConfigSyncPeriod: metav1.Duration{Duration: 30 * time.Second}, ConfigSyncPeriod: metav1.Duration{Duration: 30 * time.Second},
OOMScoreAdj: utilpointer.Int32Ptr(0), OOMScoreAdj: ptr.To[int32](0),
}, },
Client: client, Client: client,

View File

@ -37,7 +37,7 @@ import (
"k8s.io/kubernetes/pkg/proxy/healthcheck" "k8s.io/kubernetes/pkg/proxy/healthcheck"
fakehcn "k8s.io/kubernetes/pkg/proxy/winkernel/testing" fakehcn "k8s.io/kubernetes/pkg/proxy/winkernel/testing"
netutils "k8s.io/utils/net" netutils "k8s.io/utils/net"
"k8s.io/utils/pointer" "k8s.io/utils/ptr"
) )
const ( const (
@ -146,7 +146,6 @@ func TestCreateServiceVip(t *testing.T) {
Port: "p80", Port: "p80",
Protocol: v1.ProtocolTCP, Protocol: v1.ProtocolTCP,
} }
timeoutSeconds := v1.DefaultClientIPServiceAffinitySeconds
makeServiceMap(proxier, makeServiceMap(proxier,
makeTestService(svcPortName.Namespace, svcPortName.Name, func(svc *v1.Service) { makeTestService(svcPortName.Namespace, svcPortName.Name, func(svc *v1.Service) {
@ -156,7 +155,7 @@ func TestCreateServiceVip(t *testing.T) {
svc.Spec.SessionAffinity = v1.ServiceAffinityClientIP svc.Spec.SessionAffinity = v1.ServiceAffinityClientIP
svc.Spec.SessionAffinityConfig = &v1.SessionAffinityConfig{ svc.Spec.SessionAffinityConfig = &v1.SessionAffinityConfig{
ClientIP: &v1.ClientIPConfig{ ClientIP: &v1.ClientIPConfig{
TimeoutSeconds: &timeoutSeconds, TimeoutSeconds: ptr.To[int32](v1.DefaultClientIPServiceAffinitySeconds),
}, },
} }
svc.Spec.Ports = []v1.ServicePort{{ svc.Spec.Ports = []v1.ServicePort{{
@ -200,7 +199,6 @@ func TestCreateRemoteEndpointOverlay(t *testing.T) {
Port: "p80", Port: "p80",
Protocol: v1.ProtocolTCP, Protocol: v1.ProtocolTCP,
} }
tcpProtocol := v1.ProtocolTCP
makeServiceMap(proxier, makeServiceMap(proxier,
makeTestService(svcPortName.Namespace, svcPortName.Name, func(svc *v1.Service) { makeTestService(svcPortName.Namespace, svcPortName.Name, func(svc *v1.Service) {
@ -221,9 +219,9 @@ func TestCreateRemoteEndpointOverlay(t *testing.T) {
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(svcPortName.Port), Name: ptr.To(svcPortName.Port),
Port: pointer.Int32(int32(svcPort)), Port: ptr.To(int32(svcPort)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
}), }),
) )
@ -258,14 +256,13 @@ func TestCreateRemoteEndpointL2Bridge(t *testing.T) {
t.Error() t.Error()
} }
tcpProtocol := v1.ProtocolTCP
svcIP := "10.20.30.41" svcIP := "10.20.30.41"
svcPort := 80 svcPort := 80
svcNodePort := 3001 svcNodePort := 3001
svcPortName := proxy.ServicePortName{ svcPortName := proxy.ServicePortName{
NamespacedName: makeNSN("ns1", "svc1"), NamespacedName: makeNSN("ns1", "svc1"),
Port: "p80", Port: "p80",
Protocol: tcpProtocol, Protocol: v1.ProtocolTCP,
} }
makeServiceMap(proxier, makeServiceMap(proxier,
@ -275,7 +272,7 @@ func TestCreateRemoteEndpointL2Bridge(t *testing.T) {
svc.Spec.Ports = []v1.ServicePort{{ svc.Spec.Ports = []v1.ServicePort{{
Name: svcPortName.Port, Name: svcPortName.Port,
Port: int32(svcPort), Port: int32(svcPort),
Protocol: tcpProtocol, Protocol: v1.ProtocolTCP,
NodePort: int32(svcNodePort), NodePort: int32(svcNodePort),
}} }}
}), }),
@ -287,9 +284,9 @@ func TestCreateRemoteEndpointL2Bridge(t *testing.T) {
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(svcPortName.Port), Name: ptr.To(svcPortName.Port),
Port: pointer.Int32(int32(svcPort)), Port: ptr.To(int32(svcPort)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
}), }),
) )
@ -316,7 +313,6 @@ func TestCreateRemoteEndpointL2Bridge(t *testing.T) {
} }
func TestSharedRemoteEndpointDelete(t *testing.T) { func TestSharedRemoteEndpointDelete(t *testing.T) {
syncPeriod := 30 * time.Second syncPeriod := 30 * time.Second
tcpProtocol := v1.ProtocolTCP
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", netutils.ParseIPSloppy("10.0.0.1"), "L2Bridge") proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", netutils.ParseIPSloppy("10.0.0.1"), "L2Bridge")
if proxier == nil { if proxier == nil {
t.Error() t.Error()
@ -369,9 +365,9 @@ func TestSharedRemoteEndpointDelete(t *testing.T) {
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(svcPortName1.Port), Name: ptr.To(svcPortName1.Port),
Port: pointer.Int32(int32(svcPort1)), Port: ptr.To(int32(svcPort1)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
}), }),
makeTestEndpointSlice(svcPortName2.Namespace, svcPortName2.Name, 1, func(eps *discovery.EndpointSlice) { makeTestEndpointSlice(svcPortName2.Namespace, svcPortName2.Name, 1, func(eps *discovery.EndpointSlice) {
@ -380,9 +376,9 @@ func TestSharedRemoteEndpointDelete(t *testing.T) {
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(svcPortName2.Port), Name: ptr.To(svcPortName2.Port),
Port: pointer.Int32(int32(svcPort2)), Port: ptr.To(int32(svcPort2)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
}), }),
) )
@ -428,9 +424,9 @@ func TestSharedRemoteEndpointDelete(t *testing.T) {
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(svcPortName2.Port), Name: ptr.To(svcPortName2.Port),
Port: pointer.Int32(int32(svcPort2)), Port: ptr.To(int32(svcPort2)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
}), }),
) )
@ -505,7 +501,6 @@ func TestSharedRemoteEndpointUpdate(t *testing.T) {
}), }),
) )
tcpProtocol := v1.ProtocolTCP
populateEndpointSlices(proxier, populateEndpointSlices(proxier,
makeTestEndpointSlice(svcPortName1.Namespace, svcPortName1.Name, 1, func(eps *discovery.EndpointSlice) { makeTestEndpointSlice(svcPortName1.Namespace, svcPortName1.Name, 1, func(eps *discovery.EndpointSlice) {
eps.AddressType = discovery.AddressTypeIPv4 eps.AddressType = discovery.AddressTypeIPv4
@ -513,9 +508,9 @@ func TestSharedRemoteEndpointUpdate(t *testing.T) {
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(svcPortName1.Port), Name: ptr.To(svcPortName1.Port),
Port: pointer.Int32(int32(svcPort1)), Port: ptr.To(int32(svcPort1)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
}), }),
makeTestEndpointSlice(svcPortName2.Namespace, svcPortName2.Name, 1, func(eps *discovery.EndpointSlice) { makeTestEndpointSlice(svcPortName2.Namespace, svcPortName2.Name, 1, func(eps *discovery.EndpointSlice) {
@ -524,9 +519,9 @@ func TestSharedRemoteEndpointUpdate(t *testing.T) {
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(svcPortName2.Port), Name: ptr.To(svcPortName2.Port),
Port: pointer.Int32(int32(svcPort2)), Port: ptr.To(int32(svcPort2)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
}), }),
) )
@ -583,9 +578,9 @@ func TestSharedRemoteEndpointUpdate(t *testing.T) {
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(svcPortName1.Port), Name: ptr.To(svcPortName1.Port),
Port: pointer.Int32(int32(svcPort1)), Port: ptr.To(int32(svcPort1)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
}), }),
makeTestEndpointSlice(svcPortName1.Namespace, svcPortName1.Name, 1, func(eps *discovery.EndpointSlice) { makeTestEndpointSlice(svcPortName1.Namespace, svcPortName1.Name, 1, func(eps *discovery.EndpointSlice) {
@ -594,14 +589,14 @@ func TestSharedRemoteEndpointUpdate(t *testing.T) {
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(svcPortName1.Port), Name: ptr.To(svcPortName1.Port),
Port: pointer.Int32(int32(svcPort1)), Port: ptr.To(int32(svcPort1)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}, },
{ {
Name: pointer.String("p443"), Name: ptr.To("p443"),
Port: pointer.Int32(int32(443)), Port: ptr.To[int32](443),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
})) }))
@ -634,7 +629,6 @@ func TestSharedRemoteEndpointUpdate(t *testing.T) {
} }
func TestCreateLoadBalancer(t *testing.T) { func TestCreateLoadBalancer(t *testing.T) {
syncPeriod := 30 * time.Second syncPeriod := 30 * time.Second
tcpProtocol := v1.ProtocolTCP
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", netutils.ParseIPSloppy("10.0.0.1"), NETWORK_TYPE_OVERLAY) proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", netutils.ParseIPSloppy("10.0.0.1"), NETWORK_TYPE_OVERLAY)
if proxier == nil { if proxier == nil {
t.Error() t.Error()
@ -668,9 +662,9 @@ func TestCreateLoadBalancer(t *testing.T) {
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(svcPortName.Port), Name: ptr.To(svcPortName.Port),
Port: pointer.Int32(int32(svcPort)), Port: ptr.To(int32(svcPort)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
}), }),
) )
@ -723,18 +717,17 @@ func TestCreateDsrLoadBalancer(t *testing.T) {
}} }}
}), }),
) )
tcpProtocol := v1.ProtocolTCP
populateEndpointSlices(proxier, populateEndpointSlices(proxier,
makeTestEndpointSlice(svcPortName.Namespace, svcPortName.Name, 1, func(eps *discovery.EndpointSlice) { makeTestEndpointSlice(svcPortName.Namespace, svcPortName.Name, 1, func(eps *discovery.EndpointSlice) {
eps.AddressType = discovery.AddressTypeIPv4 eps.AddressType = discovery.AddressTypeIPv4
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
NodeName: pointer.String("testhost"), NodeName: ptr.To("testhost"),
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.String(svcPortName.Port), Name: ptr.To(svcPortName.Port),
Port: pointer.Int32(int32(svcPort)), Port: ptr.To(int32(svcPort)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
}), }),
) )
@ -803,18 +796,17 @@ func TestClusterIPLBInCreateDsrLoadBalancer(t *testing.T) {
}} }}
}), }),
) )
tcpProtocol := v1.ProtocolTCP
populateEndpointSlices(proxier, populateEndpointSlices(proxier,
makeTestEndpointSlice(svcPortName.Namespace, svcPortName.Name, 1, func(eps *discovery.EndpointSlice) { makeTestEndpointSlice(svcPortName.Namespace, svcPortName.Name, 1, func(eps *discovery.EndpointSlice) {
eps.AddressType = discovery.AddressTypeIPv4 eps.AddressType = discovery.AddressTypeIPv4
eps.Endpoints = []discovery.Endpoint{{ eps.Endpoints = []discovery.Endpoint{{
Addresses: []string{epIpAddressRemote}, Addresses: []string{epIpAddressRemote},
NodeName: pointer.StringPtr("testhost2"), // This will make this endpoint as a remote endpoint NodeName: ptr.To("testhost2"), // This will make this endpoint as a remote endpoint
}} }}
eps.Ports = []discovery.EndpointPort{{ eps.Ports = []discovery.EndpointPort{{
Name: pointer.StringPtr(svcPortName.Port), Name: ptr.To(svcPortName.Port),
Port: pointer.Int32(int32(svcPort)), Port: ptr.To(int32(svcPort)),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}} }}
}), }),
) )
@ -877,7 +869,6 @@ func TestEndpointSlice(t *testing.T) {
}) })
// Add initial endpoint slice // Add initial endpoint slice
tcpProtocol := v1.ProtocolTCP
endpointSlice := &discovery.EndpointSlice{ endpointSlice := &discovery.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-1", svcPortName.Name), Name: fmt.Sprintf("%s-1", svcPortName.Name),
@ -886,14 +877,14 @@ func TestEndpointSlice(t *testing.T) {
}, },
Ports: []discovery.EndpointPort{{ Ports: []discovery.EndpointPort{{
Name: &svcPortName.Port, Name: &svcPortName.Port,
Port: pointer.Int32(80), Port: ptr.To[int32](80),
Protocol: &tcpProtocol, Protocol: ptr.To(v1.ProtocolTCP),
}}, }},
AddressType: discovery.AddressTypeIPv4, AddressType: discovery.AddressTypeIPv4,
Endpoints: []discovery.Endpoint{{ Endpoints: []discovery.Endpoint{{
Addresses: []string{"192.168.2.3"}, Addresses: []string{"192.168.2.3"},
Conditions: discovery.EndpointConditions{Ready: pointer.Bool(true)}, Conditions: discovery.EndpointConditions{Ready: ptr.To(true)},
NodeName: pointer.String("testhost2"), NodeName: ptr.To("testhost2"),
}}, }},
} }