mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(emr): give back a cluster's Kerberos realm, OS release, root volume, placement groups and logging settings (#9183)
RunJobFlow dropped the cluster's KerberosAttributes, OSReleaseLabel, EbsRootVolumeIops, EbsRootVolumeThroughput, PlacementGroupConfigs, LogEncryptionKmsKeyId, RepoUpgradeOnBoot and MonitoringConfiguration, so DescribeCluster gave back none of them. - DescribeCluster gives each back as it was asked for, the placement group configs as its PlacementGroups. - OSReleaseLabel is the one asked for, else the latest Amazon Linux release DescribeReleaseLabel lists for the cluster's release, as "If no Amazon Linux release was specified, the default Amazon Linux release is shown in the response". - RepoUpgradeOnBoot is SECURITY for a cluster with a custom AMI that names none, as "If omitted, the default is SECURITY". - Of KerberosAttributes only the Realm is kept and given back, never a password, and a cluster without them answers an empty structure, as AWS does. - A member the model requires, or a value outside its enum, is refused with the framework's ValidationException. So are two placement groups for one instance role, and one for the primary nodes of a cluster without three of them (three on-demand and no spot for a fleet), in the words AWS answers them with. - As only the primary nodes take a placement group, with SPREAD or NONE, another role or strategy is refused, in Floci's words, and a group without a strategy gets SPREAD, as the Management Guide says. - AWS::EMR::Cluster passes these properties to RunJobFlow rather than warning that they are not stored.
This commit is contained in:
1 parent
eb6998ed2e
commit
a9bea6567c
10 files changed
+415
-19
No files matched your search
+23
@@ -214,6 +214,29 @@ class EmrCfnProvisionerTest {
|
||||
assertNotNull(r.getAttributes().get(EmrCfnProvisioner.CLUSTER_SHAPE_ATTR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theClustersOwnSettingsReachRunJobFlowAsTheTemplateGivesThem() {
|
||||
when(handler.clusterFrom(any(), any())).thenReturn(new EmrCluster());
|
||||
when(emr.runJobFlow(any(), eq("us-east-1"))).thenReturn(emrCluster(CLUSTER_ID, "STARTING"));
|
||||
when(emr.describeCluster(CLUSTER_ID)).thenReturn(emrCluster(CLUSTER_ID, "WAITING"));
|
||||
String settings = """
|
||||
, "KerberosAttributes": {"Realm": "EC2.INTERNAL", "KdcAdminPassword": "kdc-secret"},
|
||||
"OSReleaseLabel": "2.0.20260727.0", "EbsRootVolumeIops": 4000, "EbsRootVolumeThroughput": 250,
|
||||
"PlacementGroupConfigs": [{"InstanceRole": "MASTER", "PlacementStrategy": "SPREAD"}],
|
||||
"LogEncryptionKmsKeyId": "key-logs",
|
||||
"MonitoringConfiguration": {"CloudWatchLogConfiguration": {"Enabled": true}}""";
|
||||
JsonNode template = json(clusterProps(2, "m5.xlarge", settings));
|
||||
provisioner.provision(cluster(null), template, ctx(null, null));
|
||||
|
||||
ArgumentCaptor<JsonNode> request = ArgumentCaptor.forClass(JsonNode.class);
|
||||
verify(handler).clusterFrom(request.capture(), eq("us-east-1"));
|
||||
for (String name : List.of("KerberosAttributes", "OSReleaseLabel", "EbsRootVolumeIops",
|
||||
"EbsRootVolumeThroughput", "PlacementGroupConfigs", "LogEncryptionKmsKeyId",
|
||||
"MonitoringConfiguration")) {
|
||||
assertEquals(template.get(name), request.getValue().get(name), name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClusterThatTerminatesBeforeItIsReadyFailsTheCreateAndIsTerminatedAgain() {
|
||||
when(handler.clusterFrom(any(), any())).thenReturn(new EmrCluster());
|
||||
|
||||
@@ -17,8 +17,10 @@ import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.floci.aws.testing.EmrRequests.emr;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
@@ -735,4 +737,120 @@ class EmrIntegrationTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void describeClusterGivesBackTheClustersOwnSettingsAndOnlyTheRealmOfItsKerberosAttributes() {
|
||||
String osRelease = emr("DescribeReleaseLabel", "{\"ReleaseLabel\":\"emr-7.13.0\"}").then().statusCode(200)
|
||||
.extract().path("AvailableOSReleases[0].Label");
|
||||
String masterGroups = """
|
||||
"InstanceGroups": [
|
||||
{"InstanceRole": "MASTER", "InstanceType": "m5.xlarge", "InstanceCount": 3},
|
||||
{"InstanceRole": "CORE", "InstanceType": "m5.xlarge", "InstanceCount": 1}]""";
|
||||
List<String> launched = new ArrayList<>();
|
||||
try {
|
||||
String set = emr("RunJobFlow", """
|
||||
{"Name": "settings-set", "ReleaseLabel": "emr-7.13.0", "CustomAmiId": "ami-0abc",
|
||||
"EbsRootVolumeIops": 4000, "EbsRootVolumeThroughput": 250,
|
||||
"LogEncryptionKmsKeyId": "arn:aws:kms:us-east-1:000000000000:key/logs",
|
||||
"KerberosAttributes": {"Realm": "EC2.INTERNAL", "KdcAdminPassword": "kdc-secret",
|
||||
"CrossRealmTrustPrincipalPassword": "cross-secret"},
|
||||
"PlacementGroupConfigs": [{"InstanceRole": "MASTER"}],
|
||||
"MonitoringConfiguration": {
|
||||
"CloudWatchLogConfiguration": {"Enabled": true, "LogGroupName": "/emr/logs",
|
||||
"LogTypes": {"STEP_LOGS": ["STDOUT"]}},
|
||||
"S3LoggingConfiguration": {"LogTypeUploadPolicy": {"system-logs": "emr-managed"}}},
|
||||
"Instances": {"KeepJobFlowAliveWhenNoSteps": true, %s}}
|
||||
""".formatted(masterGroups)).then().statusCode(200).extract().path("JobFlowId");
|
||||
launched.add(set);
|
||||
String unset = emr("RunJobFlow", """
|
||||
{"Name": "settings-unset", "ReleaseLabel": "emr-7.13.0", "OSReleaseLabel": "2.0.20260727.0",
|
||||
"Instances": {"KeepJobFlowAliveWhenNoSteps": true}}
|
||||
""").then().statusCode(200).extract().path("JobFlowId");
|
||||
launched.add(unset);
|
||||
|
||||
emr("DescribeCluster", "{\"ClusterId\":\"" + set + "\"}").then().statusCode(200)
|
||||
.body("Cluster.EbsRootVolumeIops", equalTo(4000))
|
||||
.body("Cluster.EbsRootVolumeThroughput", equalTo(250))
|
||||
.body("Cluster.LogEncryptionKmsKeyId", equalTo("arn:aws:kms:us-east-1:000000000000:key/logs"))
|
||||
.body("Cluster.OSReleaseLabel", equalTo(osRelease))
|
||||
.body("Cluster.RepoUpgradeOnBoot", equalTo("SECURITY"))
|
||||
.body("Cluster.KerberosAttributes", equalTo(Map.of("Realm", "EC2.INTERNAL")))
|
||||
.body("Cluster.PlacementGroups",
|
||||
equalTo(List.of(Map.of("InstanceRole", "MASTER", "PlacementStrategy", "SPREAD"))))
|
||||
.body("Cluster.MonitoringConfiguration.CloudWatchLogConfiguration.LogGroupName",
|
||||
equalTo("/emr/logs"))
|
||||
.body("Cluster.MonitoringConfiguration.S3LoggingConfiguration.LogTypeUploadPolicy",
|
||||
equalTo(Map.of("system-logs", "emr-managed")))
|
||||
.body(not(containsString("kdc-secret")))
|
||||
.body(not(containsString("cross-secret")));
|
||||
emr("DescribeCluster", "{\"ClusterId\":\"" + unset + "\"}").then().statusCode(200)
|
||||
.body("Cluster.OSReleaseLabel", equalTo("2.0.20260727.0"))
|
||||
.body("Cluster.KerberosAttributes", equalTo(Map.of()))
|
||||
.body("Cluster", not(hasKey("RepoUpgradeOnBoot")))
|
||||
.body("Cluster", not(hasKey("PlacementGroups")))
|
||||
.body("Cluster", not(hasKey("EbsRootVolumeIops")));
|
||||
} finally {
|
||||
if (!launched.isEmpty()) {
|
||||
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + String.join("\",\"", launched) + "\"]}")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
String refused = "{\"Name\": \"settings-refused\", \"Instances\": {\"KeepJobFlowAliveWhenNoSteps\": true%s}%s}";
|
||||
emr("RunJobFlow", refused.formatted("", ", \"KerberosAttributes\": {\"Realm\": \"EC2.INTERNAL\"}"))
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", containsString("'kerberosAttributes.kdcAdminPassword'"))
|
||||
.body("message", not(containsString("EC2.INTERNAL")));
|
||||
emr("RunJobFlow", refused.formatted("", ", \"RepoUpgradeOnBoot\": \"ALL\""))
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", containsString("'repoUpgradeOnBoot'"));
|
||||
emr("RunJobFlow", refused.formatted("", ", \"MonitoringConfiguration\": "
|
||||
+ "{\"CloudWatchLogConfiguration\": {\"LogGroupName\": \"/emr/logs\"}}"))
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", containsString("'monitoringConfiguration.cloudWatchLogConfiguration.enabled'"));
|
||||
emr("RunJobFlow", refused.formatted(", " + masterGroups, ", \"PlacementGroupConfigs\": ["
|
||||
+ "{\"InstanceRole\": \"MASTER\", \"PlacementStrategy\": \"SPREAD\"},"
|
||||
+ "{\"InstanceRole\": \"MASTER\", \"PlacementStrategy\": \"SPREAD\"}]"))
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo("Placement group supports single placement strategy for an instance role. "
|
||||
+ "Found multiple strategy for the following instance role: MASTER"));
|
||||
emr("RunJobFlow", refused.formatted(", " + masterGroups, ", \"PlacementGroupConfigs\": ["
|
||||
+ "{\"InstanceRole\": \"CORE\", \"PlacementStrategy\": \"SPREAD\"}]"))
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message",
|
||||
equalTo("Placement groups are supported only for the MASTER instance role, not CORE."));
|
||||
emr("RunJobFlow", refused.formatted(", " + masterGroups, ", \"PlacementGroupConfigs\": ["
|
||||
+ "{\"InstanceRole\": \"MASTER\", \"PlacementStrategy\": \"PARTITION\"}]"))
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo("The MASTER instance role supports only the SPREAD or NONE placement "
|
||||
+ "strategy, not PARTITION."));
|
||||
String primaryPlacement = ", \"PlacementGroupConfigs\": [{\"InstanceRole\": \"MASTER\"}]";
|
||||
String singleMaster = "Placement group support for master node is available only for multi-master cluster "
|
||||
+ "and not for single-master cluster.";
|
||||
emr("RunJobFlow", refused.formatted("", primaryPlacement))
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo(singleMaster));
|
||||
emr("RunJobFlow", refused.formatted(", " + masterGroups.replace("\"InstanceCount\": 3", "\"InstanceCount\": 4"),
|
||||
primaryPlacement))
|
||||
.then().statusCode(400)
|
||||
.body("message", equalTo(singleMaster));
|
||||
emr("RunJobFlow", refused.formatted(", \"InstanceFleets\": [{\"InstanceFleetType\": \"MASTER\", "
|
||||
+ "\"TargetOnDemandCapacity\": 1, \"TargetSpotCapacity\": 2, "
|
||||
+ "\"InstanceTypeConfigs\": [{\"InstanceType\": \"m5.xlarge\"}]}]", primaryPlacement))
|
||||
.then().statusCode(400)
|
||||
.body("message", equalTo(singleMaster));
|
||||
emr("RunJobFlow", refused.formatted("", ", \"EbsRootVolumeIops\": \"fast\""))
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"));
|
||||
emr("ListClusters", "{}").then().statusCode(200)
|
||||
.body("Clusters.findAll { it.Name == 'settings-refused' }", hasSize(0));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user