Light, fluffy, and always free - The AWS Local Emulator alternative
fix(eks): use container IP for readiness polling and handle startup failures (#873)
Hector Ventura70e61dcbda8f
diff --git a/src/main/java/io/github/hectorvent/floci/services/eks/EksClusterManager.java b/src/main/java/io/github/hectorvent/floci/services/eks/EksClusterManager.javaindex d5377e8887..6d20bbd95a 100644--- a/src/main/java/io/github/hectorvent/floci/services/eks/EksClusterManager.java+++ b/src/main/java/io/github/hectorvent/floci/services/eks/EksClusterManager.java@@ -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;}diff --git a/src/main/java/io/github/hectorvent/floci/services/eks/EksService.java b/src/main/java/io/github/hectorvent/floci/services/eks/EksService.javaindex 411d709390..186504bf66 100644--- a/src/main/java/io/github/hectorvent/floci/services/eks/EksService.java+++ b/src/main/java/io/github/hectorvent/floci/services/eks/EksService.java@@ -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);diff --git a/src/main/java/io/github/hectorvent/floci/services/eks/model/Cluster.java b/src/main/java/io/github/hectorvent/floci/services/eks/model/Cluster.javaindex 7215bd94b6..2817812d5d 100644--- a/src/main/java/io/github/hectorvent/floci/services/eks/model/Cluster.java+++ b/src/main/java/io/github/hectorvent/floci/services/eks/model/Cluster.java@@ -56,6 +56,9 @@ public class Cluster {@JsonIgnoreprivate 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; }}