Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loading of AppNet Agent and capability publishing #3281

Merged
merged 2 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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