Skip to content

Commit

Permalink
fix (ecs): Unstable deployments when there are more than one containe…
Browse files Browse the repository at this point in the history
…r in task definition (#5544)
  • Loading branch information
Alexander Tyutyunnik committed Mar 11, 2020
1 parent deab492 commit 275cf8d
Showing 1 changed file with 47 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,24 @@ protected List<TaskHealth> getItems(AmazonECS ecs, ProviderCache providerCache)
continue;
}

TaskHealth taskHealth;
if (task.getContainers().get(0).getNetworkBindings().size() >= 1) {
taskHealth =
inferHealthNetworkBindedContainer(
amazonloadBalancing,
task,
containerInstance,
serviceName,
service,
taskDefinition);
} else {
TaskHealth taskHealth = null;
Collection<Container> containers = task.getContainers();

for (Container container : containers) {
if (container.getNetworkBindings().size() >= 1) {
taskHealth =
inferHealthNetworkBindedContainer(
amazonloadBalancing,
task,
containerInstance,
serviceName,
service,
taskDefinition);
break;
}
}

if (taskHealth == null) {
taskHealth =
inferHealthNetworkInterfacedContainer(
amazonloadBalancing, task, serviceName, service, taskDefinition);
Expand Down Expand Up @@ -201,7 +208,15 @@ private TaskHealth inferHealthNetworkInterfacedContainer(
continue;
}

NetworkInterface networkInterface = task.getContainers().get(0).getNetworkInterfaces().get(0);
Collection<Container> containers = task.getContainers();
NetworkInterface networkInterface = null;

for (Container container : containers) {
if (container.getNetworkInterfaces().size() >= 1) {
networkInterface = container.getNetworkInterfaces().get(0);
break;
}
}

overallTaskHealth =
describeTargetHealth(
Expand Down Expand Up @@ -372,17 +387,29 @@ private boolean isContainerMissingNetworking(Task task) {
}

private boolean isTaskMissingNetworkBindings(Task task) {
return task.getContainers().isEmpty()
|| task.getContainers().get(0).getNetworkBindings() == null
|| task.getContainers().get(0).getNetworkBindings().isEmpty()
|| task.getContainers().get(0).getNetworkBindings().get(0) == null;
Collection<Container> containers = task.getContainers();

for (Container container : containers) {
if (!(container.getNetworkBindings() == null
|| container.getNetworkBindings().isEmpty()
|| container.getNetworkBindings().get(0) == null)) {
return false;
}
}
return true;
}

private boolean isTaskMissingNetworkInterfaces(Task task) {
return task.getContainers().isEmpty()
|| task.getContainers().get(0).getNetworkInterfaces() == null
|| task.getContainers().get(0).getNetworkInterfaces().isEmpty()
|| task.getContainers().get(0).getNetworkInterfaces().get(0) == null;
Collection<Container> containers = task.getContainers();

for (Container container : containers) {
if (!(container.getNetworkInterfaces() == null
|| container.getNetworkInterfaces().isEmpty()
|| container.getNetworkInterfaces().get(0) == null)) {
return false;
}
}
return true;
}

@Override
Expand Down

0 comments on commit 275cf8d

Please sign in to comment.