mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(eks): label a node group's nodes with its recommended AMI, not its releaseVersion (#9144)
This commit is contained in:
1 parent
6de2461693
commit
7706e5705d
4 files changed
+58
-13
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package io.floci.aws.services.eks;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2ImageCatalog;
|
||||
import io.floci.aws.services.ec2.Ec2ImageCatalog.CatalogImage;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
@@ -48,12 +49,21 @@ public final class EksAmiReleaseVersions {
|
||||
* value SSM publishes for it, or empty when the catalog has no such AMI.
|
||||
*/
|
||||
public static Optional<String> recommended(Ec2ImageCatalog catalog, String kubernetesVersion, String amiType) {
|
||||
String amiPath = RECOMMENDED_AMI_PATHS.get(amiType);
|
||||
return recommendedImage(catalog, kubernetesVersion, amiType)
|
||||
.map(image -> of(kubernetesVersion, image.creationDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* The recommended EKS optimized AMI for a node group's Kubernetes version and AMI type, the
|
||||
* image SSM publishes under its {@code recommended/image_id}, or empty when the catalog has none.
|
||||
*/
|
||||
public static Optional<CatalogImage> recommendedImage(Ec2ImageCatalog catalog, String kubernetesVersion,
|
||||
String amiType) {
|
||||
String amiPath = amiType == null ? null : RECOMMENDED_AMI_PATHS.get(amiType);
|
||||
if (catalog == null || amiPath == null || !supports(kubernetesVersion)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return catalog.findByPublicParameterName(OPTIMIZED_AMI_PARAMETER_PREFIX + kubernetesVersion + "/" + amiPath
|
||||
+ "/recommended/image_id")
|
||||
.map(image -> of(kubernetesVersion, image.creationDate));
|
||||
+ "/recommended/image_id");
|
||||
}
|
||||
}
|
||||
@@ -3313,7 +3313,7 @@ public class EksClusterManager
|
||||
labels.put("eks.amazonaws.com/nodegroup", nodegroup.getNodegroupName()); // partition-literal: Kubernetes node label key is partition-invariant
|
||||
}
|
||||
|
||||
String imageId = resolveNodegroupImageId(nodegroup);
|
||||
String imageId = resolveNodegroupImageId(nodegroup, region);
|
||||
if (imageId != null && !imageId.isBlank()) {
|
||||
labels.put("eks.amazonaws.com/nodegroup-image", imageId); // partition-literal: Kubernetes node label key is partition-invariant
|
||||
}
|
||||
@@ -3363,11 +3363,8 @@ public class EksClusterManager
|
||||
return nodeInstanceType(cluster);
|
||||
}
|
||||
|
||||
private String resolveNodegroupImageId(Nodegroup nodegroup) {
|
||||
private String resolveNodegroupImageId(Nodegroup nodegroup, String region) {
|
||||
if (nodegroup != null) {
|
||||
if (nodegroup.getReleaseVersion() != null && !nodegroup.getReleaseVersion().isBlank()) {
|
||||
return nodegroup.getReleaseVersion().trim();
|
||||
}
|
||||
if (nodegroup.getLaunchTemplate() instanceof Map<?, ?> map) {
|
||||
Object directImage = map.get("imageId");
|
||||
if (directImage != null && !directImage.toString().isBlank()) {
|
||||
@@ -3380,7 +3377,7 @@ public class EksClusterManager
|
||||
String version = map.get("version") != null ? map.get("version").toString().trim() : null;
|
||||
if ((id != null && !id.isBlank()) || (name != null && !name.isBlank())) {
|
||||
try {
|
||||
LaunchTemplateData data = ec2.resolveLaunchTemplateData(null, id, name, version);
|
||||
LaunchTemplateData data = ec2.resolveLaunchTemplateData(region, id, name, version);
|
||||
if (data != null && data.getImageId() != null && !data.getImageId().isBlank()) {
|
||||
return data.getImageId().trim();
|
||||
}
|
||||
@@ -3390,6 +3387,9 @@ public class EksClusterManager
|
||||
}
|
||||
}
|
||||
}
|
||||
// The release version names the AMI's release, not the AMI: the label carries the recommended AMI's id.
|
||||
return EksAmiReleaseVersions.recommendedImage(imageCatalog, nodegroup.getVersion(), nodegroup.getAmiType())
|
||||
.map(image -> image.imageId).orElse("ami-eks-k3s");
|
||||
}
|
||||
return "ami-eks-k3s";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user