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 b5036ba commit 034b598
Show file tree
Hide file tree
Showing 8 changed files with 536 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
20 changes: 20 additions & 0 deletions agent/app/agent_capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const (
capabilityExecConfigRelativePath = "config"
capabilityExecCertsRelativePath = "certs"
capabilityExternal = "external"
capabilityServiceConnect = "service-connect-v1"
)

var (
Expand Down Expand Up @@ -114,6 +115,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 +178,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 +274,11 @@ func (agent *ecsAgent) capabilities() ([]*ecs.Attribute, error) {
if err != nil {
return nil, err
}
// add service-connect capabilities if applicable
capabilities, err = agent.appendServiceConenctCapabilities(capabilities)
if err != nil {
return nil, err
}

if agent.cfg.External.Enabled() {
// Add external specific capability; remove external unsupported capabilities.
Expand Down Expand Up @@ -438,6 +446,18 @@ func (agent *ecsAgent) appendExecCapabilities(capabilities []*ecs.Attribute) ([]
return appendNameOnlyAttribute(capabilities, attributePrefix+capabilityExec), nil
}

func (agent *ecsAgent) appendServiceConenctCapabilities(capabilities []*ecs.Attribute) ([]*ecs.Attribute, error) {
if loaded, _ := agent.serviceconnectLoader.IsLoaded(agent.dockerClient); !loaded {
_, err := agent.serviceconnectLoader.LoadImage(agent.ctx, agent.dockerClient)
if err != nil {
seelog.Warn("ServiceConnect Capability: Failed to load appnet Agent container")
return capabilities, nil
}
}

return appendNameOnlyAttribute(capabilities, attributePrefix+capabilityServiceConnect), nil
}

func defaultGetSubDirectories(path string) ([]string, error) {
var subDirectories []string

Expand Down
Loading

0 comments on commit 034b598

Please sign in to comment.