mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(eks): validate the node group launchTemplate against EC2 on CreateNodegroup (#4148)
Validate node group launchTemplate specifications against EC2 during CreateNodegroup. Reject requests where neither or both of id and name are supplied, or where the referenced launch template or version does not resolve in EC2, with InvalidParameterException (400). Resolve launch templates and construct nodegroup ARNs using the cluster's region rather than the default region.
This commit is contained in:
1 parent
8f2706a903
commit
90d8c355d9
4 files changed
+254
-8
No files matched your search
@@ -627,7 +627,9 @@ public class EksService implements TagHandler, ResourceProvider {
|
||||
"Nodegroup already exists: " + nodegroupName, 409);
|
||||
}
|
||||
|
||||
String region = config.defaultRegion();
|
||||
String region = resolveClusterRegion(cluster);
|
||||
validateLaunchTemplate(region, request.getLaunchTemplate());
|
||||
|
||||
String accountId = regionResolver.getAccountId();
|
||||
String id = UUID.randomUUID().toString();
|
||||
String arn = AwsArnUtils.Arn.of("eks", region, accountId,
|
||||
@@ -670,6 +672,43 @@ public class EksService implements TagHandler, ResourceProvider {
|
||||
return nodeGroup;
|
||||
}
|
||||
|
||||
private void validateLaunchTemplate(String region, Object launchTemplateObj) {
|
||||
if (!(launchTemplateObj instanceof Map<?, ?> map)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String id = asNonBlankString(map.get("id"));
|
||||
String name = asNonBlankString(map.get("name"));
|
||||
String version = asNonBlankString(map.get("version"));
|
||||
|
||||
if ((id != null && name != null) || (id == null && name == null)) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"You must specify either the launch template ID or the launch template name in the request, but not both.",
|
||||
400);
|
||||
}
|
||||
|
||||
try {
|
||||
ec2Service.resolveLaunchTemplateData(region, id, name, version);
|
||||
} catch (AwsException e) {
|
||||
switch (e.getErrorCode()) {
|
||||
case "InvalidLaunchTemplateId.NotFound", "InvalidLaunchTemplateName.NotFoundException" ->
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Launch template could not be found : " + e.getMessage(), 400);
|
||||
case "InvalidLaunchTemplateVersion.NotFound", "InvalidLaunchTemplateVersion.Malformed" ->
|
||||
throw new AwsException("InvalidParameterException", e.getMessage(), 400);
|
||||
default -> throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String asNonBlankString(Object val) {
|
||||
if (val == null) {
|
||||
return null;
|
||||
}
|
||||
String s = val.toString().trim();
|
||||
return s.isEmpty() ? null : s;
|
||||
}
|
||||
|
||||
public Nodegroup describeNodeGroup(String clusterName, String nodegroupName) {
|
||||
describeCluster(clusterName);
|
||||
return nodeGroupStorage.get(nodeGroupKey(clusterName, nodegroupName))
|
||||
|
||||
Reference in new issue
Block a user