mirror of
https://github.com/floci-io/floci.git
synced 2026-12-03 02:07:58 -05:00
fix(eks): mirror the cluster's own region and account in the registry config (#5399)
The k3s registries.yaml listed the default account across the regions of the deployment's partition, so a cluster in another account, or in a region of another partition served by the same process, could not pull from Floci's ECR through its own repository hostnames. Build the mirror from the cluster's account (then the default account) across every region of the cluster's partition. A commercial cluster in the default account gets the same file as before.
This commit is contained in:
1 parent
3ff5529fad
commit
8b83892dff
3 files changed
+144
-27
No files matched your search
@@ -225,6 +225,52 @@ class EksClusterManagerTest {
|
||||
assertEquals(2L * (AwsRegions.advertised("aws").size() + 1), endpoints);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registriesYamlForACommercialClusterInTheDefaultAccountIsUnchanged() {
|
||||
String yaml = EksClusterManager.buildRegistriesYaml(
|
||||
EksClusterManager.mirrorAccounts("000000000000", "000000000000"),
|
||||
EksClusterManager.mirrorRegions("us-east-1"), 4566, "http://floci:4566", false);
|
||||
|
||||
assertEquals(EksClusterManager.buildRegistriesYaml(
|
||||
"000000000000", AwsRegions.advertised("aws"), 4566, "http://floci:4566"), yaml);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registriesYamlForAChinaClusterMirrorsTheChinaRegions() {
|
||||
String yaml = EksClusterManager.buildRegistriesYaml(
|
||||
EksClusterManager.mirrorAccounts("000000000000", "000000000000"),
|
||||
EksClusterManager.mirrorRegions("cn-north-1"), 4566, "http://floci:4566", false);
|
||||
|
||||
for (String region : AwsRegions.advertised("aws-cn")) {
|
||||
assertTrue(yaml.contains("\"000000000000.dkr.ecr." + region + ".localhost:4566\":"), region);
|
||||
}
|
||||
assertTrue(yaml.contains("\"000000000000.dkr.ecr.cn-north-1.localhost:4566\":"));
|
||||
assertFalse(yaml.contains(".us-east-1."));
|
||||
assertFalse(yaml.contains("amazonaws"), "repository URIs are Floci's localhost hosts in every partition");
|
||||
assertEquals(AwsRegions.advertised("aws-cn").size() + 1,
|
||||
yaml.lines().filter(line -> line.contains("- \"http://floci:4566\"")).count());
|
||||
}
|
||||
|
||||
@Test
|
||||
void registriesYamlForANonDefaultAccountMirrorsBothAccounts() {
|
||||
String yaml = EksClusterManager.buildRegistriesYaml(
|
||||
EksClusterManager.mirrorAccounts("111122223333", "000000000000"),
|
||||
List.of("eu-central-1"), 4566, "http://floci:4566", false);
|
||||
|
||||
assertEquals("""
|
||||
mirrors:
|
||||
"111122223333.dkr.ecr.eu-central-1.localhost:4566":
|
||||
endpoint:
|
||||
- "http://floci:4566"
|
||||
"000000000000.dkr.ecr.eu-central-1.localhost:4566":
|
||||
endpoint:
|
||||
- "http://floci:4566"
|
||||
"localhost:4566":
|
||||
endpoint:
|
||||
- "http://floci:4566"
|
||||
""", yaml);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registriesYamlKeepsTheExistingOutputWhenTlsUrisAreDisabled() {
|
||||
String yaml = EksClusterManager.buildRegistriesYaml(
|
||||
@@ -1082,9 +1128,53 @@ class EksClusterManagerTest {
|
||||
Mockito.mock(RegionResolver.class));
|
||||
}
|
||||
|
||||
private Cluster demoCluster() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName("demo");
|
||||
return cluster;
|
||||
}
|
||||
|
||||
private Cluster clusterWithArn(String arn) {
|
||||
Cluster cluster = demoCluster();
|
||||
cluster.setArn(arn);
|
||||
return cluster;
|
||||
}
|
||||
|
||||
@Test
|
||||
void aDefaultCommercialClusterKeepsTheDeploymentWideMirror() throws Exception {
|
||||
manager.injectEcrRegistryMirror("container-1",
|
||||
clusterWithArn("arn:aws:eks:us-east-1:000000000000:cluster/demo"));
|
||||
|
||||
assertEquals(EksClusterManager.buildRegistriesYaml("000000000000", AwsRegions.advertised("aws"),
|
||||
4566, "http://floci:4566"), Files.readString(tempDir.resolve("registries/demo/registries.yaml")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aChinaClusterInACommercialDeploymentMirrorsItsOwnPartitionsRegions() throws Exception {
|
||||
manager.injectEcrRegistryMirror("container-1",
|
||||
clusterWithArn("arn:aws-cn:eks:cn-north-1:000000000000:cluster/demo"));
|
||||
|
||||
String yaml = Files.readString(tempDir.resolve("registries/demo/registries.yaml"));
|
||||
assertTrue(yaml.contains("\"000000000000.dkr.ecr.cn-north-1.localhost:4566\":"));
|
||||
assertTrue(yaml.contains("\"000000000000.dkr.ecr.cn-northwest-1.localhost:4566\":"));
|
||||
assertFalse(yaml.contains(".us-east-1."), "a China cluster pulls from China regions only");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClusterInAnotherAccountMirrorsItsOwnAccountAndTheDefaultOne() throws Exception {
|
||||
Cluster cluster = clusterWithArn("arn:aws:eks:eu-west-1:111122223333:cluster/demo");
|
||||
cluster.setAccountId("111122223333");
|
||||
|
||||
manager.injectEcrRegistryMirror("container-1", cluster);
|
||||
|
||||
String yaml = Files.readString(tempDir.resolve("registries/demo/registries.yaml"));
|
||||
assertTrue(yaml.contains("\"111122223333.dkr.ecr.eu-west-1.localhost:4566\":"));
|
||||
assertTrue(yaml.contains("\"000000000000.dkr.ecr.eu-west-1.localhost:4566\":"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void injectsTheMirrorIntoTheContainer() throws Exception {
|
||||
manager.injectEcrRegistryMirror("container-1", "demo");
|
||||
manager.injectEcrRegistryMirror("container-1", demoCluster());
|
||||
|
||||
verify(registryManager).ensureStarted();
|
||||
verify(copyCmd).withRemotePath("/etc");
|
||||
@@ -1100,7 +1190,7 @@ class EksClusterManagerTest {
|
||||
// k3s still reaches Floci on its own port inside the Docker network.
|
||||
when(registryManager.advertisedPort()).thenReturn(54321);
|
||||
|
||||
manager.injectEcrRegistryMirror("container-1", "demo");
|
||||
manager.injectEcrRegistryMirror("container-1", demoCluster());
|
||||
|
||||
String yaml = Files.readString(tempDir.resolve("registries/demo/registries.yaml"));
|
||||
assertTrue(yaml.contains("\"000000000000.dkr.ecr.us-east-1.localhost:54321\":"));
|
||||
@@ -1117,7 +1207,7 @@ class EksClusterManagerTest {
|
||||
when(tls.enabled()).thenReturn(true);
|
||||
when(ecr.tlsUri()).thenReturn(true);
|
||||
|
||||
manager.injectEcrRegistryMirror("container-1", "demo");
|
||||
manager.injectEcrRegistryMirror("container-1", demoCluster());
|
||||
|
||||
String yaml = Files.readString(tempDir.resolve("registries/demo/registries.yaml"));
|
||||
assertTrue(yaml.contains("\"000000000000.dkr.ecr.us-east-1.localhost.floci.io:4566\":"));
|
||||
@@ -1133,7 +1223,7 @@ class EksClusterManagerTest {
|
||||
when(config.tls()).thenReturn(tls);
|
||||
when(ecr.tlsUri()).thenReturn(true);
|
||||
|
||||
manager.injectEcrRegistryMirror("container-1", "demo");
|
||||
manager.injectEcrRegistryMirror("container-1", demoCluster());
|
||||
|
||||
String yaml = Files.readString(tempDir.resolve("registries/demo/registries.yaml"));
|
||||
assertFalse(yaml.contains("localhost.floci.io"));
|
||||
@@ -1145,7 +1235,7 @@ class EksClusterManagerTest {
|
||||
void skipsWhenTheKnobIsOff() {
|
||||
when(eks.ecrRegistryMirror()).thenReturn(false);
|
||||
|
||||
manager.injectEcrRegistryMirror("container-1", "demo");
|
||||
manager.injectEcrRegistryMirror("container-1", demoCluster());
|
||||
|
||||
verifyNoInteractions(registryManager);
|
||||
verify(lifecycleManager, never()).getDockerClient();
|
||||
@@ -1155,7 +1245,7 @@ class EksClusterManagerTest {
|
||||
void skipsWhenEcrIsDisabled() {
|
||||
when(ecr.enabled()).thenReturn(false);
|
||||
|
||||
manager.injectEcrRegistryMirror("container-1", "demo");
|
||||
manager.injectEcrRegistryMirror("container-1", demoCluster());
|
||||
|
||||
verifyNoInteractions(registryManager);
|
||||
verify(lifecycleManager, never()).getDockerClient();
|
||||
@@ -1165,7 +1255,7 @@ class EksClusterManagerTest {
|
||||
void registryStartupFailureSkipsTheMirrorWithoutAborting() {
|
||||
Mockito.doThrow(new RuntimeException("no docker")).when(registryManager).ensureStarted();
|
||||
|
||||
manager.injectEcrRegistryMirror("container-1", "demo");
|
||||
manager.injectEcrRegistryMirror("container-1", demoCluster());
|
||||
|
||||
verify(lifecycleManager, never()).getDockerClient();
|
||||
}
|
||||
@@ -1174,7 +1264,7 @@ class EksClusterManagerTest {
|
||||
void copyFailureDoesNotAbortClusterCreation() {
|
||||
when(copyCmd.exec()).thenThrow(new RuntimeException("copy failed"));
|
||||
|
||||
manager.injectEcrRegistryMirror("container-1", "demo");
|
||||
manager.injectEcrRegistryMirror("container-1", demoCluster());
|
||||
|
||||
verify(copyCmd).exec();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user