fix(eks): use container IP for readiness polling and handle startup failures (#873)

This commit is contained in:
Hector Ventura authored and GitHub committed 2026-05-17 08:39:16 -05:00
1 parent dc2efe75e8
commit 70e61dcbda
3 files changed
+30 -5

No files matched your search

@@ -100,22 +100,36 @@ public class EksClusterManager {
ContainerInfo info = lifecycleManager.createAndStart(spec);
cluster.setContainerId(info.containerId());
// Set a preliminary endpoint (will be confirmed after readiness check)
// Public endpoint uses the container name (DNS-resolvable on user-defined networks).
// Internal endpoint uses the resolved IP from ContainerLifecycleManager so the
// readiness poller works on the default bridge network where container-name DNS
// is not available.
if (containerDetector.isRunningInContainer()) {
cluster.setEndpoint("https://" + containerName + ":" + K3S_API_SERVER_PORT);
ContainerLifecycleManager.EndpointInfo ep = info.getEndpoint(K3S_API_SERVER_PORT);
if (ep != null) {
cluster.setInternalEndpoint("https://" + ep.host() + ":" + ep.port());
} else {
cluster.setInternalEndpoint(cluster.getEndpoint());
}
} else {
cluster.setEndpoint("https://localhost:" + hostPort);
cluster.setInternalEndpoint(cluster.getEndpoint());
}
LOG.infov("k3s container {0} started for cluster {1} on port {2}",
info.containerId(), cluster.getName(), hostPort);
LOG.infov("k3s container {0} started for cluster {1} on port {2} (internal: {3})",
info.containerId(), cluster.getName(), hostPort, cluster.getInternalEndpoint());
}
/**
* Checks whether the k3s API server is ready by polling its /readyz endpoint.
*/
public boolean isReady(Cluster cluster) {
String endpoint = cluster.getEndpoint();
// Prefer internalEndpoint (IP-based) for connectivity — works on both user-defined
// networks and the default bridge where container-name DNS is unavailable.
String endpoint = cluster.getInternalEndpoint() != null
? cluster.getInternalEndpoint()
: cluster.getEndpoint();
if (endpoint == null || cluster.getContainerId() == null) {
return false;
}
@@ -100,7 +100,12 @@ public class EksService implements TagHandler {
cluster.setStatus(ClusterStatus.ACTIVE);
cluster.setEndpoint("https://localhost:" + config.services().eks().apiServerBasePort());
} else {
clusterManager.startCluster(cluster);
try {
clusterManager.startCluster(cluster);
} catch (Exception e) {
LOG.errorv("Failed to start k3s container for cluster {0}: {1}", name, e.getMessage());
cluster.setStatus(ClusterStatus.FAILED);
}
}
storage.put(name, cluster);
@@ -56,6 +56,9 @@ public class Cluster {
@JsonIgnore
private String accountId;
@JsonIgnore
private String internalEndpoint;
public Cluster() {}
public String getName() { return name; }
@@ -99,4 +102,7 @@ public class Cluster {
public String getAccountId() { return accountId; }
public void setAccountId(String accountId) { this.accountId = accountId; }
public String getInternalEndpoint() { return internalEndpoint; }
public void setInternalEndpoint(String internalEndpoint) { this.internalEndpoint = internalEndpoint; }
}