From 79a955a226ce88f068efcb660d9d8fcc83d67129 Mon Sep 17 00:00:00 2001 From: Mike Metral <1112768+metral@users.noreply.github.com> Date: Wed, 27 Mar 2019 23:22:26 -0700 Subject: [PATCH] fix(getAmi): allow setting master version & explicitly filter Linux AMIs fixes https://github.com/pulumi/pulumi-eks/issues/84 --- CHANGELOG.md | 5 ++++ nodejs/eks/cluster.ts | 7 ++++++ nodejs/eks/nodegroup.ts | 51 ++++++++++++++++++++++++++++++++++------- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f97f3e7f..ce2fcff8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ - feat(workers): add 'nodeAssociatePublicIpAddress' to toggle public IPs [#81](https://github.com/pulumi/pulumi-eks/pull/81) +- fix(getAmi): allow setting master version & explicitly filter Linux AMIs + [#85](https://github.com/pulumi/pulumi-eks/pull/85) + - Fix a bug where the wrong AMI was being returned due to a loosely defined + regex. + - Add support for setting the master / control plane version of the cluster. ## 0.17.2 (Release March 19, 2019) diff --git a/nodejs/eks/cluster.ts b/nodejs/eks/cluster.ts index e98c6f11..1e656aa1 100644 --- a/nodejs/eks/cluster.ts +++ b/nodejs/eks/cluster.ts @@ -126,6 +126,7 @@ export function createCore(name: string, args: ClusterOptions, parent: pulumi.Co const eksCluster = new aws.eks.Cluster(`${name}-eksCluster`, { roleArn: eksRole.role.apply(r => r.arn), vpcConfig: { securityGroupIds: [ eksClusterSecurityGroup.id ], subnetIds: subnetIds }, + version: args.version, }, { parent: parent }); // Compute the required kubeconfig. Note that we do not export this value: we want the exported config to @@ -393,6 +394,11 @@ export interface ClusterOptions { * Defaults to `true`. */ deployDashboard?: boolean; + + /** + * Desired Kubernetes master / control plane version. If you do not specify a value, the latest available version is used. + */ + version?: pulumi.Input; } /** @@ -512,6 +518,7 @@ export class Cluster extends pulumi.ComponentResource { maxSize: args.maxSize, desiredCapacity: args.desiredCapacity, amiId: args.nodeAmiId, + version: args.version, }, this, core.provider); this.nodeSecurityGroup = this.defaultNodeGroup.nodeSecurityGroup; configDeps.push(this.defaultNodeGroup.cfnStack.id); diff --git a/nodejs/eks/nodegroup.ts b/nodejs/eks/nodegroup.ts index 0b1a91aa..46ff535a 100644 --- a/nodejs/eks/nodegroup.ts +++ b/nodejs/eks/nodegroup.ts @@ -131,6 +131,11 @@ export interface NodeGroupBaseOptions { * public IPs. */ nodeAssociatePublicIpAddress?: boolean; + + /** + * Desired Kubernetes master / control plane version. If you do not specify a value, the latest available version is used. + */ + version?: pulumi.Input; } /** @@ -310,17 +315,47 @@ ${customUserData} `; }); - let amiId: pulumi.Input = args.amiId!; + let amiId: any = args.amiId!; + const version: pulumi.Input = args.version!; if (args.amiId === undefined) { - const eksWorkerAmi = aws.getAmi({ - filters: [{ - name: "name", - values: [ "amazon-eks-node-*" ], - }], - mostRecent: true, + const filters: { name: string; values: string[]}[] = [ + { + name: "description", + values: [ "*linux*", "*Linux*" ], + }, + { + name: "description", + values: [ "*k8s*/bin/linux/amd64*"], + }, + ]; + + if (version !== undefined) { + filters.push( + { + name: "name", + values: [ "amazon-eks-node-" + version + "*" ], + }, + ); + } else { + filters.push( + { + name: "name", + values: [ "amazon-eks-node-*" ], + }, + ); + } + + const eksWorkerAmiIds = aws.getAmiIds({ + filters, owners: [ "602401143452" ], // Amazon + sortAscending: true, }, { parent: parent }); - amiId = eksWorkerAmi.then(r => r.imageId); + + const bestAmiId = eksWorkerAmiIds.then(r => r.ids.pop()); + if (!bestAmiId) { + throw new Error("No Linux AMI Id was found."); + } + amiId = bestAmiId; } // Enable auto-assignment of public IP addresses on worker nodes for