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

Address envFile resource naming defect #3554

Merged
merged 1 commit into from
Feb 6, 2023
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
2 changes: 1 addition & 1 deletion agent/api/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3240,7 +3240,7 @@ func (task *Task) initializeEnvfilesResource(config *config.Config, credentialsM
return errors.Wrapf(err, "unable to initialize envfiles resource for container %s", container.Name)
}
task.AddResource(envFiles.ResourceName, envfileResource)
container.BuildResourceDependency(envfileResource.GetName(), resourcestatus.ResourceCreated, apicontainerstatus.ContainerCreated)
container.BuildResourceDependency(envfileResource.GetName(), resourcestatus.ResourceStatus(envFiles.EnvFileCreated), apicontainerstatus.ContainerCreated)
yinyic marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
49 changes: 38 additions & 11 deletions agent/api/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3778,7 +3778,7 @@ func TestPostUnmarshalTaskEnvfiles(t *testing.T) {
}

resourceDep := apicontainer.ResourceDependency{
Name: envFiles.ResourceName,
Name: envFiles.ResourceName + "_" + container.Name,
RequiredStatus: resourcestatus.ResourceStatus(envFiles.EnvFileCreated),
}

Expand All @@ -3791,22 +3791,34 @@ func TestPostUnmarshalTaskEnvfiles(t *testing.T) {
}

func TestInitializeAndGetEnvfilesResource(t *testing.T) {
yinyic marked this conversation as resolved.
Show resolved Hide resolved
envfile := apicontainer.EnvironmentFile{
Value: "s3://bucket/envfile",
envfile1 := apicontainer.EnvironmentFile{
Value: "s3://bucket/envfile1",
Type: "s3",
}

container := &apicontainer.Container{
Name: "containerName",
envfile2 := apicontainer.EnvironmentFile{
Value: "s3://bucket/envfile2",
Type: "s3",
}

container1 := &apicontainer.Container{
Name: "containerName1",
Image: "image:tag",
EnvironmentFiles: []apicontainer.EnvironmentFile{envfile},
EnvironmentFiles: []apicontainer.EnvironmentFile{envfile1},
TransitionDependenciesMap: make(map[apicontainerstatus.ContainerStatus]apicontainer.TransitionDependencySet),
}

container2 := &apicontainer.Container{
Name: "containerName2",
Image: "image:tag",
EnvironmentFiles: []apicontainer.EnvironmentFile{envfile2},
TransitionDependenciesMap: make(map[apicontainerstatus.ContainerStatus]apicontainer.TransitionDependencySet),
}

task := &Task{
Arn: "testArn",
ResourcesMapUnsafe: make(map[string][]taskresource.TaskResource),
Containers: []*apicontainer.Container{container},
Containers: []*apicontainer.Container{container1, container2},
}

ctrl := gomock.NewController(t)
Expand All @@ -3819,15 +3831,30 @@ func TestInitializeAndGetEnvfilesResource(t *testing.T) {

task.initializeEnvfilesResource(cfg, credentialsManager)

resourceDep := apicontainer.ResourceDependency{
Name: envFiles.ResourceName,
resourceDep1 := apicontainer.ResourceDependency{
Name: envFiles.ResourceName + "_" + container1.Name,
RequiredStatus: resourcestatus.ResourceStatus(envFiles.EnvFileCreated),
}

assert.Equal(t, resourceDep,
resourceDep2 := apicontainer.ResourceDependency{
Name: envFiles.ResourceName + "_" + container2.Name,
RequiredStatus: resourcestatus.ResourceStatus(envFiles.EnvFileCreated),
}

assert.Equal(t, resourceDep1,
task.Containers[0].TransitionDependenciesMap[apicontainerstatus.ContainerCreated].ResourceDependencies[0])

_, ok := task.getEnvfilesResource("containerName")
assert.Equal(t, resourceDep2,
task.Containers[1].TransitionDependenciesMap[apicontainerstatus.ContainerCreated].ResourceDependencies[0])

assert.NotEqual(t,
task.Containers[0].TransitionDependenciesMap[apicontainerstatus.ContainerCreated].ResourceDependencies[0],
task.Containers[1].TransitionDependenciesMap[apicontainerstatus.ContainerCreated].ResourceDependencies[0])

_, ok := task.getEnvfilesResource(container1.Name)
assert.True(t, ok)

_, ok = task.getEnvfilesResource(container2.Name)
assert.True(t, ok)
}

Expand Down
4 changes: 2 additions & 2 deletions agent/taskresource/envFiles/envfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ func (envfile *EnvironmentFileResource) GetCreatedAt() time.Time {
return envfile.createdAtUnsafe
}

// GetName returns the name fo the resource
// GetName returns the name of the environment file resource
func (envfile *EnvironmentFileResource) GetName() string {
return ResourceName
return ResourceName + "_" + envfile.GetContainerName()
}

// DesiredTerminal returns true if the resource's desired status is REMOVED
Expand Down