From cc057a9529d84e59858199822b588f51b494b358 Mon Sep 17 00:00:00 2001 From: Penghao He Date: Thu, 11 Jan 2024 13:30:26 -0800 Subject: [PATCH] fix: run local --proxy should work when sc is off (#5604) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License. --- internal/pkg/ecs/ecs.go | 2 +- internal/pkg/ecs/ecs_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/internal/pkg/ecs/ecs.go b/internal/pkg/ecs/ecs.go index 02f3f5a473d..53853dfcc19 100644 --- a/internal/pkg/ecs/ecs.go +++ b/internal/pkg/ecs/ecs.go @@ -143,7 +143,7 @@ func (c Client) ServiceConnectServices(app, env, svc string) ([]*ecs.Service, er if err != nil { return nil, fmt.Errorf("get service: %w", err) } - if len(s.Deployments) == 0 { + if len(s.Deployments) == 0 || s.Deployments[0].ServiceConnectConfiguration == nil { return nil, nil } diff --git a/internal/pkg/ecs/ecs_test.go b/internal/pkg/ecs/ecs_test.go index d6e00dc1aba..f58fdfe9f61 100644 --- a/internal/pkg/ecs/ecs_test.go +++ b/internal/pkg/ecs/ecs_test.go @@ -575,6 +575,42 @@ func TestClient_ServiceConnectServices(t *testing.T) { }, wantedError: fmt.Errorf(`get service: get ECS service mockService: some error`), }, + "return early when no deployments": { + setupMocks: func(m clientMocks) { + m.resourceGetter.EXPECT().GetResourcesByTags(serviceResourceType, getRgInput). + Return([]*resourcegroups.Resource{ + {ARN: mockSvcARN}, + }, nil) + m.resourceGetter.EXPECT().GetResourcesByTags(clusterResourceType, getRgEnvClusterInput). + Return([]*resourcegroups.Resource{ + {ARN: "mockARN1"}, {ARN: "mockARN2"}, + }, nil) + m.ecsClient.EXPECT().ActiveClusters("mockARN1", "mockARN2").Return([]string{"mockARN1"}, nil) + m.ecsClient.EXPECT().ActiveServices("mockARN1", []string{mockSvcARN}).Return([]string{mockSvcARN}, nil) + m.ecsClient.EXPECT().Service(mockCluster, mockService).Return(&ecs.Service{ + Deployments: []*awsecs.Deployment{}, + }, nil) + }, + }, + "return early when service connect is not enabled": { + setupMocks: func(m clientMocks) { + m.resourceGetter.EXPECT().GetResourcesByTags(serviceResourceType, getRgInput). + Return([]*resourcegroups.Resource{ + {ARN: mockSvcARN}, + }, nil) + m.resourceGetter.EXPECT().GetResourcesByTags(clusterResourceType, getRgEnvClusterInput). + Return([]*resourcegroups.Resource{ + {ARN: "mockARN1"}, {ARN: "mockARN2"}, + }, nil) + m.ecsClient.EXPECT().ActiveClusters("mockARN1", "mockARN2").Return([]string{"mockARN1"}, nil) + m.ecsClient.EXPECT().ActiveServices("mockARN1", []string{mockSvcARN}).Return([]string{mockSvcARN}, nil) + m.ecsClient.EXPECT().Service(mockCluster, mockService).Return(&ecs.Service{ + Deployments: []*awsecs.Deployment{ + {}, + }, + }, nil) + }, + }, "error listing namespace": { setupMocks: func(m clientMocks) { m.resourceGetter.EXPECT().GetResourcesByTags(serviceResourceType, getRgInput).