mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(eks): release the API server port when a cluster is deleted or fails to start (#4937)
stopCluster never returned the k3s API server port to the PortAllocator, so after about 100 create/delete cycles (the default 6500-6599 range) CreateCluster failed with "No free port" until restart. A start that failed after allocating its port leaked it the same way. Release the port on delete and clear it from the cluster so a delete retried after a failed capacity-backup cleanup cannot free a port another cluster now holds. Release a newly allocated port when the launch fails; a port retained across a capacity restart still belongs to the surviving container and is kept.
This commit is contained in:
1 parent
3597afda07
commit
72788dfdb8
2 files changed
+55
No files matched your search
@@ -402,7 +402,19 @@ public class EksClusterManager
|
||||
config.services().eks().apiServerMaxPort());
|
||||
|
||||
cluster.setHostPort(hostPort);
|
||||
try {
|
||||
launchCluster(cluster, image, containerName, hostPort);
|
||||
} catch (RuntimeException e) {
|
||||
// A retained port still belongs to the surviving container the caller restores.
|
||||
if (retainedPort == null) {
|
||||
portAllocator.release(hostPort);
|
||||
cluster.setHostPort(0);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void launchCluster(Cluster cluster, String image, String containerName, int hostPort) {
|
||||
// Remove any stale container
|
||||
ContainerStorageHelper.removeStaleContainer(config, lifecycleManager, containerName);
|
||||
|
||||
@@ -822,6 +834,11 @@ public class EksClusterManager
|
||||
return;
|
||||
}
|
||||
lifecycleManager.stopAndRemove(cluster.getContainerId(), logStream);
|
||||
if (cluster.getHostPort() > 0) {
|
||||
portAllocator.release(cluster.getHostPort());
|
||||
// Cleared so a delete retried after a failed backup cleanup cannot free a reused port.
|
||||
cluster.setHostPort(0);
|
||||
}
|
||||
if (cluster.getDockerName() != null) {
|
||||
// A failed backup cleanup must not leave the live node running. Keep the cluster
|
||||
// record so explicit deletion can be retried once Docker accepts the removal.
|
||||
|
||||
Reference in new issue
Block a user