Skip to content

Commit

Permalink
Add the agent capability for ServiceConnect
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-gibbskt committed Jul 6, 2022
1 parent ddabb46 commit 17a56f3
Show file tree
Hide file tree
Showing 8 changed files with 539 additions and 237 deletions.
3 changes: 3 additions & 0 deletions agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions agent/app/agent_capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -73,6 +75,7 @@ const (
capabilityExecConfigRelativePath = "config"
capabilityExecCertsRelativePath = "certs"
capabilityExternal = "external"
capabilityServiceConnect = "service-connect-v1"
)

var (
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 17a56f3

Please sign in to comment.