fix(eks): isolate capacity backups from live clusters (#4663)

This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-09-29 14:25:29 -04:00
1 parent 78c06239be
commit ef08877837
3 files changed
+93 -10

No files matched your search

+9 -2
View File
@@ -417,8 +417,15 @@ container until the replacement starts and restarts it if replacement fails. Thi
containers started before resource limits were available. If Docker cannot remove the stopped
backup after a successful replacement, the new node keeps running and cluster deletion retries
the backup cleanup after stopping the live node. If cleanup still fails, deletion reports the
error and can be retried before the data volume is removed. Backup container names end in
`.capacity-backup`, which cannot match an EKS cluster name.
error and can be retried before the data volume is removed. Backup container names put the
`capacity-backup.` marker before the account-qualified cluster name, for example
`floci-aws-eks-capacity-backup.demo` for the default account and
`floci-aws-eks-capacity-backup.999999999999.demo` for another account. The configured Docker resource
namespace applies to backups too. This keeps backup names outside both accounts' live-container
namespaces without changing existing cluster container names or data volumes.
Cleanup only targets this backup namespace; it does not look up old suffix-form names, which can
identify another account's live cluster. Verify ownership before manually removing leftover stopped
backups after upgrading.
#### Cluster node provider ID and topology labels
@@ -711,8 +711,11 @@ public class EksClusterManager
}
}
private static String capacityBackupName(Cluster cluster) {
return cluster.getDockerName() + ".capacity-backup";
private String capacityBackupName(Cluster cluster) {
// The marker must precede the account qualifier: no account ID can be capacity-backup,
// and no cluster name can contain a dot. A suffix can collide with another account's node.
return ContainerStorageHelper.resourceName(config, "eks", null,
"capacity-backup." + accountQualifiedClusterName(cluster));
}
/**
@@ -1072,10 +1075,13 @@ public class EksClusterManager
* default-account name.
*/
private String accountQualifiedName(Cluster cluster) {
return ContainerStorageHelper.resourceName(config, "eks", null, accountQualifiedClusterName(cluster));
}
private String accountQualifiedClusterName(Cluster cluster) {
String accountId = cluster.getAccountId();
boolean defaultAccount = accountId == null || accountId.equals(config.defaultAccountId());
return ContainerStorageHelper.resourceName(config, "eks", null,
defaultAccount ? cluster.getName() : accountId + "." + cluster.getName());
return defaultAccount ? cluster.getName() : accountId + "." + cluster.getName();
}
/**
@@ -511,7 +511,7 @@ class EksClusterManagerTest {
verify(portAllocator, never()).release(6441);
verify(dockerClient).stopContainerCmd("cid-old");
verify(lifecycleManager, Mockito.times(2))
.removeIfExistsStrict("floci-eks-demo.capacity-backup");
.removeIfExistsStrict("floci-aws-eks-capacity-backup.demo");
}
@Test
@@ -537,11 +537,81 @@ class EksClusterManagerTest {
assertFalse("foo.capacity-backup".matches(EksService.CLUSTER_NAME_REGEX));
assertEquals("floci-eks-foo-capacity-backup", manager.clusterResourceName(other));
verify(lifecycleManager, Mockito.times(3))
.removeIfExistsStrict("floci-eks-foo.capacity-backup");
.removeIfExistsStrict("floci-aws-eks-capacity-backup.foo");
verify(lifecycleManager, never()).removeIfExistsStrict(other.getDockerName());
verify(lifecycleManager, never()).stopAndRemove("cid-other", null);
}
@ParameterizedTest
@ValueSource(strings = {"floci-eks-", "floci-aws-eks-"})
void deletingNumericClusterDoesNotRemoveAnotherAccountsCluster(String prefix) {
when(config.defaultAccountId()).thenReturn("000000000000");
Cluster cluster = cluster();
cluster.setAccountId("000000000000");
cluster.setName("999999999999");
cluster.setDockerName(prefix + cluster.getName());
cluster.setContainerId("cid-numeric");
String otherClusterName = "capacity-backup";
String otherDockerName = prefix + "999999999999." + otherClusterName;
assertTrue(cluster.getName().matches(EksService.CLUSTER_NAME_REGEX));
assertTrue(otherClusterName.matches(EksService.CLUSTER_NAME_REGEX));
manager.stopCluster(cluster);
verify(lifecycleManager).stopAndRemove("cid-numeric", null);
verify(lifecycleManager).removeIfExistsStrict("floci-aws-eks-capacity-backup.999999999999");
verify(lifecycleManager, never()).removeIfExistsStrict(otherDockerName);
}
@ParameterizedTest
@ValueSource(strings = {"floci-eks-", "floci-aws-eks-"})
void replacingNumericClusterDoesNotRemoveAnotherAccountsCluster(String prefix) {
when(config.defaultAccountId()).thenReturn("000000000000");
stubFreshStart("cid-new", 6441);
Cluster cluster = cluster();
cluster.setAccountId("000000000000");
cluster.setName("999999999999");
cluster.setDockerName(prefix + cluster.getName());
cluster.setContainerId("cid-numeric");
cluster.setHostPort(6441);
cluster.setNodeInstanceType("t3.medium");
String otherDockerName = prefix + "999999999999.capacity-backup";
assertTrue(manager.restartForNodeCapacity(cluster, "m5.large"));
assertEquals("cid-new", cluster.getContainerId());
verify(lifecycleManager, Mockito.times(2))
.removeIfExistsStrict("floci-aws-eks-capacity-backup.999999999999");
verify(dockerClient.renameContainerCmd("cid-numeric"))
.withName("floci-aws-eks-capacity-backup.999999999999");
verify(lifecycleManager, never()).removeIfExistsStrict(otherDockerName);
verify(dockerClient.renameContainerCmd("cid-numeric"), never()).withName(otherDockerName);
}
@ParameterizedTest
@ValueSource(strings = {"000000000000", "111111111111", "999999999999"})
void capacityBackupsRespectAccountAndResourceNamespace(String accountId) {
when(config.defaultAccountId()).thenReturn("000000000000");
EmulatorConfig.DockerConfig docker = Mockito.mock(EmulatorConfig.DockerConfig.class);
when(config.docker()).thenReturn(docker);
when(docker.resourceNamespace()).thenReturn(Optional.of("isolated"));
Cluster cluster = cluster();
cluster.setAccountId(accountId);
cluster.setName("demo");
cluster.setDockerName(manager.clusterResourceName(cluster));
cluster.setContainerId("cid-node");
String qualifiedName = accountId.equals("000000000000")
? cluster.getName() : accountId + "." + cluster.getName();
manager.stopCluster(cluster);
verify(lifecycleManager).removeIfExistsStrict(
"floci-aws-isolated-eks-capacity-backup." + qualifiedName);
verify(lifecycleManager, never()).removeIfExistsStrict(cluster.getDockerName() + ".capacity-backup");
assertEquals("floci-aws-isolated-eks-" + qualifiedName, cluster.getDockerName());
}
@Test
void failedFirstNodeGroupReplacementRestoresPreviousContainerAndType() {
when(lifecycleManager.create(any())).thenReturn("cid-new");
@@ -574,7 +644,7 @@ class EksClusterManagerTest {
.thenReturn(new ContainerInfo("cid-old", Map.of(), Map.of(6443, 6440)));
stubFreshStart("cid-new", 6440);
Mockito.doNothing().doThrow(new IllegalStateException("Docker cleanup failed"))
.when(lifecycleManager).removeIfExistsStrict("floci-eks-demo.capacity-backup");
.when(lifecycleManager).removeIfExistsStrict("floci-aws-eks-capacity-backup.demo");
Cluster cluster = cluster();
manager.restoreCluster(cluster);
@@ -648,7 +718,7 @@ class EksClusterManagerTest {
cluster.setDockerName("floci-eks-demo");
cluster.setContainerId("cid-new");
Mockito.doThrow(new IllegalStateException("Docker cleanup failed"))
.when(lifecycleManager).removeIfExistsStrict("floci-eks-demo.capacity-backup");
.when(lifecycleManager).removeIfExistsStrict("floci-aws-eks-capacity-backup.demo");
assertThrows(IllegalStateException.class, () -> manager.stopCluster(cluster));