mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(autoscaling): reconcile groups in every account (#3824)
This commit is contained in:
1 parent
51467dbc23
commit
dfb294a79a
3 files changed
+117
-6
No files matched your search
+24
-5
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.autoscaling;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AsgInstance;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AutoScalingGroup;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.LaunchConfiguration;
|
||||
@@ -80,12 +81,30 @@ public class AutoScalingReconciler {
|
||||
}
|
||||
|
||||
void reconcileAll() {
|
||||
for (AutoScalingGroup asg : asgService.describeAutoScalingGroups(null, null)) {
|
||||
try {
|
||||
reconcile(asg);
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Reconcile failed for ASG {0}: {1}", asg.getAutoScalingGroupName(), e.getMessage());
|
||||
Set<String> accountIds;
|
||||
try {
|
||||
accountIds = asgService.autoScalingGroupAccountIds();
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Could not enumerate Auto Scaling group accounts: {0}", e.getMessage());
|
||||
return;
|
||||
}
|
||||
for (String accountId : accountIds) {
|
||||
RequestScopes.runAs(accountId, () -> reconcileAccount(accountId));
|
||||
}
|
||||
}
|
||||
|
||||
private void reconcileAccount(String accountId) {
|
||||
try {
|
||||
for (AutoScalingGroup asg : asgService.describeAutoScalingGroups(null, null)) {
|
||||
try {
|
||||
reconcile(asg);
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Reconcile failed for ASG {0} in account {1}: {2}",
|
||||
asg.getAutoScalingGroupName(), accountId, e.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Could not reconcile Auto Scaling groups in account {0}: {1}", accountId, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-1
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackedMap;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.*;
|
||||
@@ -64,6 +65,7 @@ public class AutoScalingService {
|
||||
private Map<String, LaunchConfiguration> launchConfigs = new ConcurrentHashMap<>();
|
||||
private Map<String, AutoScalingGroup> groups = new ConcurrentHashMap<>();
|
||||
private final Map<String, Object> groupLocks = new ConcurrentHashMap<>();
|
||||
private AccountAwareStorageBackend<AutoScalingGroup> groupsStore;
|
||||
private Map<String, LifecycleHook> hooks = new ConcurrentHashMap<>();
|
||||
private Map<String, ScalingPolicy> policies = new ConcurrentHashMap<>();
|
||||
private Map<String, ScalingActivity> activities = new ConcurrentHashMap<>();
|
||||
@@ -78,7 +80,9 @@ public class AutoScalingService {
|
||||
return;
|
||||
}
|
||||
this.launchConfigs = storageBacked("autoscaling-launch-configurations.json", new TypeReference<Map<String, LaunchConfiguration>>() {});
|
||||
this.groups = storageBacked("autoscaling-groups.json", new TypeReference<Map<String, AutoScalingGroup>>() {});
|
||||
this.groupsStore = storageFactory.create("autoscaling", "autoscaling-groups.json",
|
||||
new TypeReference<Map<String, AutoScalingGroup>>() {});
|
||||
this.groups = new StorageBackedMap<>(groupsStore);
|
||||
this.hooks = storageBacked("autoscaling-lifecycle-hooks.json", new TypeReference<Map<String, LifecycleHook>>() {});
|
||||
this.policies = storageBacked("autoscaling-policies.json", new TypeReference<Map<String, ScalingPolicy>>() {});
|
||||
this.activities = storageBacked("autoscaling-activities.json", new TypeReference<Map<String, ScalingActivity>>() {});
|
||||
@@ -392,6 +396,15 @@ public class AutoScalingService {
|
||||
return groupLocks.computeIfAbsent(key, ignored -> new Object());
|
||||
}
|
||||
|
||||
Set<String> autoScalingGroupAccountIds() {
|
||||
if (groupsStore == null) {
|
||||
return Set.of();
|
||||
}
|
||||
return groupsStore.scanAllAccountEntries(key -> true).stream()
|
||||
.map(AccountAwareStorageBackend.AccountEntry::accountId)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
}
|
||||
|
||||
public void setDesiredCapacity(String region, String name, int desiredCapacity) {
|
||||
AutoScalingGroup asg = requireGroup(region, name);
|
||||
if (desiredCapacity < asg.getMinSize() || desiredCapacity > asg.getMaxSize()) {
|
||||
|
||||
Reference in new issue
Block a user