diff --git a/agent/api/task/task.go b/agent/api/task/task.go index d2f95d3b192..87548dd05a5 100644 --- a/agent/api/task/task.go +++ b/agent/api/task/task.go @@ -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) } } diff --git a/agent/api/task/task_test.go b/agent/api/task/task_test.go index b1e1cecf458..99bffe3f1dc 100644 --- a/agent/api/task/task_test.go +++ b/agent/api/task/task_test.go @@ -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), } @@ -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) @@ -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) } diff --git a/agent/taskresource/envFiles/envfile.go b/agent/taskresource/envFiles/envfile.go index 546844d02b8..2a302f9fc54 100644 --- a/agent/taskresource/envFiles/envfile.go +++ b/agent/taskresource/envFiles/envfile.go @@ -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