mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(codedeploy): match any EC2 deployment tag filter (#8040)
This commit is contained in:
1 parent
0f30a7d1f3
commit
b3e5ecc486
3 files changed
+155
-10
No files matched your search
@@ -18,6 +18,7 @@ import io.floci.aws.services.codedeploy.model.DeploymentConfig;
|
||||
import io.floci.aws.services.codedeploy.model.DeploymentGroup;
|
||||
import io.floci.aws.services.codedeploy.model.OnPremisesInstance;
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.services.ec2.model.Tag;
|
||||
import io.floci.aws.services.ecs.EcsService;
|
||||
import io.floci.aws.services.ecs.model.CreateTaskSetRequest;
|
||||
import io.floci.aws.services.ecs.model.TaskSet;
|
||||
@@ -36,6 +37,7 @@ import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -1092,17 +1094,11 @@ public class CodeDeployService {
|
||||
// EC2 instances by tag filters
|
||||
List<Map<String, String>> ec2TagFilters = group.getEc2TagFilters();
|
||||
if (ec2TagFilters != null && !ec2TagFilters.isEmpty()) {
|
||||
Map<String, List<String>> filters = new java.util.LinkedHashMap<>();
|
||||
for (Map<String, String> filter : ec2TagFilters) {
|
||||
String key = filter.get("Key");
|
||||
String value = filter.get("Value");
|
||||
if (key != null && value != null) {
|
||||
filters.computeIfAbsent("tag:" + key, k -> new ArrayList<>()).add(value);
|
||||
}
|
||||
}
|
||||
try {
|
||||
ec2Service.describeInstances(region, null, filters).stream()
|
||||
ec2Service.describeInstances(region, List.of(), Map.of()).stream()
|
||||
.flatMap(r -> r.getInstances().stream())
|
||||
.filter(inst -> matchesTagFilters(ec2TagMaps(inst.getTags()),
|
||||
ec2TagFilters, TagFilterMatchMode.ANY))
|
||||
.map(inst -> inst.getInstanceId())
|
||||
.filter(id -> id != null)
|
||||
.forEach(instanceIds::add);
|
||||
@@ -1133,6 +1129,18 @@ public class CodeDeployService {
|
||||
return instanceIds;
|
||||
}
|
||||
|
||||
private List<Map<String, String>> ec2TagMaps(List<Tag> tags) {
|
||||
if (tags == null) { return List.of(); }
|
||||
List<Map<String, String>> result = new ArrayList<>();
|
||||
for (Tag tag : tags) {
|
||||
Map<String, String> fields = new HashMap<>();
|
||||
fields.put("Key", tag.getKey());
|
||||
fields.put("Value", tag.getValue());
|
||||
result.add(fields);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private enum TagFilterMatchMode { ALL, ANY }
|
||||
|
||||
private boolean matchesTagFilters(List<Map<String, String>> instanceTags,
|
||||
|
||||
Reference in new issue
Block a user