From 17a56f3991e4819d2f6cf321222fb8847efa2d69 Mon Sep 17 00:00:00 2001 From: Kevin Gibbs Date: Mon, 20 Jun 2022 23:43:11 +0000 Subject: [PATCH] Add the agent capability for ServiceConnect --- agent/app/agent.go | 3 + agent/app/agent_capability.go | 23 ++ agent/app/agent_capability_test.go | 378 +++++++++++++++------ agent/app/agent_capability_unix_test.go | 163 +++++---- agent/app/agent_capability_windows_test.go | 27 +- agent/app/agent_test.go | 149 +++++--- agent/app/agent_unix_test.go | 18 +- agent/engine/docker_task_engine.go | 15 +- 8 files changed, 539 insertions(+), 237 deletions(-) diff --git a/agent/app/agent.go b/agent/app/agent.go index ba3f65f694a..eba4d37e2b0 100644 --- a/agent/app/agent.go +++ b/agent/app/agent.go @@ -52,6 +52,7 @@ import ( "github.com/aws/amazon-ecs-agent/agent/eventhandler" "github.com/aws/amazon-ecs-agent/agent/eventstream" "github.com/aws/amazon-ecs-agent/agent/handlers" + "github.com/aws/amazon-ecs-agent/agent/serviceconnect" "github.com/aws/amazon-ecs-agent/agent/sighandlers" "github.com/aws/amazon-ecs-agent/agent/sighandlers/exitcodes" "github.com/aws/amazon-ecs-agent/agent/statemanager" @@ -134,6 +135,7 @@ type ecsAgent struct { stateManagerFactory factory.StateManager saveableOptionFactory factory.SaveableOption pauseLoader pause.Loader + serviceconnectLoader serviceconnect.Loader eniWatcher *watcher.ENIWatcher cniClient ecscni.CNIClient vpc string @@ -229,6 +231,7 @@ func newAgent(blackholeEC2Metadata bool, acceptInsecureCert *bool) (agent, error stateManagerFactory: factory.NewStateManager(), saveableOptionFactory: factory.NewSaveableOption(), pauseLoader: pause.New(), + serviceconnectLoader: serviceconnect.New(), cniClient: ecscni.NewClient(cfg.CNIPluginsPath), metadataManager: metadataManager, terminationHandler: sighandlers.StartDefaultTerminationHandler, diff --git a/agent/app/agent_capability.go b/agent/app/agent_capability.go index 5febc49fc2a..cb8fe180316 100644 --- a/agent/app/agent_capability.go +++ b/agent/app/agent_capability.go @@ -23,6 +23,8 @@ import ( "github.com/aws/amazon-ecs-agent/agent/config" "github.com/aws/amazon-ecs-agent/agent/dockerclient" "github.com/aws/amazon-ecs-agent/agent/ecs_client/model/ecs" + "github.com/aws/amazon-ecs-agent/agent/logger" + "github.com/aws/amazon-ecs-agent/agent/logger/field" "github.com/aws/aws-sdk-go/aws" "github.com/cihub/seelog" "github.com/pkg/errors" @@ -73,6 +75,7 @@ const ( capabilityExecConfigRelativePath = "config" capabilityExecCertsRelativePath = "certs" capabilityExternal = "external" + capabilityServiceConnect = "service-connect-v1" ) var ( @@ -114,6 +117,7 @@ var ( attributePrefix + appMeshAttributeSuffix, attributePrefix + taskEIAAttributeSuffix, attributePrefix + taskEIAWithOptimizedCPU, + attributePrefix + capabilityServiceConnect, } // List of capabilities that are only supported on external capaciity. Currently only one but keep as a list // for future proof and also align with externalUnsupportedCapabilities. @@ -176,6 +180,7 @@ var ( // ecs.capability.fsxWindowsFileServer // ecs.capability.execute-command // ecs.capability.external +// ecs.capability.service-connect-v1 func (agent *ecsAgent) capabilities() ([]*ecs.Attribute, error) { var capabilities []*ecs.Attribute @@ -271,6 +276,8 @@ func (agent *ecsAgent) capabilities() ([]*ecs.Attribute, error) { if err != nil { return nil, err } + // add service-connect capabilities if applicable + capabilities = agent.appendServiceConnectCapabilities(capabilities) if agent.cfg.External.Enabled() { // Add external specific capability; remove external unsupported capabilities. @@ -438,6 +445,22 @@ func (agent *ecsAgent) appendExecCapabilities(capabilities []*ecs.Attribute) ([] return appendNameOnlyAttribute(capabilities, attributePrefix+capabilityExec), nil } +func (agent *ecsAgent) appendServiceConnectCapabilities(capabilities []*ecs.Attribute) []*ecs.Attribute { + if loaded, _ := agent.serviceconnectLoader.IsLoaded(agent.dockerClient); !loaded { + _, err := agent.serviceconnectLoader.LoadImage(agent.ctx, agent.dockerClient) + if err != nil { + logger.Error("ServiceConnect Capability: Failed to load appnet Agent container. This container instance will not be able to support ServiceConnect tasks", + logger.Fields{ + field.Error: err, + }, + ) + return capabilities + } + } + + return appendNameOnlyAttribute(capabilities, attributePrefix+capabilityServiceConnect) +} + func defaultGetSubDirectories(path string) ([]string, error) { var subDirectories []string diff --git a/agent/app/agent_capability_test.go b/agent/app/agent_capability_test.go index 4048496598c..002a39699eb 100644 --- a/agent/app/agent_capability_test.go +++ b/agent/app/agent_capability_test.go @@ -32,6 +32,7 @@ import ( "github.com/aws/amazon-ecs-agent/agent/ecs_client/model/ecs" mock_ecscni "github.com/aws/amazon-ecs-agent/agent/ecscni/mocks" mock_pause "github.com/aws/amazon-ecs-agent/agent/eni/pause/mocks" + mock_serviceconnect "github.com/aws/amazon-ecs-agent/agent/serviceconnect/mocks" mock_mobypkgwrapper "github.com/aws/amazon-ecs-agent/agent/utils/mobypkgwrapper/mocks" "github.com/aws/aws-sdk-go/aws" @@ -90,6 +91,10 @@ func TestCapabilities(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + // Scan() and ListPluginsWithFilters() are tested with // AnyTimes() because they are not called in windows. gomock.InOrder( @@ -132,6 +137,7 @@ func TestCapabilities(t *testing.T) { attributePrefix + capabilityEnvFilesS3, attributePrefix + taskENIBlockInstanceMetadataAttributeSuffix, attributePrefix + capabilityExec, + attributePrefix + capabilityServiceConnect, } var expectedCapabilities []*ecs.Attribute @@ -151,13 +157,14 @@ func TestCapabilities(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - cniClient: cniClient, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + cniClient: cniClient, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -225,6 +232,9 @@ func getCapabilitiesWithConfig(cfg *config.Config, t *testing.T) []*ecs.Attribut mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() // CNI plugins are platform dependent. Therefore return version for any plugin query. mockCNIClient.EXPECT().Version(gomock.Any()).Return("v1", nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -244,13 +254,14 @@ func getCapabilitiesWithConfig(cfg *config.Config, t *testing.T) []*ecs.Attribut // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: cfg, - dockerClient: client, - pauseLoader: mockPauseLoader, - cniClient: mockCNIClient, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: cfg, + dockerClient: client, + pauseLoader: mockPauseLoader, + cniClient: mockCNIClient, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() require.NoError(t, err) @@ -275,15 +286,19 @@ func TestCapabilitiesECR(t *testing.T) { mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + ctx, cancel := context.WithCancel(context.TODO()) // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - pauseLoader: mockPauseLoader, - dockerClient: client, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + pauseLoader: mockPauseLoader, + dockerClient: client, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -321,15 +336,19 @@ func TestCapabilitiesTaskIAMRoleForSupportedDockerVersion(t *testing.T) { mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + ctx, cancel := context.WithCancel(context.TODO()) // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -364,15 +383,19 @@ func TestCapabilitiesTaskIAMRoleForUnSupportedDockerVersion(t *testing.T) { mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + ctx, cancel := context.WithCancel(context.TODO()) // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() @@ -408,15 +431,19 @@ func TestCapabilitiesTaskIAMRoleNetworkHostForSupportedDockerVersion(t *testing. mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + ctx, cancel := context.WithCancel(context.TODO()) // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() @@ -452,15 +479,19 @@ func TestCapabilitiesTaskIAMRoleNetworkHostForUnSupportedDockerVersion(t *testin mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + ctx, cancel := context.WithCancel(context.TODO()) // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() @@ -493,6 +524,9 @@ func TestAWSVPCBlockInstanceMetadataWhenTaskENIIsDisabled(t *testing.T) { mockMobyPlugins := mock_mobypkgwrapper.NewMockPlugins(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -525,13 +559,14 @@ func TestAWSVPCBlockInstanceMetadataWhenTaskENIIsDisabled(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - cniClient: cniClient, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + cniClient: cniClient, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -576,16 +611,19 @@ func TestCapabilitiesExecutionRoleAWSLogs(t *testing.T) { mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() ctx, cancel := context.WithCancel(context.TODO()) // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - cniClient: cniClient, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + cniClient: cniClient, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() @@ -610,6 +648,8 @@ func TestCapabilitiesTaskResourceLimit(t *testing.T) { mockMobyPlugins := mock_mobypkgwrapper.NewMockPlugins(ctrl) mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return(versionList), client.EXPECT().KnownVersions().Return(versionList), @@ -621,11 +661,12 @@ func TestCapabilitiesTaskResourceLimit(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } expectedCapability := attributePrefix + capabilityTaskCPUMemLimit @@ -653,6 +694,8 @@ func TestCapabilitesTaskResourceLimitDisabledByMissingDockerVersion(t *testing.T mockMobyPlugins := mock_mobypkgwrapper.NewMockPlugins(ctrl) mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return(versionList), client.EXPECT().KnownVersions().Return(versionList), @@ -664,11 +707,12 @@ func TestCapabilitesTaskResourceLimitDisabledByMissingDockerVersion(t *testing.T // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } unexpectedCapability := attributePrefix + capabilityTaskCPUMemLimit @@ -695,6 +739,8 @@ func TestCapabilitesTaskResourceLimitErrorCase(t *testing.T) { versionList := []dockerclient.DockerVersion{dockerclient.Version_1_19} mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return(versionList), client.EXPECT().KnownVersions().Return(versionList), @@ -703,10 +749,11 @@ func TestCapabilitesTaskResourceLimitErrorCase(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - pauseLoader: mockPauseLoader, - dockerClient: client, + ctx: ctx, + cfg: conf, + pauseLoader: mockPauseLoader, + dockerClient: client, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() @@ -754,6 +801,8 @@ func TestCapabilitiesIncreasedTaskCPULimit(t *testing.T) { mockMobyPlugins := mock_mobypkgwrapper.NewMockPlugins(ctrl) mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return(versionList), client.EXPECT().KnownVersions().Return(versionList), @@ -765,11 +814,12 @@ func TestCapabilitiesIncreasedTaskCPULimit(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capability := attributePrefix + capabilityIncreasedTaskCPULimit @@ -804,16 +854,19 @@ func TestCapabilitiesContainerHealth(t *testing.T) { mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() ctx, cancel := context.WithCancel(context.TODO()) // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: &config.Config{}, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &config.Config{}, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() @@ -845,16 +898,19 @@ func TestCapabilitiesContainerHealthDisabled(t *testing.T) { mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() ctx, cancel := context.WithCancel(context.TODO()) // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: &config.Config{DisableDockerHealthCheck: config.BooleanDefaultFalse{Value: config.ExplicitlyEnabled}}, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &config.Config{DisableDockerHealthCheck: config.BooleanDefaultFalse{Value: config.ExplicitlyEnabled}}, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() @@ -877,6 +933,8 @@ func TestCapabilitesListPluginsErrorCase(t *testing.T) { versionList := []dockerclient.DockerVersion{dockerclient.Version_1_19} mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return(versionList), client.EXPECT().KnownVersions().Return(versionList), @@ -888,11 +946,12 @@ func TestCapabilitesListPluginsErrorCase(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: &config.Config{}, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &config.Config{}, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() @@ -914,6 +973,8 @@ func TestCapabilitesScanPluginsErrorCase(t *testing.T) { versionList := []dockerclient.DockerVersion{dockerclient.Version_1_19} mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return(versionList), client.EXPECT().KnownVersions().Return(versionList), @@ -925,11 +986,12 @@ func TestCapabilitesScanPluginsErrorCase(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: &config.Config{}, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &config.Config{}, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() @@ -1021,6 +1083,8 @@ func TestCapabilitiesExecuteCommand(t *testing.T) { versionList := []dockerclient.DockerVersion{dockerclient.Version_1_19} mockPauseLoader := mock_pause.NewMockLoader(ctrl) mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return(versionList), client.EXPECT().KnownVersions().Return(versionList), @@ -1032,11 +1096,12 @@ func TestCapabilitiesExecuteCommand(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: &config.Config{}, - dockerClient: client, - pauseLoader: mockPauseLoader, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &config.Config{}, + dockerClient: client, + pauseLoader: mockPauseLoader, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() @@ -1053,6 +1118,127 @@ func TestCapabilitiesExecuteCommand(t *testing.T) { } } +func TestCapabilitiesNoServiceConnect(t *testing.T) { + mockPathExists(true) + defer mockPathExists(false) + getSubDirectories = func(path string) ([]string, error) { + // appendExecCapabilities() requires at least 1 version to exist + return []string{"3.0.236.0"}, nil + } + defer func() { + getSubDirectories = defaultGetSubDirectories + }() + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + client := mock_dockerapi.NewMockDockerClient(ctrl) + cniClient := mock_ecscni.NewMockCNIClient(ctrl) + mockCredentialsProvider := app_mocks.NewMockProvider(ctrl) + mockMobyPlugins := mock_mobypkgwrapper.NewMockPlugins(ctrl) + mockPauseLoader := mock_pause.NewMockLoader(ctrl) + conf := &config.Config{ + AvailableLoggingDrivers: []dockerclient.LoggingDriver{ + dockerclient.JSONFileDriver, + dockerclient.SyslogDriver, + dockerclient.JournaldDriver, + dockerclient.GelfDriver, + dockerclient.FluentdDriver, + }, + PrivilegedDisabled: config.BooleanDefaultFalse{Value: config.ExplicitlyDisabled}, + SELinuxCapable: config.BooleanDefaultFalse{Value: config.ExplicitlyEnabled}, + AppArmorCapable: config.BooleanDefaultFalse{Value: config.ExplicitlyEnabled}, + TaskENIEnabled: config.BooleanDefaultFalse{Value: config.ExplicitlyEnabled}, + AWSVPCBlockInstanceMetdata: config.BooleanDefaultFalse{Value: config.ExplicitlyEnabled}, + TaskCleanupWaitDuration: config.DefaultConfig().TaskCleanupWaitDuration, + } + + mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() + mockServiceConnectLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any()).Return(nil, errors.New("No File")).AnyTimes() + + // Scan() and ListPluginsWithFilters() are tested with + // AnyTimes() because they are not called in windows. + gomock.InOrder( + client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ + dockerclient.Version_1_17, + dockerclient.Version_1_18, + }), + client.EXPECT().KnownVersions().Return([]dockerclient.DockerVersion{ + dockerclient.Version_1_17, + dockerclient.Version_1_18, + dockerclient.Version_1_19, + }), + // CNI plugins are platform dependent. + // Therefore, for any version query for any plugin return an appropriate version + cniClient.EXPECT().Version(gomock.Any()).Return("v1", nil), + mockMobyPlugins.EXPECT().Scan().AnyTimes().Return([]string{}, nil), + client.EXPECT().ListPluginsWithFilters(gomock.Any(), gomock.Any(), gomock.Any(), + gomock.Any()).AnyTimes().Return([]string{}, nil), + ) + + expectedNameOnlyCapabilities := []string{ + capabilityPrefix + "privileged-container", + capabilityPrefix + "docker-remote-api.1.17", + capabilityPrefix + "docker-remote-api.1.18", + capabilityPrefix + "logging-driver.json-file", + capabilityPrefix + "logging-driver.syslog", + capabilityPrefix + "logging-driver.journald", + capabilityPrefix + "selinux", + capabilityPrefix + "apparmor", + attributePrefix + "docker-plugin.local", + attributePrefix + taskENIAttributeSuffix, + attributePrefix + capabilityPrivateRegistryAuthASM, + attributePrefix + capabilitySecretEnvSSM, + attributePrefix + capabilitySecretLogDriverSSM, + attributePrefix + capabilityECREndpoint, + attributePrefix + capabilitySecretEnvASM, + attributePrefix + capabilitySecretLogDriverASM, + attributePrefix + capabilityContainerOrdering, + attributePrefix + capabilityFullTaskSync, + attributePrefix + capabilityEnvFilesS3, + attributePrefix + taskENIBlockInstanceMetadataAttributeSuffix, + attributePrefix + capabilityExec, + } + + var expectedCapabilities []*ecs.Attribute + for _, name := range expectedNameOnlyCapabilities { + expectedCapabilities = append(expectedCapabilities, + &ecs.Attribute{Name: aws.String(name)}) + } + expectedCapabilities = append(expectedCapabilities, + []*ecs.Attribute{ + { + Name: aws.String(attributePrefix + cniPluginVersionSuffix), + Value: aws.String("v1"), + }, + }...) + + ctx, cancel := context.WithCancel(context.TODO()) + // Cancel the context to cancel async routines + defer cancel() + agent := &ecsAgent{ + ctx: ctx, + cfg: conf, + dockerClient: client, + cniClient: cniClient, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, + } + capabilities, err := agent.capabilities() + assert.NoError(t, err) + + for _, expected := range expectedCapabilities { + assert.Contains(t, capabilities, &ecs.Attribute{ + Name: expected.Name, + Value: expected.Value, + }) + } +} + func TestDefaultGetSubDirectories(t *testing.T) { rootDir, err := ioutil.TempDir(os.TempDir(), testTempDirPrefix) if err != nil { diff --git a/agent/app/agent_capability_unix_test.go b/agent/app/agent_capability_unix_test.go index fc476506f68..48844303f8f 100644 --- a/agent/app/agent_capability_unix_test.go +++ b/agent/app/agent_capability_unix_test.go @@ -33,6 +33,7 @@ import ( "github.com/aws/amazon-ecs-agent/agent/ecscni" mock_ecscni "github.com/aws/amazon-ecs-agent/agent/ecscni/mocks" "github.com/aws/amazon-ecs-agent/agent/gpu" + mock_serviceconnect "github.com/aws/amazon-ecs-agent/agent/serviceconnect/mocks" "github.com/aws/amazon-ecs-agent/agent/taskresource" "github.com/aws/amazon-ecs-agent/agent/utils" mock_mobypkgwrapper "github.com/aws/amazon-ecs-agent/agent/utils/mobypkgwrapper/mocks" @@ -72,6 +73,8 @@ func TestVolumeDriverCapabilitiesUnix(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -123,13 +126,14 @@ func TestVolumeDriverCapabilitiesUnix(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - cniClient: cniClient, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + cniClient: cniClient, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -156,6 +160,8 @@ func TestNvidiaDriverCapabilitiesUnix(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -199,6 +205,7 @@ func TestNvidiaDriverCapabilitiesUnix(t *testing.T) { DriverVersion: "396.44", }, }, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -225,6 +232,8 @@ func TestEmptyNvidiaDriverCapabilitiesUnix(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -266,6 +275,7 @@ func TestEmptyNvidiaDriverCapabilitiesUnix(t *testing.T) { DriverVersion: "", }, }, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -294,6 +304,8 @@ func TestENITrunkingCapabilitiesUnix(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -342,13 +354,14 @@ func TestENITrunkingCapabilitiesUnix(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - cniClient: cniClient, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + cniClient: cniClient, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -378,6 +391,8 @@ func TestNoENITrunkingCapabilitiesUnix(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -418,13 +433,14 @@ func TestNoENITrunkingCapabilitiesUnix(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - cniClient: cniClient, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + cniClient: cniClient, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -450,6 +466,8 @@ func TestPIDAndIPCNamespaceSharingCapabilitiesUnix(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -486,12 +504,13 @@ func TestPIDAndIPCNamespaceSharingCapabilitiesUnix(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -517,6 +536,8 @@ func TestPIDAndIPCNamespaceSharingCapabilitiesNoPauseContainer(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, errors.New("mock error")) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -552,12 +573,13 @@ func TestPIDAndIPCNamespaceSharingCapabilitiesNoPauseContainer(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -583,6 +605,8 @@ func TestAppMeshCapabilitiesUnix(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -621,12 +645,13 @@ func TestAppMeshCapabilitiesUnix(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -657,6 +682,8 @@ func TestTaskEIACapabilitiesNoOptimizedCPU(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -673,12 +700,13 @@ func TestTaskEIACapabilitiesNoOptimizedCPU(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -705,6 +733,8 @@ func TestTaskEIACapabilitiesWithOptimizedCPU(t *testing.T) { defer resetOpenFile() mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -721,12 +751,13 @@ func TestTaskEIACapabilitiesWithOptimizedCPU(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -750,6 +781,8 @@ func TestCapabilitiesUnix(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -793,12 +826,13 @@ func TestCapabilitiesUnix(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -823,6 +857,8 @@ func TestFirelensConfigCapabilitiesUnix(t *testing.T) { } mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil) + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( client.EXPECT().SupportedVersions().Return([]dockerclient.DockerVersion{ dockerclient.Version_1_17, @@ -839,12 +875,13 @@ func TestFirelensConfigCapabilitiesUnix(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } capabilities, err := agent.capabilities() assert.NoError(t, err) diff --git a/agent/app/agent_capability_windows_test.go b/agent/app/agent_capability_windows_test.go index c5568537c95..60212448fcd 100644 --- a/agent/app/agent_capability_windows_test.go +++ b/agent/app/agent_capability_windows_test.go @@ -27,6 +27,7 @@ import ( "github.com/aws/amazon-ecs-agent/agent/ecs_client/model/ecs" "github.com/aws/amazon-ecs-agent/agent/ecscni" mock_ecscni "github.com/aws/amazon-ecs-agent/agent/ecscni/mocks" + "github.com/aws/amazon-ecs-agent/agent/serviceconnect" mock_mobypkgwrapper "github.com/aws/amazon-ecs-agent/agent/utils/mobypkgwrapper/mocks" "github.com/aws/aws-sdk-go/aws" @@ -107,12 +108,13 @@ func TestVolumeDriverCapabilitiesWindows(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - cniClient: cniClient, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + cniClient: cniClient, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: serviceconnect.New(), } capabilities, err := agent.capabilities() assert.NoError(t, err) @@ -203,12 +205,13 @@ func TestSupportedCapabilitiesWindows(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: conf, - dockerClient: client, - cniClient: cniClient, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: conf, + dockerClient: client, + cniClient: cniClient, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: serviceconnect.New(), } capabilities, err := agent.capabilities() assert.NoError(t, err) diff --git a/agent/app/agent_test.go b/agent/app/agent_test.go index 8b488c3c18d..7ed9c2a815e 100644 --- a/agent/app/agent_test.go +++ b/agent/app/agent_test.go @@ -47,6 +47,7 @@ import ( mock_engine "github.com/aws/amazon-ecs-agent/agent/engine/mocks" mock_pause "github.com/aws/amazon-ecs-agent/agent/eni/pause/mocks" "github.com/aws/amazon-ecs-agent/agent/eventstream" + mock_serviceconnect "github.com/aws/amazon-ecs-agent/agent/serviceconnect/mocks" "github.com/aws/amazon-ecs-agent/agent/sighandlers/exitcodes" "github.com/aws/amazon-ecs-agent/agent/statemanager" mock_statemanager "github.com/aws/amazon-ecs-agent/agent/statemanager/mocks" @@ -214,6 +215,8 @@ func TestDoStartRegisterContainerInstanceErrorTerminal(t *testing.T) { mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( dockerClient.EXPECT().SupportedVersions().Return(apiVersions), mockCredentialsProvider.EXPECT().Retrieve().Return(aws_credentials.Value{}, nil), @@ -243,6 +246,7 @@ func TestDoStartRegisterContainerInstanceErrorTerminal(t *testing.T) { ec2MetadataClient: mockEC2Metadata, terminationHandler: func(taskEngineState dockerstate.TaskEngineState, dataClient data.Client, taskEngine engine.TaskEngine, cancel context.CancelFunc) { }, + serviceconnectLoader: mockServiceConnectLoader, } exitCode := agent.doStart(eventstream.NewEventStream("events", ctx), @@ -261,6 +265,8 @@ func TestDoStartRegisterContainerInstanceErrorNonTerminal(t *testing.T) { mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( dockerClient.EXPECT().SupportedVersions().Return(apiVersions), mockCredentialsProvider.EXPECT().Retrieve().Return(aws_credentials.Value{}, nil), @@ -289,6 +295,7 @@ func TestDoStartRegisterContainerInstanceErrorNonTerminal(t *testing.T) { ec2MetadataClient: mockEC2Metadata, terminationHandler: func(taskEngineState dockerstate.TaskEngineState, dataClient data.Client, taskEngine engine.TaskEngine, cancel context.CancelFunc) { }, + serviceconnectLoader: mockServiceConnectLoader, } exitCode := agent.doStart(eventstream.NewEventStream("events", ctx), @@ -386,6 +393,8 @@ func testDoStartHappyPathWithConditions(t *testing.T, blackholed bool, warmPools mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() imageManager.EXPECT().StartImageCleanupProcess(gomock.Any()).MaxTimes(1) dockerClient.EXPECT().ListContainers(gomock.Any(), gomock.Any(), gomock.Any()).Return( dockerapi.ListContainersResponse{}).AnyTimes() @@ -446,6 +455,7 @@ func testDoStartHappyPathWithConditions(t *testing.T, blackholed bool, warmPools stateManagerFactory: stateManagerFactory, ec2MetadataClient: ec2MetadataClient, saveableOptionFactory: saveableOptionFactory, + serviceconnectLoader: mockServiceConnectLoader, } var agentW sync.WaitGroup @@ -877,6 +887,8 @@ func TestReregisterContainerInstanceHappyPath(t *testing.T) { mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( mockCredentialsProvider.EXPECT().Retrieve().Return(aws_credentials.Value{}, nil), mockDockerClient.EXPECT().SupportedVersions().Return(nil), @@ -896,13 +908,14 @@ func TestReregisterContainerInstanceHappyPath(t *testing.T) { mockEC2Metadata.EXPECT().OutpostARN().Return("", nil) agent := &ecsAgent{ - ctx: ctx, - cfg: &cfg, - dockerClient: mockDockerClient, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, - ec2MetadataClient: mockEC2Metadata, + ctx: ctx, + cfg: &cfg, + dockerClient: mockDockerClient, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + ec2MetadataClient: mockEC2Metadata, + serviceconnectLoader: mockServiceConnectLoader, } agent.containerInstanceARN = containerInstanceARN agent.availabilityZone = availabilityZone @@ -924,6 +937,8 @@ func TestReregisterContainerInstanceInstanceTypeChanged(t *testing.T) { mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( mockCredentialsProvider.EXPECT().Retrieve().Return(aws_credentials.Value{}, nil), mockDockerClient.EXPECT().SupportedVersions().Return(nil), @@ -944,13 +959,14 @@ func TestReregisterContainerInstanceInstanceTypeChanged(t *testing.T) { mockEC2Metadata.EXPECT().OutpostARN().Return("", nil) agent := &ecsAgent{ - ctx: ctx, - cfg: &cfg, - dockerClient: mockDockerClient, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - ec2MetadataClient: mockEC2Metadata, - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &cfg, + dockerClient: mockDockerClient, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + ec2MetadataClient: mockEC2Metadata, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } agent.containerInstanceARN = containerInstanceARN agent.availabilityZone = availabilityZone @@ -973,6 +989,8 @@ func TestReregisterContainerInstanceAttributeError(t *testing.T) { mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( mockCredentialsProvider.EXPECT().Retrieve().Return(aws_credentials.Value{}, nil), @@ -992,13 +1010,14 @@ func TestReregisterContainerInstanceAttributeError(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: &cfg, - ec2MetadataClient: mockEC2Metadata, - dockerClient: mockDockerClient, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &cfg, + ec2MetadataClient: mockEC2Metadata, + dockerClient: mockDockerClient, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } agent.containerInstanceARN = containerInstanceARN agent.availabilityZone = availabilityZone @@ -1021,6 +1040,8 @@ func TestReregisterContainerInstanceNonTerminalError(t *testing.T) { mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( mockCredentialsProvider.EXPECT().Retrieve().Return(aws_credentials.Value{}, nil), mockDockerClient.EXPECT().SupportedVersions().Return(nil), @@ -1039,13 +1060,14 @@ func TestReregisterContainerInstanceNonTerminalError(t *testing.T) { // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: &cfg, - dockerClient: mockDockerClient, - ec2MetadataClient: mockEC2Metadata, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &cfg, + dockerClient: mockDockerClient, + ec2MetadataClient: mockEC2Metadata, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } agent.containerInstanceARN = containerInstanceARN agent.availabilityZone = availabilityZone @@ -1069,6 +1091,8 @@ func TestRegisterContainerInstanceWhenContainerInstanceARNIsNotSetHappyPath(t *t mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( mockCredentialsProvider.EXPECT().Retrieve().Return(aws_credentials.Value{}, nil), mockDockerClient.EXPECT().SupportedVersions().Return(nil), @@ -1087,13 +1111,14 @@ func TestRegisterContainerInstanceWhenContainerInstanceARNIsNotSetHappyPath(t *t // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: &cfg, - dockerClient: mockDockerClient, - ec2MetadataClient: mockEC2Metadata, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &cfg, + dockerClient: mockDockerClient, + ec2MetadataClient: mockEC2Metadata, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } err := agent.registerContainerInstance(client, nil) assert.NoError(t, err) @@ -1114,6 +1139,8 @@ func TestRegisterContainerInstanceWhenContainerInstanceARNIsNotSetCanRetryError( mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() retriableError := apierrors.NewRetriableError(apierrors.NewRetriable(true), errors.New("error")) gomock.InOrder( mockCredentialsProvider.EXPECT().Retrieve().Return(aws_credentials.Value{}, nil), @@ -1133,13 +1160,14 @@ func TestRegisterContainerInstanceWhenContainerInstanceARNIsNotSetCanRetryError( // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: &cfg, - dockerClient: mockDockerClient, - ec2MetadataClient: mockEC2Metadata, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &cfg, + dockerClient: mockDockerClient, + ec2MetadataClient: mockEC2Metadata, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } err := agent.registerContainerInstance(client, nil) @@ -1160,6 +1188,8 @@ func TestRegisterContainerInstanceWhenContainerInstanceARNIsNotSetCannotRetryErr mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() cannotRetryError := apierrors.NewRetriableError(apierrors.NewRetriable(false), errors.New("error")) gomock.InOrder( mockCredentialsProvider.EXPECT().Retrieve().Return(aws_credentials.Value{}, nil), @@ -1179,13 +1209,14 @@ func TestRegisterContainerInstanceWhenContainerInstanceARNIsNotSetCannotRetryErr // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: &cfg, - ec2MetadataClient: mockEC2Metadata, - dockerClient: mockDockerClient, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &cfg, + ec2MetadataClient: mockEC2Metadata, + dockerClient: mockDockerClient, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } err := agent.registerContainerInstance(client, nil) @@ -1206,6 +1237,8 @@ func TestRegisterContainerInstanceWhenContainerInstanceARNIsNotSetAttributeError mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( mockCredentialsProvider.EXPECT().Retrieve().Return(aws_credentials.Value{}, nil), mockDockerClient.EXPECT().SupportedVersions().Return(nil), @@ -1224,13 +1257,14 @@ func TestRegisterContainerInstanceWhenContainerInstanceARNIsNotSetAttributeError // Cancel the context to cancel async routines defer cancel() agent := &ecsAgent{ - ctx: ctx, - cfg: &cfg, - ec2MetadataClient: mockEC2Metadata, - dockerClient: mockDockerClient, - pauseLoader: mockPauseLoader, - credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), - mobyPlugins: mockMobyPlugins, + ctx: ctx, + cfg: &cfg, + ec2MetadataClient: mockEC2Metadata, + dockerClient: mockDockerClient, + pauseLoader: mockPauseLoader, + credentialProvider: aws_credentials.NewCredentials(mockCredentialsProvider), + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } err := agent.registerContainerInstance(client, nil) @@ -1250,6 +1284,8 @@ func TestRegisterContainerInstanceInvalidParameterTerminalError(t *testing.T) { mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(false, nil).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( dockerClient.EXPECT().SupportedVersions().Return(apiVersions), mockCredentialsProvider.EXPECT().Retrieve().Return(aws_credentials.Value{}, nil), @@ -1277,6 +1313,7 @@ func TestRegisterContainerInstanceInvalidParameterTerminalError(t *testing.T) { mobyPlugins: mockMobyPlugins, terminationHandler: func(taskEngineState dockerstate.TaskEngineState, dataClient data.Client, taskEngine engine.TaskEngine, cancel context.CancelFunc) { }, + serviceconnectLoader: mockServiceConnectLoader, } exitCode := agent.doStart(eventstream.NewEventStream("events", ctx), diff --git a/agent/app/agent_unix_test.go b/agent/app/agent_unix_test.go index e67d49f321d..c5b4a5855b1 100644 --- a/agent/app/agent_unix_test.go +++ b/agent/app/agent_unix_test.go @@ -40,6 +40,7 @@ import ( "github.com/aws/amazon-ecs-agent/agent/eni/watcher" "github.com/aws/amazon-ecs-agent/agent/eventstream" mock_gpu "github.com/aws/amazon-ecs-agent/agent/gpu/mocks" + mock_serviceconnect "github.com/aws/amazon-ecs-agent/agent/serviceconnect/mocks" "github.com/aws/amazon-ecs-agent/agent/sighandlers/exitcodes" "github.com/aws/amazon-ecs-agent/agent/taskresource" "github.com/aws/amazon-ecs-agent/agent/taskresource/cgroup/control/mock_control" @@ -106,6 +107,8 @@ func TestDoStartTaskENIHappyPath(t *testing.T) { mockMetadata.EXPECT().OutpostARN().Return("", nil) mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() mockUdevMonitor.EXPECT().Monitor(gomock.Any()).Return(monitoShutdownEvents).AnyTimes() gomock.InOrder( @@ -165,7 +168,8 @@ func TestDoStartTaskENIHappyPath(t *testing.T) { ec2MetadataClient: mockMetadata, terminationHandler: func(state dockerstate.TaskEngineState, dataClient data.Client, taskEngine engine.TaskEngine, cancel context.CancelFunc) { }, - mobyPlugins: mockMobyPlugins, + mobyPlugins: mockMobyPlugins, + serviceconnectLoader: mockServiceConnectLoader, } getPid = func() int { @@ -439,6 +443,8 @@ func TestDoStartCgroupInitHappyPath(t *testing.T) { ec2MetadataClient.EXPECT().OutpostARN().Return("", nil) mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( mockControl.EXPECT().Init().Return(nil), @@ -486,6 +492,7 @@ func TestDoStartCgroupInitHappyPath(t *testing.T) { resourceFields: &taskresource.ResourceFields{ Control: mockControl, }, + serviceconnectLoader: mockServiceConnectLoader, } var agentW sync.WaitGroup @@ -522,6 +529,8 @@ func TestDoStartCgroupInitErrorPath(t *testing.T) { mockCredentialsProvider.EXPECT().IsExpired().Return(false).AnyTimes() mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() mockControl.EXPECT().Init().Return(errors.New("test error")) @@ -542,6 +551,7 @@ func TestDoStartCgroupInitErrorPath(t *testing.T) { resourceFields: &taskresource.ResourceFields{ Control: mockControl, }, + serviceconnectLoader: mockServiceConnectLoader, } status := agent.doStart(eventstream.NewEventStream("events", ctx), @@ -585,6 +595,8 @@ func TestDoStartGPUManagerHappyPath(t *testing.T) { ec2MetadataClient.EXPECT().OutpostARN().Return("", nil) mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() gomock.InOrder( mockGPUManager.EXPECT().Initialize().Return(nil), @@ -635,6 +647,7 @@ func TestDoStartGPUManagerHappyPath(t *testing.T) { resourceFields: &taskresource.ResourceFields{ NvidiaGPUManager: mockGPUManager, }, + serviceconnectLoader: mockServiceConnectLoader, } var agentW sync.WaitGroup @@ -672,6 +685,8 @@ func TestDoStartGPUManagerInitError(t *testing.T) { mockGPUManager.EXPECT().Initialize().Return(errors.New("init error")) mockPauseLoader.EXPECT().LoadImage(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() mockPauseLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() + mockServiceConnectLoader := mock_serviceconnect.NewMockLoader(ctrl) + mockServiceConnectLoader.EXPECT().IsLoaded(gomock.Any()).Return(true, nil).AnyTimes() cfg := getTestConfig() cfg.GPUSupportEnabled = true @@ -689,6 +704,7 @@ func TestDoStartGPUManagerInitError(t *testing.T) { resourceFields: &taskresource.ResourceFields{ NvidiaGPUManager: mockGPUManager, }, + serviceconnectLoader: mockServiceConnectLoader, } status := agent.doStart(eventstream.NewEventStream("events", ctx), diff --git a/agent/engine/docker_task_engine.go b/agent/engine/docker_task_engine.go index 26b6b1e939b..ec26519f4e2 100644 --- a/agent/engine/docker_task_engine.go +++ b/agent/engine/docker_task_engine.go @@ -25,16 +25,10 @@ import ( "sync" "time" - "github.com/aws/amazon-ecs-agent/agent/api/appnet" - - serviceconnect "github.com/aws/amazon-ecs-agent/agent/engine/service_connect" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/amazon-ecs-agent/agent/logger" - "github.com/aws/amazon-ecs-agent/agent/logger/field" - "github.com/aws/amazon-ecs-agent/agent/api" + "github.com/aws/amazon-ecs-agent/agent/api/appnet" apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container" apicontainerstatus "github.com/aws/amazon-ecs-agent/agent/api/container/status" apierrors "github.com/aws/amazon-ecs-agent/agent/api/errors" @@ -50,7 +44,10 @@ import ( "github.com/aws/amazon-ecs-agent/agent/engine/dependencygraph" "github.com/aws/amazon-ecs-agent/agent/engine/dockerstate" "github.com/aws/amazon-ecs-agent/agent/engine/execcmd" + engineserviceconnect "github.com/aws/amazon-ecs-agent/agent/engine/service_connect" "github.com/aws/amazon-ecs-agent/agent/eventstream" + "github.com/aws/amazon-ecs-agent/agent/logger" + "github.com/aws/amazon-ecs-agent/agent/logger/field" "github.com/aws/amazon-ecs-agent/agent/metrics" "github.com/aws/amazon-ecs-agent/agent/statechange" "github.com/aws/amazon-ecs-agent/agent/taskresource" @@ -166,7 +163,7 @@ type DockerTaskEngine struct { imageManager ImageManager containerStatusToTransitionFunction map[apicontainerstatus.ContainerStatus]transitionApplyFunc metadataManager containermetadata.Manager - serviceconnectManager serviceconnect.Manager + serviceconnectManager engineserviceconnect.Manager // taskSteadyStatePollInterval is the duration that a managed task waits // once the task gets into steady state before polling the state of all of @@ -221,7 +218,7 @@ func NewDockerTaskEngine(cfg *config.Config, appnetClient: appnet.Client(), metadataManager: metadataManager, - serviceconnectManager: serviceconnect.NewManager(), + serviceconnectManager: engineserviceconnect.NewManager(), taskSteadyStatePollInterval: defaultTaskSteadyStatePollInterval, taskSteadyStatePollIntervalJitter: defaultTaskSteadyStatePollIntervalJitter, resourceFields: resourceFields,