Skip to content

Commit

Permalink
Address envFile resource naming defect
Browse files Browse the repository at this point in the history
  • Loading branch information
danehlim committed Jan 31, 2023
1 parent 822c4eb commit 779b454
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
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)
}
}

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) {
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

0 comments on commit 779b454

Please sign in to comment.