Skip to content

Commit

Permalink
Add ServiceConnect image to clean-up exclusion list
Browse files Browse the repository at this point in the history
  • Loading branch information
yinyic committed Dec 15, 2022
1 parent fc99baf commit 209842f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
6 changes: 5 additions & 1 deletion agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ func (agent *ecsAgent) doStart(containerChangeEventStream *eventstream.EventStre
}
return exitcodes.ExitTerminal
}
agent.serviceconnectManager.SetECSClient(client, agent.containerInstanceARN)
scManager := agent.serviceconnectManager
scManager.SetECSClient(client, agent.containerInstanceARN)
if loaded, _ := scManager.IsLoaded(agent.dockerClient); loaded {
imageManager.AddImageToCleanUpExclusionList(agent.serviceconnectManager.GetLoadedImageName())
}

// Add container instance ARN to metadata manager
if agent.cfg.ContainerMetadataEnabled.Enabled() {
Expand Down
8 changes: 8 additions & 0 deletions agent/engine/docker_image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type ImageManager interface {
GetImageStateFromImageName(containerImageName string) (*image.ImageState, bool)
StartImageCleanupProcess(ctx context.Context)
SetDataClient(dataClient data.Client)
AddImageToCleanUpExclusionList(image string)
}

// dockerImageManager accounts all the images and their states in the instance.
Expand Down Expand Up @@ -112,6 +113,13 @@ func buildImageCleanupExclusionList(cfg *config.Config) []string {
return excludedImages
}

func (imageManager *dockerImageManager) AddImageToCleanUpExclusionList(image string) {
imageManager.imageCleanupExclusionList = append(imageManager.imageCleanupExclusionList, image)
logger.Info("Image excluded from cleanup", logger.Fields{
field.Image: image,
})
}

func (imageManager *dockerImageManager) AddAllImageStates(imageStates []*image.ImageState) {
imageManager.updateLock.Lock()
defer imageManager.updateLock.Unlock()
Expand Down
12 changes: 12 additions & 0 deletions agent/engine/mocks/engine_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion agent/engine/serviceconnect/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
type Manager interface {
loader.Loader

GetLoadedImageName() (string, error)
GetLoadedImageName() string
AugmentTaskContainer(task *apitask.Task, container *apicontainer.Container, hostConfig *dockercontainer.HostConfig) error
CreateInstanceTask(config *config.Config) (*apitask.Task, error)
AugmentInstanceContainer(task *apitask.Task, container *apicontainer.Container, hostConfig *dockercontainer.HostConfig) error
Expand Down
16 changes: 6 additions & 10 deletions agent/engine/serviceconnect/manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (m *manager) augmentAgentContainer(task *apitask.Task, container *apicontai
config.DrainRequest = m.adminDrainRequest

task.PopulateServiceConnectRuntimeConfig(config)
container.Image, _ = m.GetLoadedImageName()
container.Image = m.GetLoadedImageName()
return nil
}

Expand Down Expand Up @@ -297,10 +297,7 @@ func (m *manager) AugmentTaskContainer(task *apitask.Task, container *apicontain
}

func (m *manager) CreateInstanceTask(cfg *config.Config) (*apitask.Task, error) {
imageName, err := m.GetLoadedImageName()
if err != nil {
return nil, err
}
imageName := m.GetLoadedImageName()
containerRunning := apicontainerstatus.ContainerRunning
dockerHostConfig := dockercontainer.HostConfig{
NetworkMode: apitask.HostNetworkMode,
Expand Down Expand Up @@ -404,7 +401,7 @@ func (agent *manager) LoadImage(ctx context.Context, _ *config.Config, dockerCli
continue
}
agent.setLoadedAppnetVerion(supportedAppnetInterfaceVersion)
imageName, _ := agent.GetLoadedImageName()
imageName := agent.GetLoadedImageName()
logger.Info(fmt.Sprintf("Successfully loaded Appnet agent container tarball: %s", agentContainerTarballPath),
logger.Fields{
field.Image: imageName,
Expand All @@ -415,13 +412,12 @@ func (agent *manager) LoadImage(ctx context.Context, _ *config.Config, dockerCli
}

func (agent *manager) IsLoaded(dockerClient dockerapi.DockerClient) (bool, error) {
imageName, _ := agent.GetLoadedImageName()
return loader.IsImageLoaded(imageName, dockerClient)
return loader.IsImageLoaded(agent.GetLoadedImageName(), dockerClient)
}

func (agent *manager) GetLoadedImageName() (string, error) {
func (agent *manager) GetLoadedImageName() string {
agent.agentContainerTag = fmt.Sprintf(defaultAgentContainerTagFormat, agent.appnetInterfaceVersion)
return fmt.Sprintf("%s:%s", agent.agentContainerImageName, agent.agentContainerTag), nil
return fmt.Sprintf("%s:%s", agent.agentContainerImageName, agent.agentContainerTag)
}

func (agent *manager) GetLoadedAppnetVersion() (string, error) {
Expand Down
6 changes: 2 additions & 4 deletions agent/engine/serviceconnect/manager_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ func (*manager) IsLoaded(dockerClient dockerapi.DockerClient) (bool, error) {
func (m *manager) SetECSClient(api.ECSClient, string) {
}

func (*manager) GetLoadedImageName() (string, error) {
return "", loader.NewUnsupportedPlatformError(fmt.Errorf(
"appnetAgent container get image name: unsupported platform: %s/%s",
runtime.GOOS, runtime.GOARCH))
func (*manager) GetLoadedImageName() string {
return ""
}

func (*manager) GetLoadedAppnetVersion() (string, error) {
Expand Down
5 changes: 2 additions & 3 deletions agent/engine/serviceconnect/mock/manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 209842f

Please sign in to comment.