From 886ada2d50e4644ef70ad2157cb8fc4b5e90cead Mon Sep 17 00:00:00 2001 From: Shraddha Bang Date: Wed, 18 Sep 2024 15:56:36 -0700 Subject: [PATCH] Fix the endpoint ports to avoid reconciles --- pkg/backend/endpoint_resolver.go | 4 +- pkg/backend/endpoint_resolver_test.go | 46 +++++++++++----------- pkg/backend/endpoint_types.go | 4 +- pkg/targetgroupbinding/resource_manager.go | 4 +- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/pkg/backend/endpoint_resolver.go b/pkg/backend/endpoint_resolver.go index 5e7fbedf7..254b4ae9f 100644 --- a/pkg/backend/endpoint_resolver.go +++ b/pkg/backend/endpoint_resolver.go @@ -284,7 +284,7 @@ func buildEndpointsDataFromEndpointSliceList(epsList *discovery.EndpointSliceLis func buildPodEndpoint(pod k8s.PodInfo, epAddr string, port int32) PodEndpoint { return PodEndpoint{ IP: epAddr, - Port: awssdk.Int32(port), + Port: port, Pod: pod, } } @@ -292,7 +292,7 @@ func buildPodEndpoint(pod k8s.PodInfo, epAddr string, port int32) PodEndpoint { func buildNodePortEndpoint(node *corev1.Node, instanceID string, nodePort int32) NodePortEndpoint { return NodePortEndpoint{ InstanceID: instanceID, - Port: awssdk.Int32(nodePort), + Port: nodePort, Node: node, } } diff --git a/pkg/backend/endpoint_resolver_test.go b/pkg/backend/endpoint_resolver_test.go index e128f217b..815fbe9c1 100644 --- a/pkg/backend/endpoint_resolver_test.go +++ b/pkg/backend/endpoint_resolver_test.go @@ -768,12 +768,12 @@ func Test_defaultEndpointResolver_ResolvePodEndpoints(t *testing.T) { want: []PodEndpoint{ { IP: "192.168.1.1", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod1, }, { IP: "192.168.1.4", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod4, }, }, @@ -840,12 +840,12 @@ func Test_defaultEndpointResolver_ResolvePodEndpoints(t *testing.T) { want: []PodEndpoint{ { IP: "192.168.1.1", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod1, }, { IP: "192.168.1.4", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod4, }, }, @@ -912,12 +912,12 @@ func Test_defaultEndpointResolver_ResolvePodEndpoints(t *testing.T) { want: []PodEndpoint{ { IP: "192.168.1.1", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod1, }, { IP: "192.168.1.4", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod4, }, }, @@ -974,17 +974,17 @@ func Test_defaultEndpointResolver_ResolvePodEndpoints(t *testing.T) { want: []PodEndpoint{ { IP: "192.168.1.2", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod2, }, { IP: "192.168.1.5", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod5, }, { IP: "192.168.1.8", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod8, }, }, @@ -1102,12 +1102,12 @@ func Test_defaultEndpointResolver_ResolvePodEndpoints(t *testing.T) { want: []PodEndpoint{ { IP: "192.168.1.1", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod1, }, { IP: "192.168.1.4", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod4, }, }, @@ -1169,12 +1169,12 @@ func Test_defaultEndpointResolver_ResolvePodEndpoints(t *testing.T) { want: []PodEndpoint{ { IP: "192.168.1.1", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod1, }, { IP: "192.168.1.4", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod4, }, }, @@ -1236,7 +1236,7 @@ func Test_defaultEndpointResolver_ResolvePodEndpoints(t *testing.T) { want: []PodEndpoint{ { IP: "192.168.1.4", - Port: awssdk.Int32(8080), + Port: 8080, Pod: pod4, }, }, @@ -1539,12 +1539,12 @@ func Test_defaultEndpointResolver_ResolveNodePortEndpoints(t *testing.T) { want: []NodePortEndpoint{ { InstanceID: "i-abcdefg1", - Port: awssdk.Int32(18080), + Port: 18080, Node: node1, }, { InstanceID: "i-abcdefg2", - Port: awssdk.Int32(18080), + Port: 18080, Node: node2, }, }, @@ -1566,12 +1566,12 @@ func Test_defaultEndpointResolver_ResolveNodePortEndpoints(t *testing.T) { want: []NodePortEndpoint{ { InstanceID: "i-abcdefg1", - Port: awssdk.Int32(18080), + Port: 18080, Node: node1, }, { InstanceID: "i-abcdefg2", - Port: awssdk.Int32(18080), + Port: 18080, Node: node2, }, }, @@ -1593,12 +1593,12 @@ func Test_defaultEndpointResolver_ResolveNodePortEndpoints(t *testing.T) { want: []NodePortEndpoint{ { InstanceID: "i-abcdefg3", - Port: awssdk.Int32(18080), + Port: 18080, Node: node3, }, { InstanceID: "i-abcdefg4", - Port: awssdk.Int32(18080), + Port: 18080, Node: node4, }, }, @@ -1633,7 +1633,7 @@ func Test_defaultEndpointResolver_ResolveNodePortEndpoints(t *testing.T) { want: []NodePortEndpoint{ { InstanceID: "i-abcdefg1", - Port: awssdk.Int32(18080), + Port: 18080, Node: node1, }, }, @@ -2609,7 +2609,7 @@ func Test_buildPodEndpoint(t *testing.T) { }, want: PodEndpoint{ IP: "192.168.1.1", - Port: awssdk.Int32(80), + Port: 80, Pod: k8s.PodInfo{ Key: types.NamespacedName{Name: "sample-node"}, }, @@ -2653,7 +2653,7 @@ func Test_buildNodePortEndpoint(t *testing.T) { }, }, InstanceID: "i-xxxxx", - Port: awssdk.Int32(33382), + Port: 33382, }, }, } diff --git a/pkg/backend/endpoint_types.go b/pkg/backend/endpoint_types.go index bacfd4688..648db9cec 100644 --- a/pkg/backend/endpoint_types.go +++ b/pkg/backend/endpoint_types.go @@ -12,7 +12,7 @@ type PodEndpoint struct { // Pod's IP. IP string // Pod's container port. - Port *int32 + Port int32 // Pod that provides this endpoint. Pod k8s.PodInfo } @@ -22,7 +22,7 @@ type NodePortEndpoint struct { // Node's instanceID. InstanceID string // Node's NodePort. - Port *int32 + Port int32 // Node that provides this endpoint. Node *corev1.Node } diff --git a/pkg/targetgroupbinding/resource_manager.go b/pkg/targetgroupbinding/resource_manager.go index 3b261b2ab..d9b263ea2 100644 --- a/pkg/targetgroupbinding/resource_manager.go +++ b/pkg/targetgroupbinding/resource_manager.go @@ -407,7 +407,7 @@ func (m *defaultResourceManager) registerPodEndpoints(ctx context.Context, tgARN for _, endpoint := range endpoints { target := elbv2types.TargetDescription{ Id: awssdk.String(endpoint.IP), - Port: endpoint.Port, + Port: awssdk.Int32(endpoint.Port), } podIP, err := netip.ParseAddr(endpoint.IP) if err != nil { @@ -426,7 +426,7 @@ func (m *defaultResourceManager) registerNodePortEndpoints(ctx context.Context, for _, endpoint := range endpoints { sdkTargets = append(sdkTargets, elbv2types.TargetDescription{ Id: awssdk.String(endpoint.InstanceID), - Port: endpoint.Port, + Port: awssdk.Int32(endpoint.Port), }) } return m.targetsManager.RegisterTargets(ctx, tgARN, sdkTargets)