-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathnodegroup.ts
2496 lines (2253 loc) · 93.4 KB
/
nodegroup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2016-2022, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import * as aws from "@pulumi/aws";
import * as awsInputs from "@pulumi/aws/types/input";
import * as pulumi from "@pulumi/pulumi";
import * as netmask from "netmask";
import {
AmiType,
CpuArchitecture,
getAmiMetadata,
getAmiType,
getOperatingSystem,
OperatingSystem,
toAmiType,
} from "./ami";
import { supportsAccessEntries } from "./authenticationMode";
import { Cluster, ClusterInternal, CoreData } from "./cluster";
import randomSuffix from "./randomSuffix";
import { createNodeGroupSecurityGroup } from "./securitygroup";
import { InputTags } from "./utils";
import {
createUserData,
customUserDataArgs,
ManagedNodeUserDataArgs,
requiresCustomUserData,
SelfManagedV1NodeUserDataArgs,
SelfManagedV2NodeUserDataArgs,
} from "./userdata";
import { InstanceProfile } from "@pulumi/aws/iam";
export type TaintEffect = "NoSchedule" | "NoExecute" | "PreferNoSchedule";
/**
* Taint represents a Kubernetes `taint` to apply to all Nodes in a NodeGroup. See
* https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/.
*/
export interface Taint {
/**
* The value of the taint.
*/
value: pulumi.Input<string>;
/**
* The effect of the taint.
*/
effect: pulumi.Input<TaintEffect>;
}
/**
* MIME document parts for nodeadm configuration. This can be shell scripts, nodeadm configuration or any other user data compatible script.
*
* See for more details: https://awslabs.github.io/amazon-eks-ami/nodeadm/.
*/
export type NodeadmOptions = {
content: pulumi.Input<string>;
contentType: pulumi.Input<string>;
};
/**
* NodeGroupArgs represents the common configuration settings for NodeGroups.
*/
export interface NodeGroupBaseOptions {
/**
* The set of subnets to override and use for the worker node group.
*
* Setting this option overrides which subnets to use for the worker node
* group, regardless if the cluster's `subnetIds` is set, or if
* `publicSubnetIds` and/or `privateSubnetIds` were set.
*/
nodeSubnetIds?: pulumi.Input<pulumi.Input<string>[]>;
/**
* The instance type to use for the cluster's nodes. Defaults to "t3.medium".
*/
instanceType?: pulumi.Input<string | aws.ec2.InstanceType>;
/**
* Bidding price for spot instance. If set, only spot instances will be added as worker node
*/
spotPrice?: pulumi.Input<string>;
/**
* The security group for the worker node group to communicate with the cluster.
*
* This security group requires specific inbound and outbound rules.
*
* See for more details:
* https://docs.aws.amazon.com/eks/latest/userguide/sec-group-reqs.html
*
* Note: The `nodeSecurityGroup` option and the cluster option
* `nodeSecurityGroupTags` are mutually exclusive.
*/
nodeSecurityGroup?: aws.ec2.SecurityGroup;
nodeSecurityGroupId?: pulumi.Input<string>;
/**
* The ingress rule that gives node group access.
*/
clusterIngressRule?: aws.ec2.SecurityGroupRule;
clusterIngressRuleId?: pulumi.Input<string>;
/**
* Extra security groups to attach on all nodes in this worker node group.
*
* This additional set of security groups captures any user application rules
* that will be needed for the nodes.
*/
extraNodeSecurityGroups?: aws.ec2.SecurityGroup[];
/**
* Public key material for SSH access to worker nodes. See allowed formats at:
* https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html
* If not provided, no SSH access is enabled on VMs.
*/
nodePublicKey?: pulumi.Input<string>;
/**
* Name of the key pair to use for SSH access to worker nodes.
*/
keyName?: pulumi.Input<string>;
/**
* The size in GiB of a cluster node's root volume. Defaults to 20.
*/
nodeRootVolumeSize?: pulumi.Input<number>;
/**
* Whether to delete a cluster node's root volume on termination. Defaults to true.
*/
nodeRootVolumeDeleteOnTermination?: pulumi.Input<boolean>;
/**
* Whether to encrypt a cluster node's root volume. Defaults to false.
*/
nodeRootVolumeEncrypted?: pulumi.Input<boolean>;
/**
* Provisioned IOPS for a cluster node's root volume.
* Only valid for io1 volumes.
*/
nodeRootVolumeIops?: pulumi.Input<number> | undefined;
/**
* Provisioned throughput performance in integer MiB/s for a cluster node's root volume.
* Only valid for gp3 volumes.
*/
nodeRootVolumeThroughput?: pulumi.Input<number> | undefined;
/**
* Configured EBS type for a cluster node's root volume. Default is gp2.
*/
nodeRootVolumeType?: "standard" | "gp2" | "gp3" | "st1" | "sc1" | "io1";
/**
* Extra code to run on node startup. This code will run after the AWS EKS bootstrapping code and before the node
* signals its readiness to the managing CloudFormation stack. This code must be a typical user data script:
* critically it must begin with an interpreter directive (i.e. a `#!`).
*/
nodeUserData?: pulumi.Input<string>;
/**
* User specified code to run on node startup. This code is expected to
* handle the full AWS EKS bootstrapping code and signal node readiness
* to the managing CloudFormation stack. This code must be a complete
* and executable user data script in bash (Linux) or powershell (Windows).
*
* See for more details: https://docs.aws.amazon.com/eks/latest/userguide/worker.html
*/
nodeUserDataOverride?: pulumi.Input<string>;
/**
* The number of worker nodes that should be running in the cluster. Defaults to 2.
*/
desiredCapacity?: pulumi.Input<number>;
/**
* The minimum number of worker nodes running in the cluster. Defaults to 1.
*/
minSize?: pulumi.Input<number>;
/**
* The maximum number of worker nodes running in the cluster. Defaults to 2.
*/
maxSize?: pulumi.Input<number>;
/**
* The AMI type for the instance.
*
* If you are passing an amiId that is `arm64` type, then we need to ensure
* that this value is set as `amazon-linux-2-arm64`.
*
* Note: `amiType` and `gpu` are mutually exclusive.
*/
amiType?: pulumi.Input<string>;
/**
* The AMI ID to use for the worker nodes.
*
* Defaults to the latest recommended EKS Optimized Linux AMI from the
* AWS Systems Manager Parameter Store.
*
* Note: `amiId` and `gpu` are mutually exclusive.
*
* See for more details:
* - https://docs.aws.amazon.com/eks/latest/userguide/eks-optimized-ami.html.
*/
amiId?: pulumi.Input<string>;
/**
* Use the latest recommended EKS Optimized Linux AMI with GPU support for
* the worker nodes from the AWS Systems Manager Parameter Store.
*
* Defaults to false.
*
* Note: `gpu` and `amiId` are mutually exclusive.
*
* See for more details:
* - https://docs.aws.amazon.com/eks/latest/userguide/eks-optimized-ami.html.
* - https://docs.aws.amazon.com/eks/latest/userguide/retrieve-ami-id.html
*/
gpu?: pulumi.Input<boolean>;
/**
* Custom k8s node labels to be attached to each worker node. Adds the given key/value pairs to the `--node-labels`
* kubelet argument.
*/
labels?: pulumi.Input<{ [key: string]: pulumi.Input<string> }>;
/**
* Custom k8s node taints to be attached to each worker node. Adds the given taints to the `--register-with-taints`
* kubelet argument.
*/
taints?: pulumi.Input<{ [key: string]: pulumi.Input<Taint> }>;
/**
* Extra args to pass to the Kubelet. Corresponds to the options passed in the `--kubeletExtraArgs` flag to
* `/etc/eks/bootstrap.sh`. For example, '--port=10251 --address=0.0.0.0'. Note that the `labels` and `taints`
* properties will be applied to this list (using `--node-labels` and `--register-with-taints` respectively) after
* to the expicit `kubeletExtraArgs`.
*/
kubeletExtraArgs?: pulumi.Input<string>;
/**
* Additional args to pass directly to `/etc/eks/bootstrap.sh`. For details on available options, see:
* https://github.com/awslabs/amazon-eks-ami/blob/master/files/bootstrap.sh. Note that the `--apiserver-endpoint`,
* `--b64-cluster-ca` and `--kubelet-extra-args` flags are included automatically based on other configuration
* parameters.
*/
bootstrapExtraArgs?: pulumi.Input<string>;
/**
* Whether or not to auto-assign public IP addresses on the EKS worker nodes.
* If this toggle is set to true, the EKS workers will be
* auto-assigned public IPs. If false, they will not be auto-assigned
* public IPs.
*/
nodeAssociatePublicIpAddress?: pulumi.Input<boolean>;
/**
* Desired Kubernetes master / control plane version. If you do not specify a value, the latest available version is used.
*/
version?: pulumi.Input<string>;
/**
* The instance profile to use for this node group. Note, the role for the instance profile
* must be supplied in the ClusterOptions as either: 'instanceRole', or as a role of 'instanceRoles'.
*/
instanceProfile?: aws.iam.InstanceProfile;
instanceProfileName?: pulumi.Input<string>;
/**
* The tags to apply to the NodeGroup's AutoScalingGroup in the
* CloudFormation Stack.
*
* Per AWS, all stack-level tags, including automatically created tags, and
* the `cloudFormationTags` option are propagated to resources that AWS
* CloudFormation supports, including the AutoScalingGroup. See
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html
*
* Note: Given the inheritance of auto-generated CF tags and
* `cloudFormationTags`, you should either supply the tag in
* `autoScalingGroupTags` or `cloudFormationTags`, but not both.
*/
autoScalingGroupTags?: InputTags;
/**
* The tags to apply to the CloudFormation Stack of the Worker NodeGroup.
*
* Note: Given the inheritance of auto-generated CF tags and
* `cloudFormationTags`, you should either supply the tag in
* `autoScalingGroupTags` or `cloudFormationTags`, but not both.
*/
cloudFormationTags?: InputTags;
/**
* Enables/disables detailed monitoring of the EC2 instances.
*
* With detailed monitoring, all metrics, including status check metrics, are available in 1-minute intervals.
* When enabled, you can also get aggregated data across groups of similar instances.
*
* Note: You are charged per metric that is sent to CloudWatch. You are not charged for data storage.
* For more information, see "Paid tier" and "Example 1 - EC2 Detailed Monitoring" here https://aws.amazon.com/cloudwatch/pricing/.
*/
enableDetailedMonitoring?: pulumi.Input<boolean>;
/**
* The type of OS to use for the node group. Will be used to determine the right EKS optimized AMI to use based on the
* instance types and gpu configuration.
*
* Defaults to `AL2`.
*/
operatingSystem?: pulumi.Input<OperatingSystem>;
/**
* The configuration settings for Bottlerocket OS.
* The settings will get merged with the base settings the provider uses to configure Bottlerocket.
* This includes:
* - settings.kubernetes.api-server
* - settings.kubernetes.cluster-certificate
* - settings.kubernetes.cluster-name
* - settings.kubernetes.cluster-dns-ip
*
* For an overview of the available settings, see https://bottlerocket.dev/en/os/1.20.x/api/settings/.
*/
bottlerocketSettings?: pulumi.Input<object>;
/**
* Extra nodeadm configuration sections to be added to the nodeadm user data.
* This can be shell scripts, nodeadm NodeConfig or any other user data compatible script.
* When configuring additional nodeadm NodeConfig sections, they'll be merged with the base settings the provider sets.
* You can overwrite base settings or provide additional settings this way.
*
* The base settings are:
* - cluster.name
* - cluster.apiServerEndpoint
* - cluster.certificateAuthority
* - cluster.cidr
*
* Note: This is only applicable when using AL2023.
* See for more details:
* - [Amazon EKS AMI - Nodeadm](https://awslabs.github.io/amazon-eks-ami/nodeadm/).
* - [Amazon EKS AMI - Nodeadm Configuration](https://awslabs.github.io/amazon-eks-ami/nodeadm/doc/api/).
*/
nodeadmExtraOptions?: pulumi.Input<pulumi.Input<NodeadmOptions>[]>;
}
/**
* NodeGroupOptions describes the configuration options accepted by a NodeGroup component.
*/
export interface NodeGroupOptions extends NodeGroupBaseOptions {
/**
* The target EKS cluster.
*/
cluster: Cluster | CoreData;
}
/**
* NodeGroupV2Options describes the configuration options accepted by a NodeGroupV2 component.
*/
export interface NodeGroupV2Options extends NodeGroupOptions {
/**
* The minimum amount of instances that should remain available during an instance refresh,
* expressed as a percentage.
*
* Defaults to 50.
*/
minRefreshPercentage?: pulumi.Input<number>;
launchTemplateTagSpecifications?: pulumi.Input<
pulumi.Input<awsInputs.ec2.LaunchTemplateTagSpecification>[]
>;
/**
* Metadata options passed to EC2 instances
*/
metadataOptions?: pulumi.Input<awsInputs.ec2.InstanceMetadataOptions>;
/**
* The instance warmup is the time period, in seconds, from when a new instance's state changes to InService to
* when it can receive traffic. During an instance refresh, Amazon EC2 Auto Scaling does not immediately move on
* to the next replacement after determining that a newly launched instance is healthy. It waits for the warm-up
* period that you specified before it moves on to replacing other instances. This can be helpful when your
* application takes time to initialize itself before it starts to serve traffic.
*/
defaultInstanceWarmup?: pulumi.Input<number>;
/**
* Whether to ignore changes to the desired size of the AutoScalingGroup. This is useful when using Cluster Autoscaler.
*
* See EKS best practices for more details: https://aws.github.io/aws-eks-best-practices/cluster-autoscaling/
*/
ignoreScalingChanges?: boolean;
}
/**
* NodeGroupData describes the resources created for the given NodeGroup.
*/
export interface NodeGroupData {
/**
* The security group for the node group to communicate with the cluster.
*/
nodeSecurityGroup: aws.ec2.SecurityGroup | undefined;
nodeSecurityGroupId: pulumi.Output<string>;
/**
* The CloudFormation Stack which defines the node group's AutoScalingGroup.
*/
cfnStack: aws.cloudformation.Stack;
/**
* The AutoScalingGroup name for the node group.
*/
autoScalingGroupName: pulumi.Output<string>;
/**
* The additional security groups for the node group that captures user-specific rules.
*/
extraNodeSecurityGroups?: aws.ec2.SecurityGroup[];
}
export interface NodeGroupV2Data {
/**
* The security group for the node group to communicate with the cluster.
*/
nodeSecurityGroup: aws.ec2.SecurityGroup | undefined;
nodeSecurityGroupId: pulumi.Output<string>;
/**
* The AutoScalingGroup name for the node group.
*/
autoScalingGroup: aws.autoscaling.Group;
/**
* The additional security groups for the node group that captures user-specific rules.
*/
extraNodeSecurityGroups?: aws.ec2.SecurityGroup[];
}
/**
* NodeGroup is a component that wraps the AWS EC2 instances that provide compute capacity for an EKS cluster.
*/
export class NodeGroup extends pulumi.ComponentResource implements NodeGroupData {
/**
* The security group for the node group to communicate with the cluster.
*/
public readonly nodeSecurityGroup: aws.ec2.SecurityGroup | undefined;
public readonly nodeSecurityGroupId: pulumi.Output<string>;
/**
* The additional security groups for the node group that captures user-specific rules.
*/
public readonly extraNodeSecurityGroups: aws.ec2.SecurityGroup[];
/**
* The CloudFormation Stack which defines the Node AutoScalingGroup.
*/
cfnStack: aws.cloudformation.Stack;
/**
* The AutoScalingGroup name for the Node group.
*/
autoScalingGroupName: pulumi.Output<string>;
/**
* Create a new EKS cluster with worker nodes, optional storage classes, and deploy the Kubernetes Dashboard if
* requested.
*
* @param name The _unique_ name of this component.
* @param args The arguments for this cluster.
* @param opts A bag of options that control this component's behavior.
*/
constructor(name: string, args: NodeGroupOptions, opts?: pulumi.ComponentResourceOptions) {
super("eks:index:NodeGroup", name, args, opts);
const group = createNodeGroup(name, args, this, opts?.provider);
this.nodeSecurityGroup = group.nodeSecurityGroup;
this.nodeSecurityGroupId = group.nodeSecurityGroupId;
this.cfnStack = group.cfnStack;
this.autoScalingGroupName = group.autoScalingGroupName;
this.registerOutputs(undefined);
}
}
/**
* This is a variant of `NodeGroup` that is used for the MLC `NodeGroup`. We don't just use `NodeGroup`,
* because we need to accept `ClusterInternal` as the `cluster` arg, so we can correctly pull out `cluster.core`
* for use in creating the `NodeGroup`.
*
* @internal
*/
export class NodeGroupInternal extends pulumi.ComponentResource {
public readonly autoScalingGroupName!: pulumi.Output<string>;
public readonly cfnStack!: pulumi.Output<aws.cloudformation.Stack>;
public readonly extraNodeSecurityGroups!: pulumi.Output<aws.ec2.SecurityGroup[]>;
public readonly nodeSecurityGroup!: pulumi.Output<aws.ec2.SecurityGroup | undefined>;
public readonly nodeSecurityGroupId!: pulumi.Output<string>;
constructor(name: string, args: NodeGroupInternalArgs, opts?: pulumi.ComponentResourceOptions) {
const type = "eks:index:NodeGroup";
if (opts?.urn) {
const props = {
autoScalingGroupName: undefined,
cfnStack: undefined,
extraNodeSecurityGroups: undefined,
nodeSecurityGroup: undefined,
nodeSecurityGroupId: undefined,
};
super(type, name, props, opts);
return;
}
super(type, name, args, opts);
const core = pulumi
.output(args.cluster)
.apply((c) => (c instanceof ClusterInternal ? c.core : c)) as pulumi.Output<
pulumi.Unwrap<CoreData>
>;
const group = createNodeGroupInternal(name, args, core, this, opts?.provider);
this.autoScalingGroupName = group.autoScalingGroupName;
this.cfnStack = pulumi.output(group.cfnStack);
this.extraNodeSecurityGroups = pulumi.output(group.extraNodeSecurityGroups ?? []);
this.nodeSecurityGroup = pulumi.output(group.nodeSecurityGroup);
this.nodeSecurityGroupId = pulumi.output(group.nodeSecurityGroupId);
this.registerOutputs({
autoScalingGroupName: this.autoScalingGroupName,
cfnStack: this.cfnStack,
extraNodeSecurityGroups: this.extraNodeSecurityGroups,
nodeSecurityGroup: this.nodeSecurityGroup,
nodeSecurityGroupId: this.nodeSecurityGroupId,
});
}
}
/** @internal */
export type NodeGroupInternalArgs = Omit<NodeGroupOptions, "cluster"> & {
cluster: pulumi.Input<ClusterInternal | pulumi.Unwrap<CoreData>>;
};
export class NodeGroupV2 extends pulumi.ComponentResource implements NodeGroupV2Data {
/**
* The security group for the node group to communicate with the cluster.
*/
public readonly nodeSecurityGroup: aws.ec2.SecurityGroup | undefined;
public readonly nodeSecurityGroupId: pulumi.Output<string>;
/**
* The additional security groups for the node group that captures user-specific rules.
*/
public readonly extraNodeSecurityGroups: aws.ec2.SecurityGroup[];
/**
* The AutoScalingGroup name for the Node group.
*/
autoScalingGroup: aws.autoscaling.Group;
/**
* Create a new EKS cluster with worker nodes, optional storage classes, and deploy the Kubernetes Dashboard if
* requested.
*
* @param name The _unique_ name of this component.
* @param args The arguments for this cluster.
* @param opts A bag of options that control this component's behavior.
*/
constructor(name: string, args: NodeGroupV2Options, opts?: pulumi.ComponentResourceOptions) {
super("eks:index:NodeGroupV2", name, args, opts);
const group = createNodeGroupV2(name, args, this, opts?.provider);
this.nodeSecurityGroup = group.nodeSecurityGroup;
this.nodeSecurityGroupId = group.nodeSecurityGroupId;
this.autoScalingGroup = group.autoScalingGroup;
this.registerOutputs(undefined);
}
}
/**
* This is a variant of `NodeGroupV2` that is used for the MLC `NodeGroupV2`. We don't just use `NodeGroupV2`,
* because we need to accept `ClusterInternal` as the `cluster` arg, so we can correctly pull out `cluster.core`
* for use in creating the `NodeGroupV2`.
*
* @internal
*/
export class NodeGroupV2Internal extends pulumi.ComponentResource {
public readonly autoScalingGroup!: pulumi.Output<aws.autoscaling.Group>;
public readonly extraNodeSecurityGroups!: pulumi.Output<aws.ec2.SecurityGroup[]>;
public readonly nodeSecurityGroup!: pulumi.Output<aws.ec2.SecurityGroup | undefined>;
public readonly nodeSecurityGroupId!: pulumi.Output<string>;
constructor(
name: string,
args: NodeGroupV2InternalArgs,
opts?: pulumi.ComponentResourceOptions,
) {
const type = "eks:index:NodeGroupV2";
if (opts?.urn) {
const props = {
autoScalingGroup: undefined,
extraNodeSecurityGroups: undefined,
nodeSecurityGroup: undefined,
nodeSecurityGroupId: undefined,
};
super(type, name, props, opts);
return;
}
super(type, name, args, opts);
const core = pulumi
.output(args.cluster)
.apply((c) => (c instanceof ClusterInternal ? c.core : c)) as pulumi.Output<
pulumi.Unwrap<CoreData>
>;
const group = createNodeGroupV2Internal(name, args, core, this, opts?.provider);
this.autoScalingGroup = pulumi.output(group.autoScalingGroup);
this.extraNodeSecurityGroups = pulumi.output(group.extraNodeSecurityGroups ?? []);
this.nodeSecurityGroup = pulumi.output(group.nodeSecurityGroup);
this.nodeSecurityGroupId = pulumi.output(group.nodeSecurityGroupId);
this.registerOutputs({
autoScalingGroup: this.autoScalingGroup,
extraNodeSecurityGroups: this.extraNodeSecurityGroups,
nodeSecurityGroup: this.nodeSecurityGroup,
nodeSecurityGroupId: this.nodeSecurityGroupId,
});
}
}
/** @internal */
export type NodeGroupV2InternalArgs = Omit<NodeGroupV2Options, "cluster"> & {
cluster: pulumi.Input<ClusterInternal | pulumi.Unwrap<CoreData>>;
};
/**
* Create a self-managed node group using CloudFormation and an ASG.
*
* See for more details:
* https://docs.aws.amazon.com/eks/latest/userguide/worker.html
*/
export function createNodeGroup(
name: string,
args: NodeGroupOptions,
parent: pulumi.ComponentResource,
provider?: pulumi.ProviderResource,
): NodeGroupData {
const core = args.cluster instanceof Cluster ? args.cluster.core : args.cluster;
return createNodeGroupInternal(name, args, pulumi.output(core), parent, provider);
}
export function resolveInstanceProfileName(
name: string,
args: Omit<NodeGroupOptions, "cluster">,
c: pulumi.UnwrappedObject<CoreData>,
parent: pulumi.ComponentResource,
): pulumi.Output<string> {
if (
(args.instanceProfile || c.nodeGroupOptions.instanceProfile) &&
(args.instanceProfileName || c.nodeGroupOptions.instanceProfileName)
) {
throw new pulumi.ResourceError(
`invalid args for node group ${name}, instanceProfile and instanceProfileName are mutually exclusive`,
parent,
);
}
if (args.instanceProfile) {
return args.instanceProfile.name;
} else if (args.instanceProfileName) {
return pulumi.output(args.instanceProfileName);
} else if (c.nodeGroupOptions.instanceProfile) {
return c.nodeGroupOptions.instanceProfile.name;
} else if (c.nodeGroupOptions.instanceProfileName) {
return pulumi.output(c.nodeGroupOptions.instanceProfileName!);
} else {
throw new pulumi.ResourceError(
`an instanceProfile or instanceProfileName is required`,
parent,
);
}
}
function createNodeGroupInternal(
name: string,
args: Omit<NodeGroupOptions, "cluster">,
core: pulumi.Output<pulumi.Unwrap<CoreData>>,
parent: pulumi.ComponentResource,
provider?: pulumi.ProviderResource,
): NodeGroupData {
const instanceProfileName = core.apply((c) =>
resolveInstanceProfileName(name, args, c, parent),
);
if (args.clusterIngressRule && args.clusterIngressRuleId) {
throw new pulumi.ResourceError(
`invalid args for node group ${name}, clusterIngressRule and clusterIngressRuleId are mutually exclusive`,
parent,
);
}
if (args.nodeSecurityGroup && args.nodeSecurityGroupId) {
throw new pulumi.ResourceError(
`invalid args for node group ${name}, nodeSecurityGroup and nodeSecurityGroupId are mutually exclusive`,
parent,
);
}
const coreSecurityGroupId = core.nodeGroupOptions.nodeSecurityGroup?.apply((sg) => sg?.id);
pulumi
.all([
coreSecurityGroupId,
args.nodeSecurityGroup?.id ?? args.nodeSecurityGroupId,
core.nodeSecurityGroupTags,
])
.apply(([coreSecurityGroup, nodeSecurityGroup, sgTags]) => {
if (coreSecurityGroup && nodeSecurityGroup) {
if (sgTags && coreSecurityGroup !== nodeSecurityGroup) {
throw new pulumi.ResourceError(
`The NodeGroup's nodeSecurityGroup and the cluster option nodeSecurityGroupTags are mutually exclusive. Choose a single approach`,
parent,
);
}
}
});
if (args.nodePublicKey && args.keyName) {
throw new pulumi.ResourceError(
"nodePublicKey and keyName are mutually exclusive. Choose a single approach",
parent,
);
}
if (args.amiId && args.gpu) {
throw new pulumi.ResourceError("amiId and gpu are mutually exclusive.", parent);
}
if (
args.nodeUserDataOverride &&
(args.nodeUserData ||
args.labels ||
args.taints ||
args.kubeletExtraArgs ||
args.bootstrapExtraArgs)
) {
throw new pulumi.ResourceError(
"nodeUserDataOverride and any combination of {nodeUserData, labels, taints, kubeletExtraArgs, or bootstrapExtraArgs} is mutually exclusive.",
parent,
);
}
let nodeSecurityGroupId: pulumi.Output<string>;
let nodeSecurityGroup: aws.ec2.SecurityGroup | undefined;
const eksCluster = core.cluster;
const cfnStackDeps = core.apply((c) => {
const result: pulumi.Resource[] = [];
if (c.vpcCni !== undefined) {
result.push(c.vpcCni);
}
if (c.eksNodeAccess !== undefined) {
result.push(c.eksNodeAccess);
}
return result;
});
let eksClusterIngressRuleId: pulumi.Output<string>;
if (args.nodeSecurityGroup || args.nodeSecurityGroupId) {
if (args.clusterIngressRule === undefined && args.clusterIngressRuleId === undefined) {
throw new pulumi.ResourceError(
`invalid args for node group ${name}, clusterIngressRule or clusterIngressRuleId is required when nodeSecurityGroup is manually specified`,
parent,
);
}
nodeSecurityGroup = args.nodeSecurityGroup;
nodeSecurityGroupId =
args.nodeSecurityGroup?.id ?? pulumi.output(args.nodeSecurityGroupId!);
eksClusterIngressRuleId =
args.clusterIngressRule?.id ?? pulumi.output(args.clusterIngressRuleId!);
} else {
const [nodeSg, eksClusterIngressRule] = createNodeGroupSecurityGroup(
name,
{
vpcId: core.vpcId,
clusterSecurityGroupId: pulumi
.output(core.clusterSecurityGroup)
.apply((sg) => sg?.id ?? core.cluster.vpcConfig.clusterSecurityGroupId),
eksCluster: eksCluster,
tags: pulumi.all([core.tags, core.nodeSecurityGroupTags]).apply(
([tags, nodeSecurityGroupTags]) =>
<aws.Tags>{
...nodeSecurityGroupTags,
...tags,
},
),
},
parent,
);
nodeSecurityGroup = nodeSg;
nodeSecurityGroupId = nodeSecurityGroup.id;
eksClusterIngressRuleId = eksClusterIngressRule.id;
}
// Collect the IDs of any extra, user-specific security groups.
const extraSGOutput = pulumi.output(args.extraNodeSecurityGroups);
const extraNodeSecurityGroupIds = pulumi.all([extraSGOutput]).apply(([sg]) => {
if (sg === undefined) {
return [];
}
// Map out the ARNs of all of the instanceRoles.
return sg.map((sg) => sg.id);
});
// If requested, add a new EC2 KeyPair for SSH access to the instances.
let keyName = args.keyName;
if (args.nodePublicKey) {
const key = new aws.ec2.KeyPair(
`${name}-keyPair`,
{
publicKey: args.nodePublicKey,
},
{ parent, provider },
);
keyName = key.keyName;
}
const cfnStackName = randomSuffix(`${name}-cfnStackName`, name, { parent });
const awsRegion = pulumi.output(aws.getRegion({}, { parent, async: true }));
const os = pulumi
.all([args.amiType, args.operatingSystem])
.apply(([amiType, operatingSystem]) => {
return getOperatingSystem(amiType, operatingSystem, parent);
});
const serviceCidr = getClusterServiceCidr(core.cluster.kubernetesNetworkConfig);
const clusterMetadata = {
name: eksCluster.name,
apiServerEndpoint: eksCluster.endpoint,
certificateAuthority: eksCluster.certificateAuthority.data,
serviceCidr,
};
const nodeadmExtraOptions = pulumi
.output(args.nodeadmExtraOptions)
.apply((nodeadmExtraOptions) => {
return nodeadmExtraOptions ? pulumi.all(nodeadmExtraOptions) : undefined;
});
const nodegroupInputs = {
nodeUserData: args.nodeUserData,
nodeUserDataOverride: args.nodeUserDataOverride,
bottlerocketSettings: args.bottlerocketSettings,
kubeletExtraArgs: args.kubeletExtraArgs,
bootstrapExtraArgs: args.bootstrapExtraArgs,
labels: args.labels,
taints: args.taints,
};
const userdata = pulumi
.all([awsRegion, clusterMetadata, cfnStackName, os, nodeadmExtraOptions, nodegroupInputs])
.apply(([region, clusterMetadata, stackName, os, nodeadmExtraOptions, nodegroupInputs]) => {
const userDataArgs: SelfManagedV1NodeUserDataArgs = {
...nodegroupInputs,
nodeGroupType: "self-managed-v1",
awsRegion: region.name,
stackName,
nodeadmExtraOptions,
extraUserData: nodegroupInputs.nodeUserData,
userDataOverride: nodegroupInputs.nodeUserDataOverride,
};
return createUserData(os, clusterMetadata, userDataArgs, parent);
});
const version = pulumi.output(args.version || core.cluster.version);
const amiId: pulumi.Input<string> = args.amiId || getRecommendedAMI(args, version, parent);
// Enable auto-assignment of public IP addresses on worker nodes for
// backwards compatibility on existing EKS clusters launched with it
// enabled. Defaults to `true`.
const nodeAssociatePublicIpAddress = args.nodeAssociatePublicIpAddress ?? true;
const numeric = new RegExp("^\\d+$");
// We need to wrap the validation in a pulumi.all as MLCs could supply pulumi.Output<T> or T.
pulumi
.all([args.nodeRootVolumeIops, args.nodeRootVolumeType, args.nodeRootVolumeThroughput])
.apply(([nodeRootVolumeIops, nodeRootVolumeType, nodeRootVolumeThroughput]) => {
if (nodeRootVolumeIops && nodeRootVolumeType !== "io1") {
throw new pulumi.ResourceError(
"Cannot create a cluster node root volume of non-io1 type with provisioned IOPS (nodeRootVolumeIops).",
parent,
);
}
if (nodeRootVolumeType === "io1" && nodeRootVolumeIops) {
if (!numeric.test(nodeRootVolumeIops?.toString())) {
throw new pulumi.ResourceError(
"Cannot create a cluster node root volume of io1 type without provisioned IOPS (nodeRootVolumeIops) as integer value.",
parent,
);
}
}
if (nodeRootVolumeThroughput && nodeRootVolumeType !== "gp3") {
throw new pulumi.ResourceError(
"Cannot create a cluster node root volume of non-gp3 type with provisioned throughput (nodeRootVolumeThroughput).",
parent,
);
}
if (nodeRootVolumeType === "gp3" && nodeRootVolumeThroughput) {
if (!numeric.test(nodeRootVolumeThroughput?.toString())) {
throw new pulumi.ResourceError(
"Cannot create a cluster node root volume of gp3 type without provisioned throughput (nodeRootVolumeThroughput) as integer value.",
parent,
);
}
}
});
const amiInfo = pulumi.output(amiId).apply((id) =>
aws.ec2.getAmi(
{
owners: ["self", "amazon"],
filters: [
{
name: "image-id",
values: [id],
},
],
},
{ parent },
),
);
const { rootBlockDevice, ebsBlockDevices } = pulumi
.all([os, amiInfo])
.apply(([os, amiInfo]) => {
if (os === OperatingSystem.AL2) {
// Old behavior to stay backwards compatible
return {
rootBlockDevice: {
encrypted: args.nodeRootVolumeEncrypted ?? false,
volumeSize: args.nodeRootVolumeSize ?? 20, // GiB
volumeType: args.nodeRootVolumeType ?? "gp2",
iops: args.nodeRootVolumeIops,
throughput: args.nodeRootVolumeThroughput,
deleteOnTermination: args.nodeRootVolumeDeleteOnTermination ?? true,
},
ebsBlockDevices: [],
};
} else if (os !== OperatingSystem.Bottlerocket) {
// New behavior, do not overwrite default values of the AMI
return {
rootBlockDevice: {
encrypted: args.nodeRootVolumeEncrypted,
volumeSize: args.nodeRootVolumeSize,
volumeType: args.nodeRootVolumeType,
iops: args.nodeRootVolumeIops,
throughput: args.nodeRootVolumeThroughput,
deleteOnTermination: args.nodeRootVolumeDeleteOnTermination,
},
ebsBlockDevices: [],
};
}
// Bottlerocket has two block devices, the root device stores the OS itself and the other is for data like images, logs, persistent storage
// We need to allow users to configure the block device for data
const deviceName = amiInfo.blockDeviceMappings.find(
(bdm) => bdm.deviceName !== amiInfo.rootDeviceName,
)?.deviceName;
return {
rootBlockDevice: {} as aws.types.input.ec2.LaunchConfigurationEbsBlockDevice,
// if no ebs settings are specified, we cannot set the blockDevice props because that would end up as a validation error
ebsBlockDevices: [
{
deviceName,
encrypted: args.nodeRootVolumeEncrypted,
volumeSize: args.nodeRootVolumeSize,
volumeType: args.nodeRootVolumeType,
iops: args.nodeRootVolumeIops,
throughput: args.nodeRootVolumeThroughput,
deleteOnTermination: args.nodeRootVolumeDeleteOnTermination,
},
]
.filter((bd) => Object.values(bd).some((v) => v !== undefined))
.map((bd) => {
return { ...bd, deviceName: bd.deviceName ?? amiInfo.rootDeviceName };
}),
};