mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(eks): stop shipping a default storage class in clusters (#5061)
* feat(eks): stop shipping a default storage class in clusters * test(eks): verify coredns rollout status and preserve cluster storage on restore * test(eks): assert storage class absence after coredns rollout completes * docs(eks): clarify stock storage class and provisioner behavior
This commit is contained in:
1 parent
30be71c56e
commit
dc3e9cacec
9 files changed
+326
-10
No files matched your search
@@ -510,6 +510,14 @@ Floci derives the availability zone from the cluster region (for example, `<regi
|
||||
|
||||
The node name, the instance ID in `spec.providerID`, and the synthetic EC2 instance (`InstanceId` and `PrivateDnsName`) all describe the same instance. This enables controllers that reconcile nodes against EC2 (such as CSI drivers) to look up the node instance via `DescribeInstances`.
|
||||
|
||||
#### Storage classes
|
||||
|
||||
Stock Amazon EKS clusters historically define a default `gp2` StorageClass pointing to the legacy in-tree `kubernetes.io/aws-ebs` plugin, but run no active storage provisioner without the EBS CSI driver. Unqualified PersistentVolumeClaims remain `Pending` on EKS because nothing can provision them. Floci matches this behavior by disabling k3s's bundled `local-path` provisioner and StorageClass, preventing unqualified claims from silently binding to the node filesystem.
|
||||
|
||||
Callers requiring dynamic volume provisioning can install a driver (such as the `aws-ebs-csi-driver` addon) and define their desired StorageClass.
|
||||
|
||||
For local testing workflows that rely on automatic volume binding without a CSI driver, set `floci.services.eks.default-storage-class: true` (or `FLOCI_SERVICES_EKS_DEFAULT_STORAGE_CLASS=true`) to retain k3s's bundled `local-path` provisioner and default StorageClass.
|
||||
|
||||
## Configuration
|
||||
|
||||
| Variable | Default | Description |
|
||||
@@ -528,6 +536,8 @@ The node name, the instance ID in `spec.providerID`, and the synthetic EC2 insta
|
||||
| `FLOCI_SERVICES_EKS_ENDPOINT_MODE` | `host` | `describe-cluster` endpoint: `host` (`localhost:<hostPort>`) or `network` (container DNS) |
|
||||
| `FLOCI_SERVICES_EKS_IAM_AUTH_WEBHOOK` | `true` | Wire a token-auth webhook into k3s so `aws eks get-token` works |
|
||||
| `FLOCI_SERVICES_EKS_ECR_REGISTRY_MIRROR` | `true` | Inject a containerd `registries.yaml` so pods can pull images pushed to [Floci ECR](ecr.md) |
|
||||
| `FLOCI_SERVICES_EKS_DISABLE_CNI` | `false` | Start k3s without bundled flannel, network policy, and kube-proxy so an external CNI can take over |
|
||||
| `FLOCI_SERVICES_EKS_DEFAULT_STORAGE_CLASS` | `false` | Retain k3s bundled local-path provisioner and default StorageClass (default false matches EKS with no default class) |
|
||||
| `FLOCI_SERVICES_EKS_IRSA_SIGNING_KEY` | `true` | Pass the cluster OIDC signing key to k3s so in-cluster projected service account tokens can assume IAM roles via Floci STS |
|
||||
| `FLOCI_SERVICES_EKS_POD_IDENTITY_WEBHOOK` | `true` | Register a mutating admission webhook that injects pod identity credentials. Needs `FLOCI_TLS_ENABLED=true` |
|
||||
| `FLOCI_SERVICES_EKS_IMDS` | `false` | Enable link-local IMDS (`169.254.169.254`) proxy in cluster containers |
|
||||
|
||||
@@ -3276,13 +3276,25 @@ public interface EmulatorConfig {
|
||||
* --disable-kube-proxy} instead of its bundled networking stack. k3s's default flannel CNI
|
||||
* and kube-proxy run embedded in the k3s server process itself (not separate, killable
|
||||
* DaemonSets), so a real CNI (e.g. Cilium) can only cleanly take over if k3s never starts
|
||||
* its own in the first place — there is no way to evict them after the fact. CoreDNS,
|
||||
* its own in the first place: there is no way to evict them after the fact. CoreDNS,
|
||||
* local-path-provisioner, and metrics-server are unaffected; they don't depend on which CNI
|
||||
* is in place.
|
||||
*/
|
||||
@WithDefault("false")
|
||||
boolean disableCni();
|
||||
|
||||
/**
|
||||
* When false (default), starts k3s with {@code --disable=local-storage} so clusters match
|
||||
* AWS EKS by starting with no default StorageClass and no host-path provisioner. When true,
|
||||
* retains k3s's bundled local-path provisioner and default StorageClass for local workloads
|
||||
* that rely on automatic volume binding without installing a CSI driver.
|
||||
*
|
||||
* <p>Like {@link #disableCni()}, k3s's local-path-provisioner runs embedded in the k3s server
|
||||
* process itself, so this flag must be set at startup rather than applied afterwards.
|
||||
*/
|
||||
@WithDefault("false")
|
||||
boolean defaultStorageClass();
|
||||
|
||||
/**
|
||||
* When true, exposes an IMDS link-local proxy (169.254.169.254:80) inside the cluster container's
|
||||
* network namespace that relays to Floci's EC2 metadata service.
|
||||
|
||||
@@ -99,6 +99,7 @@ public class EksClusterManager
|
||||
private static final int K3S_API_SERVER_PORT = 6443;
|
||||
static final String DEFAULT_NODE_INSTANCE_TYPE = "m5.large";
|
||||
private static final String NODE_CAPACITY_LABEL = "io.floci.eks.node-capacity";
|
||||
private static final String DEFAULT_STORAGE_CLASS_LABEL = "io.floci.eks.default-storage-class";
|
||||
|
||||
private static final String WEBHOOK_CONFIG_DIR = "/etc";
|
||||
private static final String WEBHOOK_CONFIG_FILE = "token-webhook.yaml";
|
||||
@@ -490,7 +491,18 @@ public class EksClusterManager
|
||||
? cluster.getPodCidr()
|
||||
: DEFAULT_POD_CIDR;
|
||||
|
||||
List<String> serverArgs = buildServerArgs(config.services().eks().disableCni(), serviceCidr, clusterCidr);
|
||||
boolean defaultStorageClass = cluster != null && cluster.getDefaultStorageClass() != null
|
||||
? cluster.getDefaultStorageClass()
|
||||
: config.services().eks().defaultStorageClass();
|
||||
if (cluster != null) {
|
||||
cluster.setDefaultStorageClass(defaultStorageClass);
|
||||
}
|
||||
|
||||
List<String> serverArgs = buildServerArgs(
|
||||
config.services().eks().disableCni(),
|
||||
defaultStorageClass,
|
||||
serviceCidr,
|
||||
clusterCidr);
|
||||
|
||||
EksNodeCapacity.Limits nodeLimits = resolveNodeCapacity(cluster);
|
||||
if (nodeLimits != null) {
|
||||
@@ -532,6 +544,7 @@ public class EksClusterManager
|
||||
Map<String, String> labels = new LinkedHashMap<>(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"eks", cluster.getName(), labelAccountId, clusterRegion(cluster)));
|
||||
labels.put(NODE_CAPACITY_LABEL, capacityLabel(cluster, nodeLimits));
|
||||
labels.put(DEFAULT_STORAGE_CLASS_LABEL, String.valueOf(defaultStorageClass));
|
||||
ContainerBuilder.Builder specBuilder = containerBuilder.newContainer(image)
|
||||
.withName(containerName)
|
||||
.withEnv("K3S_KUBECONFIG_MODE", "644")
|
||||
@@ -678,6 +691,13 @@ public class EksClusterManager
|
||||
if (existing.isEmpty()) {
|
||||
LOG.infov("No surviving k3s container for EKS cluster {0}; recreating it "
|
||||
+ "(a surviving data volume is reused)", cluster.getName());
|
||||
if (cluster.getDefaultStorageClass() == null) {
|
||||
boolean targetSetting = config.services().eks().defaultStorageClass();
|
||||
LOG.infov("Recreating EKS cluster {0} with defaultStorageClass={1} "
|
||||
+ "(set floci.services.eks.default-storage-class: true to retain bundled local-path)",
|
||||
cluster.getName(), String.valueOf(targetSetting));
|
||||
cluster.setDefaultStorageClass(targetSetting);
|
||||
}
|
||||
startCluster(cluster);
|
||||
return;
|
||||
}
|
||||
@@ -686,6 +706,14 @@ public class EksClusterManager
|
||||
Map<String, String> existingLabels = existing.get().getLabels();
|
||||
boolean capacityChanged = existingLabels == null
|
||||
|| !desiredCapacity.equals(existingLabels.get(NODE_CAPACITY_LABEL));
|
||||
if (existingLabels != null && existingLabels.containsKey(DEFAULT_STORAGE_CLASS_LABEL)) {
|
||||
cluster.setDefaultStorageClass(Boolean.parseBoolean(existingLabels.get(DEFAULT_STORAGE_CLASS_LABEL)));
|
||||
} else if (cluster.getDefaultStorageClass() == null) {
|
||||
// Surviving container was created before defaultStorageClass was configurable:
|
||||
// preserve prior behavior with local-storage enabled.
|
||||
cluster.setDefaultStorageClass(true);
|
||||
LOG.infov("Adopting pre-upgrade EKS cluster {0} with local-storage enabled", cluster.getName());
|
||||
}
|
||||
if (!adoptSurvivingCluster(cluster, existing.get().getId())) {
|
||||
startCluster(cluster);
|
||||
return;
|
||||
@@ -1319,14 +1347,20 @@ public class EksClusterManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the k3s {@code server} command-line args. When {@code disableCni} is true, flannel,
|
||||
* k3s's default network policy controller, and kube-proxy are all disabled up front: see the
|
||||
* {@code disableCni} config javadoc for why this must happen at startup, not after the fact.
|
||||
* Builds the k3s {@code server} command-line args. When {@code defaultStorageClass} is false,
|
||||
* k3s's bundled local-path provisioner is disabled so clusters match AWS EKS by starting with
|
||||
* no default StorageClass. When {@code disableCni} is true, flannel, k3s's default network
|
||||
* policy controller, and kube-proxy are all disabled up front: see the {@code disableCni}
|
||||
* config javadoc for why this must happen at startup, not after the fact.
|
||||
*/
|
||||
static List<String> buildServerArgs(boolean disableCni, String serviceCidr, String clusterCidr) {
|
||||
static List<String> buildServerArgs(boolean disableCni, boolean defaultStorageClass,
|
||||
String serviceCidr, String clusterCidr) {
|
||||
List<String> serverArgs = new ArrayList<>(List.of("server",
|
||||
"--disable=traefik",
|
||||
"--tls-san=localhost"));
|
||||
if (!defaultStorageClass) {
|
||||
serverArgs.add("--disable=local-storage");
|
||||
}
|
||||
if (disableCni) {
|
||||
serverArgs.add("--flannel-backend=none");
|
||||
serverArgs.add("--disable-network-policy");
|
||||
@@ -1341,8 +1375,12 @@ public class EksClusterManager
|
||||
return serverArgs;
|
||||
}
|
||||
|
||||
static List<String> buildServerArgs(boolean disableCni, String serviceCidr, String clusterCidr) {
|
||||
return buildServerArgs(disableCni, false, serviceCidr, clusterCidr);
|
||||
}
|
||||
|
||||
static List<String> buildServerArgs(boolean disableCni) {
|
||||
return buildServerArgs(disableCni, null, null);
|
||||
return buildServerArgs(disableCni, false, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,13 +92,15 @@ public class EksController {
|
||||
* causes Jackson to omit the property due to @JsonInclude(NON_DEFAULT).
|
||||
*/
|
||||
private Cluster toClusterResponse(Cluster cluster) {
|
||||
if (cluster == null || (!cluster.isExplicitVersion() && cluster.getNodeInstanceType() == null && cluster.getClusterArgs() == null)) {
|
||||
if (cluster == null || (!cluster.isExplicitVersion() && cluster.getNodeInstanceType() == null
|
||||
&& cluster.getClusterArgs() == null && cluster.getDefaultStorageClass() == null)) {
|
||||
return cluster;
|
||||
}
|
||||
Cluster response = cluster.copy();
|
||||
response.setExplicitVersion(false);
|
||||
response.setNodeInstanceType(null);
|
||||
response.setClusterArgs(null);
|
||||
response.setDefaultStorageClass(null);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +110,15 @@ public class Cluster {
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private List<String> clusterArgs;
|
||||
|
||||
/**
|
||||
* Internal setting indicating whether the cluster was started with k3s's bundled
|
||||
* local-path provisioner and default StorageClass. Persisted to storage so restored
|
||||
* clusters preserve their storage behavior across container recreations.
|
||||
*/
|
||||
@JsonProperty("defaultStorageClass")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Boolean defaultStorageClass;
|
||||
|
||||
private AccessConfig accessConfig;
|
||||
|
||||
public AccessConfig getAccessConfig() { return accessConfig; }
|
||||
@@ -189,6 +198,9 @@ public class Cluster {
|
||||
public boolean isExplicitVersion() { return explicitVersion; }
|
||||
public void setExplicitVersion(boolean explicitVersion) { this.explicitVersion = explicitVersion; }
|
||||
|
||||
public Boolean getDefaultStorageClass() { return defaultStorageClass; }
|
||||
public void setDefaultStorageClass(Boolean defaultStorageClass) { this.defaultStorageClass = defaultStorageClass; }
|
||||
|
||||
public Cluster copy() {
|
||||
Cluster c = new Cluster();
|
||||
c.name = this.name;
|
||||
@@ -215,6 +227,7 @@ public class Cluster {
|
||||
c.dockerName = this.dockerName;
|
||||
c.nodeInstanceType = this.nodeInstanceType;
|
||||
c.clusterArgs = this.clusterArgs != null ? new ArrayList<>(this.clusterArgs) : null;
|
||||
c.defaultStorageClass = this.defaultStorageClass;
|
||||
c.accessConfig = this.accessConfig;
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -693,6 +693,7 @@ floci:
|
||||
iam-auth-webhook: true # validate `aws eks get-token` SigV4 tokens through a k3s webhook
|
||||
ecr-registry-mirror: true # inject a registries.yaml so pods can pull images pushed to Floci ECR
|
||||
disable-cni: false # start k3s without its bundled flannel/kube-proxy so a real CNI (e.g. Cilium) can take over
|
||||
default-storage-class: false # start k3s without its bundled local-path provisioner to match EKS
|
||||
imds: false # expose link-local IMDS (169.254.169.254) inside the cluster container
|
||||
imds-pod-network: false # route link-local IMDS traffic from ordinary pod network namespaces (requires imds: true)
|
||||
irsa-signing-key: true # sign k3s service account tokens with the cluster OIDC key
|
||||
|
||||
@@ -235,6 +235,7 @@ class EksClusterManagerTest {
|
||||
List<String> args = EksClusterManager.buildServerArgs(false);
|
||||
|
||||
assertTrue(args.contains("--disable=traefik"));
|
||||
assertTrue(args.contains("--disable=local-storage"));
|
||||
assertFalse(args.contains("--flannel-backend=none"));
|
||||
assertFalse(args.contains("--disable-network-policy"));
|
||||
assertFalse(args.contains("--disable-kube-proxy"));
|
||||
@@ -247,8 +248,27 @@ class EksClusterManagerTest {
|
||||
assertTrue(args.contains("--flannel-backend=none"));
|
||||
assertTrue(args.contains("--disable-network-policy"));
|
||||
assertTrue(args.contains("--disable-kube-proxy"));
|
||||
// Base args must still be present — disableCni only adds flags, never replaces them.
|
||||
// Base args must still be present: disableCni only adds flags, never replaces them.
|
||||
assertTrue(args.contains("--disable=traefik"));
|
||||
assertTrue(args.contains("--disable=local-storage"));
|
||||
assertTrue(args.contains("--tls-san=localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void serverArgsRetainLocalStorageWhenDefaultStorageClassEnabled() {
|
||||
List<String> args = EksClusterManager.buildServerArgs(false, true, null, null);
|
||||
|
||||
assertTrue(args.contains("--disable=traefik"));
|
||||
assertFalse(args.contains("--disable=local-storage"));
|
||||
assertTrue(args.contains("--tls-san=localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void serverArgsDisableLocalStorageWhenDefaultStorageClassDisabled() {
|
||||
List<String> args = EksClusterManager.buildServerArgs(false, false, null, null);
|
||||
|
||||
assertTrue(args.contains("--disable=traefik"));
|
||||
assertTrue(args.contains("--disable=local-storage"));
|
||||
assertTrue(args.contains("--tls-san=localhost"));
|
||||
}
|
||||
|
||||
@@ -329,7 +349,8 @@ class EksClusterManagerTest {
|
||||
"io.floci.resource-id", "my-cluster",
|
||||
"io.floci.account", "000000000000",
|
||||
"io.floci.region", "us-east-1",
|
||||
"io.floci.eks.node-capacity", "m5.large:unbounded"));
|
||||
"io.floci.eks.node-capacity", "m5.large:unbounded",
|
||||
"io.floci.eks.default-storage-class", "false"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -364,6 +385,43 @@ class EksClusterManagerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void startClusterDefaultStorageClassFlag(boolean defaultStorageClass) {
|
||||
EmulatorConfig config = Mockito.mock(EmulatorConfig.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
when(config.services().eks().defaultImage()).thenReturn("rancher/k3s:v1.30.0-k3s1");
|
||||
when(config.services().eks().defaultStorageClass()).thenReturn(defaultStorageClass);
|
||||
|
||||
ContainerLifecycleManager lifecycleManager = Mockito.mock(ContainerLifecycleManager.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
when(lifecycleManager.create(any())).thenReturn("container-id");
|
||||
|
||||
ContainerBuilder containerBuilder = Mockito.mock(ContainerBuilder.class);
|
||||
ContainerBuilder.Builder builder = Mockito.mock(ContainerBuilder.Builder.class, Mockito.RETURNS_SELF);
|
||||
when(containerBuilder.newContainer(anyString())).thenReturn(builder);
|
||||
when(builder.build()).thenReturn(Mockito.mock(ContainerSpec.class));
|
||||
|
||||
EksClusterManager manager = new EksClusterManager(containerBuilder, lifecycleManager,
|
||||
Mockito.mock(ContainerDetector.class), Mockito.mock(PortAllocator.class),
|
||||
Mockito.mock(DockerHostResolver.class), Mockito.mock(EcrRegistryManager.class),
|
||||
config, new RegionResolver("us-east-1", "000000000000"));
|
||||
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName("my-cluster");
|
||||
|
||||
manager.startCluster(cluster);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<List<String>> cmdCaptor = ArgumentCaptor.forClass(List.class);
|
||||
verify(builder).withCmd(cmdCaptor.capture());
|
||||
List<String> cmd = cmdCaptor.getValue();
|
||||
|
||||
if (defaultStorageClass) {
|
||||
assertFalse(cmd.contains("--disable=local-storage"));
|
||||
} else {
|
||||
assertTrue(cmd.contains("--disable=local-storage"));
|
||||
}
|
||||
}
|
||||
|
||||
/** Re-latching persisted clusters after a Floci/Docker restart (#2609), without a Docker daemon. */
|
||||
@Nested
|
||||
class RestoreCluster {
|
||||
@@ -461,6 +519,35 @@ class EksClusterManagerTest {
|
||||
verify(lifecycleManager, never()).create(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void restoreClusterPreservesPreUpgradeLocalStorageWhenContainerSurvives() {
|
||||
when(lifecycleManager.findByName("floci-eks-demo"))
|
||||
.thenReturn(Optional.of(survivingContainer("cid-pre-upgrade")));
|
||||
when(lifecycleManager.adopt("cid-pre-upgrade", List.of(6443)))
|
||||
.thenReturn(new ContainerInfo("cid-pre-upgrade", Map.of(), Map.of(6443, 6512)));
|
||||
|
||||
Cluster cluster = cluster();
|
||||
manager.restoreCluster(cluster);
|
||||
|
||||
assertEquals(Boolean.TRUE, cluster.getDefaultStorageClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void restoreClusterPreservesDefaultStorageClassLabelFromSurvivingContainer() {
|
||||
Container container = containerFromJson("{\"Id\":\"cid-new\","
|
||||
+ "\"Labels\":{\"io.floci.eks.node-capacity\":\"m5.large:unbounded\","
|
||||
+ "\"io.floci.eks.default-storage-class\":\"false\"}}");
|
||||
when(lifecycleManager.findByName("floci-eks-demo"))
|
||||
.thenReturn(Optional.of(container));
|
||||
when(lifecycleManager.adopt("cid-new", List.of(6443)))
|
||||
.thenReturn(new ContainerInfo("cid-new", Map.of(), Map.of(6443, 6512)));
|
||||
|
||||
Cluster cluster = cluster();
|
||||
manager.restoreCluster(cluster);
|
||||
|
||||
assertEquals(Boolean.FALSE, cluster.getDefaultStorageClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void recreatesAnOldSurvivorWithoutCapacityLimits() {
|
||||
when(lifecycleManager.findByName("floci-eks-demo"))
|
||||
@@ -2542,6 +2629,7 @@ class EksClusterManagerTest {
|
||||
List<String> args = EksClusterManager.buildServerArgs(false, "172.20.0.0/16", "10.44.0.0/16");
|
||||
assertTrue(args.contains("--service-cidr=172.20.0.0/16"));
|
||||
assertTrue(args.contains("--cluster-cidr=10.44.0.0/16"));
|
||||
assertTrue(args.contains("--disable=local-storage"));
|
||||
assertFalse(args.contains("--flannel-backend=none"));
|
||||
}
|
||||
|
||||
@@ -2551,6 +2639,7 @@ class EksClusterManagerTest {
|
||||
assertTrue(args.contains("--flannel-backend=none"));
|
||||
assertTrue(args.contains("--disable-network-policy"));
|
||||
assertTrue(args.contains("--disable-kube-proxy"));
|
||||
assertTrue(args.contains("--disable=local-storage"));
|
||||
assertTrue(args.contains("--service-cidr=10.100.0.0/16"));
|
||||
assertTrue(args.contains("--cluster-cidr=10.42.0.0/16"));
|
||||
}
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
package io.github.hectorvent.floci.services.eks;
|
||||
|
||||
import com.github.dockerjava.api.DockerClient;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerExec;
|
||||
import io.github.hectorvent.floci.services.eks.model.Cluster;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Docker integration test verifying that freshly created clusters start with no StorageClass,
|
||||
* no bundled local-path provisioner, and that CoreDNS remains functional.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(EksStorageClassDockerIntegrationTest.Profile.class)
|
||||
class EksStorageClassDockerIntegrationTest {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(EksStorageClassDockerIntegrationTest.class);
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
|
||||
public static final class Profile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of(
|
||||
"floci.services.eks.mock", "false"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
DockerClient dockerClient;
|
||||
|
||||
@Inject
|
||||
EksClusterManager eksClusterManager;
|
||||
|
||||
private Cluster cluster;
|
||||
|
||||
@BeforeEach
|
||||
void requireDocker() {
|
||||
boolean dockerAvailable = isDockerAvailable();
|
||||
if (!dockerAvailable) {
|
||||
LOG.warn("Docker daemon is not available; skipping EksStorageClassDockerIntegrationTest");
|
||||
}
|
||||
Assumptions.assumeTrue(dockerAvailable, "Docker daemon must be available for EKS storage class integration test");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
if (cluster != null) {
|
||||
try {
|
||||
eksClusterManager.stopCluster(cluster);
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Failed to stop test cluster: {0}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterStartsWithoutStorageClassAndCoreDnsRemainsAvailable() throws Exception {
|
||||
String suffix = UUID.randomUUID().toString().substring(0, 8);
|
||||
String clusterName = "sc-dock-" + suffix;
|
||||
|
||||
cluster = new Cluster();
|
||||
cluster.setName(clusterName);
|
||||
cluster.setAccountId(ACCOUNT);
|
||||
cluster.setArn("arn:aws:eks:us-east-1:" + ACCOUNT + ":cluster/" + clusterName);
|
||||
cluster.setCreatedAt(Instant.now());
|
||||
cluster.setRoleArn("arn:aws:iam::" + ACCOUNT + ":role/eks-service-role");
|
||||
|
||||
eksClusterManager.startCluster(cluster);
|
||||
assertNotNull(cluster.getContainerId(), "Container ID must not be null");
|
||||
|
||||
// Wait for k3s API server readiness (up to 60s)
|
||||
long deadline = System.currentTimeMillis() + 60000;
|
||||
boolean ready = false;
|
||||
while (System.currentTimeMillis() < deadline) {
|
||||
if (eksClusterManager.isReady(cluster)) {
|
||||
ready = true;
|
||||
break;
|
||||
}
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
assertTrue(ready, "k3s API server must become ready within 60 seconds");
|
||||
eksClusterManager.finalizeCluster(cluster);
|
||||
|
||||
String containerId = cluster.getContainerId();
|
||||
|
||||
// 1. Verify CoreDNS deployment is present and healthy in kube-system
|
||||
long corednsDeadline = System.currentTimeMillis() + 60000;
|
||||
boolean corednsRolledOut = false;
|
||||
while (System.currentTimeMillis() < corednsDeadline) {
|
||||
ContainerExec.Result rolloutResult = execInContainerWithExitCode(containerId,
|
||||
new String[]{"kubectl", "rollout", "status", "deployment/coredns", "-n", "kube-system", "--timeout=10s"});
|
||||
if (rolloutResult.exitCode() == 0) {
|
||||
corednsRolledOut = true;
|
||||
break;
|
||||
}
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
assertTrue(corednsRolledOut, "CoreDNS deployment must be successfully rolled out");
|
||||
|
||||
// 2. Verify CoreDNS pods are running and ready
|
||||
ContainerExec.Result podsResult = execInContainerWithExitCode(containerId,
|
||||
new String[]{"kubectl", "get", "pods", "-n", "kube-system", "-l", "k8s-app=kube-dns",
|
||||
"-o", "jsonpath={.items[*].status.phase}"});
|
||||
assertEquals(0, podsResult.exitCode(), "kubectl get pods failed: " + podsResult.stderr());
|
||||
assertTrue(podsResult.stdout().contains("Running"),
|
||||
"CoreDNS pod must be in Running phase, but got: " + podsResult.stdout());
|
||||
|
||||
// 3. Verify no StorageClass exists in the cluster after manifests settle
|
||||
ContainerExec.Result scResult = execInContainerWithExitCode(containerId,
|
||||
new String[]{"kubectl", "get", "storageclass", "-o", "jsonpath={.items[*].metadata.name}"});
|
||||
assertEquals(0, scResult.exitCode(), "kubectl get storageclass failed: " + scResult.stderr());
|
||||
assertTrue(scResult.stdout().trim().isEmpty(),
|
||||
"No StorageClass should exist in newly created cluster, but found: " + scResult.stdout());
|
||||
|
||||
// 4. Explicitly verify local-path StorageClass is absent
|
||||
ContainerExec.Result localPathResult = execInContainerWithExitCode(containerId,
|
||||
new String[]{"kubectl", "get", "storageclass", "local-path"});
|
||||
assertNotEquals(0, localPathResult.exitCode(), "local-path StorageClass must not exist");
|
||||
}
|
||||
|
||||
private boolean isDockerAvailable() {
|
||||
try {
|
||||
dockerClient.pingCmd().exec();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private ContainerExec.Result execInContainerWithExitCode(String containerId, String[] cmd) {
|
||||
return ContainerExec.run(dockerClient, containerId, cmd, 30).throwIfTimedOut(containerId);
|
||||
}
|
||||
}
|
||||
@@ -339,6 +339,7 @@ floci:
|
||||
max-memory-mib: 0
|
||||
max-vcpus: 0
|
||||
ecr-registry-mirror: true
|
||||
default-storage-class: false
|
||||
imds: false
|
||||
irsa-signing-key: true
|
||||
embedded-dns: true
|
||||
|
||||
Reference in new issue
Block a user