mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -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
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user