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