-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
types.go
1640 lines (1374 loc) · 51.4 KB
/
types.go
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
package v1alpha5
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"strings"
"time"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface"
"github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface"
"github.com/aws/aws-sdk-go/service/cloudtrail/cloudtrailiface"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/aws/aws-sdk-go/service/eks"
"github.com/aws/aws-sdk-go/service/eks/eksiface"
"github.com/aws/aws-sdk-go/service/elb/elbiface"
"github.com/aws/aws-sdk-go/service/elbv2/elbv2iface"
"github.com/aws/aws-sdk-go/service/iam/iamiface"
"github.com/aws/aws-sdk-go/service/ssm/ssmiface"
"github.com/aws/aws-sdk-go/service/sts/stsiface"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"github.com/weaveworks/eksctl/pkg/utils/taints"
)
// Values for `KubernetesVersion`
// All valid values should go in this block
const (
Version1_16 = "1.16"
Version1_17 = "1.17"
Version1_18 = "1.18"
Version1_19 = "1.19"
Version1_20 = "1.20"
Version1_21 = "1.21"
// DefaultVersion (default)
DefaultVersion = Version1_20
LatestVersion = Version1_21
)
// No longer supported versions
const (
// Version1_10 represents Kubernetes version 1.10.x
Version1_10 = "1.10"
// Version1_11 represents Kubernetes version 1.11.x
Version1_11 = "1.11"
// Version1_12 represents Kubernetes version 1.12.x
Version1_12 = "1.12"
// Version1_13 represents Kubernetes version 1.13.x
Version1_13 = "1.13"
// Version1_14 represents Kubernetes version 1.14.x
Version1_14 = "1.14"
// Version1_15 represents Kubernetes version 1.15.x
Version1_15 = "1.15"
)
// Not yet supported versions
const (
// Version1_22 represents Kubernetes version 1.22.x
Version1_22 = "1.22"
)
const (
// AWSDebugLevel defines the LogLevel for AWS produced logs
AWSDebugLevel = 5
)
// Regions
const (
// RegionUSWest1 represents the US West Region North California
RegionUSWest1 = "us-west-1"
// RegionUSWest2 represents the US West Region Oregon
RegionUSWest2 = "us-west-2"
// RegionUSEast1 represents the US East Region North Virginia
RegionUSEast1 = "us-east-1"
// RegionUSEast2 represents the US East Region Ohio
RegionUSEast2 = "us-east-2"
// RegionCACentral1 represents the Canada Central Region
RegionCACentral1 = "ca-central-1"
// RegionEUWest1 represents the EU West Region Ireland
RegionEUWest1 = "eu-west-1"
// RegionEUWest2 represents the EU West Region London
RegionEUWest2 = "eu-west-2"
// RegionEUWest3 represents the EU West Region Paris
RegionEUWest3 = "eu-west-3"
// RegionEUNorth1 represents the EU North Region Stockholm
RegionEUNorth1 = "eu-north-1"
// RegionEUCentral1 represents the EU Central Region Frankfurt
RegionEUCentral1 = "eu-central-1"
// RegionEUSouth1 represents te Eu South Region Milan
RegionEUSouth1 = "eu-south-1"
// RegionAPNorthEast1 represents the Asia-Pacific North East Region Tokyo
RegionAPNorthEast1 = "ap-northeast-1"
// RegionAPNorthEast2 represents the Asia-Pacific North East Region Seoul
RegionAPNorthEast2 = "ap-northeast-2"
// RegionAPNorthEast3 represents the Asia-Pacific North East region Osaka
RegionAPNorthEast3 = "ap-northeast-3"
// RegionAPSouthEast1 represents the Asia-Pacific South East Region Singapore
RegionAPSouthEast1 = "ap-southeast-1"
// RegionAPSouthEast2 represents the Asia-Pacific South East Region Sydney
RegionAPSouthEast2 = "ap-southeast-2"
// RegionAPSouth1 represents the Asia-Pacific South Region Mumbai
RegionAPSouth1 = "ap-south-1"
// RegionAPEast1 represents the Asia Pacific Region Hong Kong
RegionAPEast1 = "ap-east-1"
// RegionMESouth1 represents the Middle East Region Bahrain
RegionMESouth1 = "me-south-1"
// RegionSAEast1 represents the South America Region Sao Paulo
RegionSAEast1 = "sa-east-1"
// RegionAFSouth1 represents the Africa Region Cape Town
RegionAFSouth1 = "af-south-1"
// RegionCNNorthwest1 represents the China region Ningxia
RegionCNNorthwest1 = "cn-northwest-1"
// RegionCNNorth1 represents the China region Beijing
RegionCNNorth1 = "cn-north-1"
// RegionUSGovWest1 represents the region GovCloud (US-West)
RegionUSGovWest1 = "us-gov-west-1"
// RegionUSGovEast1 represents the region GovCloud (US-East)
RegionUSGovEast1 = "us-gov-east-1"
// DefaultRegion defines the default region, where to deploy the EKS cluster
DefaultRegion = RegionUSWest2
)
// Partitions
const (
PartitionAWS = "aws"
PartitionChina = "aws-cn"
PartitionUSGov = "aws-us-gov"
)
// Values for `NodeAMIFamily`
// All valid values of supported families should go in this block
const (
// DefaultNodeImageFamily (default)
DefaultNodeImageFamily = NodeImageFamilyAmazonLinux2
NodeImageFamilyAmazonLinux2 = "AmazonLinux2"
NodeImageFamilyUbuntu2004 = "Ubuntu2004"
NodeImageFamilyUbuntu1804 = "Ubuntu1804"
NodeImageFamilyBottlerocket = "Bottlerocket"
NodeImageFamilyWindowsServer2019CoreContainer = "WindowsServer2019CoreContainer"
NodeImageFamilyWindowsServer2019FullContainer = "WindowsServer2019FullContainer"
NodeImageFamilyWindowsServer2004CoreContainer = "WindowsServer2004CoreContainer"
)
// Container runtime values.
const (
ContainerRuntimeContainerD = "containerd"
ContainerRuntimeDockerD = "dockerd"
)
const (
// DefaultNodeType is the default instance type to use for nodes
DefaultNodeType = "m5.large"
// DefaultNodeCount defines the default number of nodes to be created
DefaultNodeCount = 2
// NodeImageResolverAuto represents auto AMI resolver (see ami package)
NodeImageResolverAuto = "auto"
// NodeImageResolverAutoSSM is used to indicate that the latest EKS AMIs should be used for the nodes. The AMI is selected
// using an SSM GetParameter query
NodeImageResolverAutoSSM = "auto-ssm"
// EksctlVersionTag defines the version of eksctl which is used to provision or update EKS cluster
EksctlVersionTag = "alpha.eksctl.io/eksctl-version"
// ClusterNameTag defines the tag of the cluster name
ClusterNameTag = "alpha.eksctl.io/cluster-name"
// OldClusterNameTag defines the tag of the cluster name
OldClusterNameTag = "eksctl.cluster.k8s.io/v1alpha1/cluster-name"
// NodeGroupNameTag defines the tag of the nodegroup name
NodeGroupNameTag = "alpha.eksctl.io/nodegroup-name"
// NodeGroupTypeTag defines the nodegroup type as managed or unmanaged
NodeGroupTypeTag = "alpha.eksctl.io/nodegroup-type"
// OldNodeGroupNameTag defines the tag of the nodegroup name
OldNodeGroupNameTag = "eksctl.io/v1alpha2/nodegroup-name"
// OldNodeGroupIDTag defines the old version of tag of the nodegroup name
OldNodeGroupIDTag = "eksctl.cluster.k8s.io/v1alpha1/nodegroup-id"
// IAMServiceAccountNameTag defines the tag of the IAM service account name
IAMServiceAccountNameTag = "alpha.eksctl.io/iamserviceaccount-name"
// AddonNameTag defines the tag of the IAM service account name
AddonNameTag = "alpha.eksctl.io/addon-name"
// ClusterNameLabel defines the tag of the cluster name
ClusterNameLabel = "alpha.eksctl.io/cluster-name"
// NodeGroupNameLabel defines the label of the nodegroup name
NodeGroupNameLabel = "alpha.eksctl.io/nodegroup-name"
EKSNodeGroupNameLabel = "eks.amazonaws.com/nodegroup"
// SpotAllocationStrategyLowestPrice defines the ASG spot allocation strategy of lowest-price
SpotAllocationStrategyLowestPrice = "lowest-price"
// SpotAllocationStrategyCapacityOptimized defines the ASG spot allocation strategy of capacity-optimized
SpotAllocationStrategyCapacityOptimized = "capacity-optimized"
// SpotAllocationStrategyCapacityOptimizedPrioritized defines the ASG spot allocation strategy of capacity-optimized-prioritized
// Use the capacity-optimized-prioritized allocation strategy and then set the order of instance types in
// the list of launch template overrides from highest to lowest priority (first to last in the list).
// Amazon EC2 Auto Scaling honors the instance type priorities on a best-effort basis but optimizes
// for capacity first. This is a good option for workloads where the possibility of disruption must be
// minimized, but also the preference for certain instance types matters.
// https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-purchase-options.html#asg-spot-strategy
SpotAllocationStrategyCapacityOptimizedPrioritized = "capacity-optimized-prioritized"
// eksResourceAccountStandard defines the AWS EKS account ID that provides node resources in default regions
// for standard AWS partition
eksResourceAccountStandard = "602401143452"
// eksResourceAccountAPEast1 defines the AWS EKS account ID that provides node resources in ap-east-1 region
eksResourceAccountAPEast1 = "800184023465"
// eksResourceAccountMESouth1 defines the AWS EKS account ID that provides node resources in me-south-1 region
eksResourceAccountMESouth1 = "558608220178"
// eksResourceAccountCNNorthWest1 defines the AWS EKS account ID that provides node resources in cn-northwest-1 region
eksResourceAccountCNNorthWest1 = "961992271922"
// eksResourceAccountCNNorth1 defines the AWS EKS account ID that provides node resources in cn-north-1
eksResourceAccountCNNorth1 = "918309763551"
// eksResourceAccountAFSouth1 defines the AWS EKS account ID that provides node resources in af-south-1
eksResourceAccountAFSouth1 = "877085696533"
// eksResourceAccountEUSouth1 defines the AWS EKS account ID that provides node resources in eu-south-1
eksResourceAccountEUSouth1 = "590381155156"
// eksResourceAccountUSGovWest1 defines the AWS EKS account ID that provides node resources in us-gov-west-1
eksResourceAccountUSGovWest1 = "013241004608"
// eksResourceAccountUSGovEast1 defines the AWS EKS account ID that provides node resources in us-gov-east-1
eksResourceAccountUSGovEast1 = "151742754352"
)
// Values for `VolumeType`
const (
// NodeVolumeTypeGP2 is General Purpose SSD
NodeVolumeTypeGP2 = "gp2"
// NodeVolumeTypeGP3 is General Purpose SSD which can be optimised for high throughput (default)
NodeVolumeTypeGP3 = "gp3"
// NodeVolumeTypeIO1 is Provisioned IOPS SSD
NodeVolumeTypeIO1 = "io1"
// NodeVolumeTypeSC1 is Cold HDD
NodeVolumeTypeSC1 = "sc1"
// NodeVolumeTypeST1 is Throughput Optimized HDD
NodeVolumeTypeST1 = "st1"
)
// NodeGroupType defines the nodegroup type
type NodeGroupType string
const (
// NodeGroupTypeManaged defines a managed nodegroup
NodeGroupTypeManaged NodeGroupType = "managed"
// NodeGroupTypeUnmanaged defines an unmanaged nodegroup
NodeGroupTypeUnmanaged NodeGroupType = "unmanaged"
// NodeGroupTypeUnowned defines an unowned managed nodegroup
NodeGroupTypeUnowned NodeGroupType = "unowned"
// DefaultNodeVolumeThroughput defines the default throughput for gp3 volumes, set to the min value
DefaultNodeVolumeThroughput = 125
// DefaultNodeVolumeIO1IOPS defines the default throughput for io1 volumes, set to the min value
DefaultNodeVolumeIO1IOPS = 100
// DefaultNodeVolumeGP3IOPS defines the default throughput for gp3, set to the min value
DefaultNodeVolumeGP3IOPS = 3000
)
var (
// DefaultWaitTimeout defines the default wait timeout
DefaultWaitTimeout = 25 * time.Minute
// DefaultNodeSSHPublicKeyPath is the default path to SSH public key
DefaultNodeSSHPublicKeyPath = "~/.ssh/id_rsa.pub"
// DefaultNodeVolumeType defines the default root volume type to use
DefaultNodeVolumeType = NodeVolumeTypeGP3
// DefaultNodeVolumeSize defines the default root volume size
DefaultNodeVolumeSize = 80
)
var (
// DefaultContainerRuntime defines the default container runtime.
DefaultContainerRuntime = ContainerRuntimeDockerD
)
// Enabled return pointer to true value
// for use in defaulters of *bool fields
func Enabled() *bool {
v := true
return &v
}
// Disabled return pointer to false value
// for use in defaulters of *bool fields
func Disabled() *bool {
v := false
return &v
}
// IsEnabled will only return true if v is not nil and true
func IsEnabled(v *bool) bool { return v != nil && *v }
// IsDisabled will only return true if v is not nil and false
func IsDisabled(v *bool) bool { return v != nil && !*v }
// IsSetAndNonEmptyString will only return true if s is not nil and not empty
func IsSetAndNonEmptyString(s *string) bool { return s != nil && *s != "" }
// SupportedRegions are the regions where EKS is available
func SupportedRegions() []string {
return []string{
RegionUSWest1,
RegionUSWest2,
RegionUSEast1,
RegionUSEast2,
RegionCACentral1,
RegionEUWest1,
RegionEUWest2,
RegionEUWest3,
RegionEUNorth1,
RegionEUCentral1,
RegionEUSouth1,
RegionAPNorthEast1,
RegionAPNorthEast2,
RegionAPNorthEast3,
RegionAPSouthEast1,
RegionAPSouthEast2,
RegionAPSouth1,
RegionAPEast1,
RegionMESouth1,
RegionSAEast1,
RegionAFSouth1,
RegionCNNorthwest1,
RegionCNNorth1,
RegionUSGovWest1,
RegionUSGovEast1,
}
}
// Partition gives the partition a region belongs to
func Partition(region string) string {
switch region {
case RegionUSGovWest1, RegionUSGovEast1:
return PartitionUSGov
case RegionCNNorth1, RegionCNNorthwest1:
return PartitionChina
default:
return PartitionAWS
}
}
// DeprecatedVersions are the versions of Kubernetes that EKS used to support
// but no longer does. See also:
// https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html
func DeprecatedVersions() []string {
return []string{
Version1_10,
Version1_11,
Version1_12,
Version1_13,
Version1_14,
Version1_15,
}
}
// IsDeprecatedVersion returns true if the given Kubernetes version has been deprecated in EKS
func IsDeprecatedVersion(version string) bool {
for _, v := range DeprecatedVersions() {
if version == v {
return true
}
}
return false
}
// SupportedVersions are the versions of Kubernetes that EKS supports
func SupportedVersions() []string {
return []string{
Version1_16,
Version1_17,
Version1_18,
Version1_19,
Version1_20,
Version1_21,
}
}
// IsSupportedVersion returns true if the given Kubernetes version is supported by eksctl and EKS
func IsSupportedVersion(version string) bool {
for _, v := range SupportedVersions() {
if version == v {
return true
}
}
return false
}
// SupportedNodeVolumeTypes are the volume types that can be used for a node root volume
func SupportedNodeVolumeTypes() []string {
return []string{
NodeVolumeTypeGP2,
NodeVolumeTypeGP3,
NodeVolumeTypeIO1,
NodeVolumeTypeSC1,
NodeVolumeTypeST1,
}
}
// supportedAMIFamilies are the AMI families supported by EKS
func supportedAMIFamilies() []string {
return []string{
NodeImageFamilyAmazonLinux2,
NodeImageFamilyUbuntu2004,
NodeImageFamilyUbuntu1804,
NodeImageFamilyBottlerocket,
NodeImageFamilyWindowsServer2019CoreContainer,
NodeImageFamilyWindowsServer2019FullContainer,
NodeImageFamilyWindowsServer2004CoreContainer,
}
}
// supportedSpotAllocationStrategies are the spot allocation strategies supported by ASG
func supportedSpotAllocationStrategies() []string {
return []string{
SpotAllocationStrategyLowestPrice,
SpotAllocationStrategyCapacityOptimized,
SpotAllocationStrategyCapacityOptimizedPrioritized,
}
}
// isSpotAllocationStrategySupported returns true if the spot allocation strategy is supported for ASG
func isSpotAllocationStrategySupported(allocationStrategy string) bool {
for _, strategy := range supportedSpotAllocationStrategies() {
if strategy == allocationStrategy {
return true
}
}
return false
}
// EKSResourceAccountID provides worker node resources(ami/ecr image) in different aws account
// for different aws partitions & opt-in regions.
func EKSResourceAccountID(region string) string {
switch region {
case RegionAPEast1:
return eksResourceAccountAPEast1
case RegionMESouth1:
return eksResourceAccountMESouth1
case RegionCNNorthwest1:
return eksResourceAccountCNNorthWest1
case RegionCNNorth1:
return eksResourceAccountCNNorth1
case RegionUSGovWest1:
return eksResourceAccountUSGovWest1
case RegionUSGovEast1:
return eksResourceAccountUSGovEast1
case RegionAFSouth1:
return eksResourceAccountAFSouth1
case RegionEUSouth1:
return eksResourceAccountEUSouth1
default:
return eksResourceAccountStandard
}
}
// ClusterMeta contains general cluster information
type ClusterMeta struct {
// Name of the cluster
// +required
Name string `json:"name"`
// the AWS region hosting this cluster
// +required
Region string `json:"region"`
// Valid variants are `KubernetesVersion` constants
// +optional
Version string `json:"version,omitempty"`
// Tags are used to tag AWS resources created by eksctl
// +optional
Tags map[string]string `json:"tags,omitempty"`
// Annotations are arbitrary metadata ignored by `eksctl`.
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
}
// KubernetesNetworkConfig contains cluster networking options
type KubernetesNetworkConfig struct {
// ServiceIPv4CIDR is the CIDR range from where `ClusterIP`s are assigned
ServiceIPv4CIDR string `json:"serviceIPv4CIDR,omitempty"`
}
type EKSCTLCreated string
// ClusterStatus holds read-only attributes of a cluster
type ClusterStatus struct {
Endpoint string `json:"endpoint,omitempty"`
CertificateAuthorityData []byte `json:"certificateAuthorityData,omitempty"`
ARN string `json:"arn,omitempty"`
KubernetesNetworkConfig *KubernetesNetworkConfig `json:"-"`
StackName string `json:"stackName,omitempty"`
EKSCTLCreated EKSCTLCreated `json:"eksctlCreated,omitempty"`
}
// String returns canonical representation of ClusterMeta
func (c *ClusterMeta) String() string {
return fmt.Sprintf("%s.%s.eksctl.io", c.Name, c.Region)
}
// LogString returns representation of ClusterMeta for logs
func (c *ClusterMeta) LogString() string {
return fmt.Sprintf("EKS cluster %q in %q region", c.Name, c.Region)
}
// LogString returns representation of ClusterConfig for logs
func (c ClusterConfig) LogString() string {
modes := []string{}
if c.IsFargateEnabled() {
modes = append(modes, "Fargate profile")
}
if len(c.ManagedNodeGroups) > 0 {
modes = append(modes, "managed nodes")
}
if len(c.NodeGroups) > 0 {
modes = append(modes, "un-managed nodes")
}
return fmt.Sprintf("%s with %s", c.Metadata.LogString(), strings.Join(modes, " and "))
}
// IsFargateEnabled returns true if Fargate is enabled in this ClusterConfig,
// or false otherwise.
func (c ClusterConfig) IsFargateEnabled() bool {
return len(c.FargateProfiles) > 0
}
// ClusterProvider is the interface to AWS APIs
type ClusterProvider interface {
CloudFormation() cloudformationiface.CloudFormationAPI
CloudFormationRoleARN() string
CloudFormationDisableRollback() bool
ASG() autoscalingiface.AutoScalingAPI
EKS() eksiface.EKSAPI
EC2() ec2iface.EC2API
ELB() elbiface.ELBAPI
ELBV2() elbv2iface.ELBV2API
STS() stsiface.STSAPI
SSM() ssmiface.SSMAPI
IAM() iamiface.IAMAPI
CloudTrail() cloudtrailiface.CloudTrailAPI
Region() string
Profile() string
WaitTimeout() time.Duration
ConfigProvider() client.ConfigProvider
Session() *session.Session
}
// ProviderConfig holds global parameters for all interactions with AWS APIs
type ProviderConfig struct {
CloudFormationRoleARN string
CloudFormationDisableRollback bool
Region string
Profile string
WaitTimeout time.Duration
}
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ClusterConfig is a simple config, to be replaced with Cluster API
type ClusterConfig struct {
metav1.TypeMeta
// +required
Metadata *ClusterMeta `json:"metadata"`
// +optional
KubernetesNetworkConfig *KubernetesNetworkConfig `json:"kubernetesNetworkConfig,omitempty"`
// +optional
IAM *ClusterIAM `json:"iam,omitempty"`
// +optional
IdentityProviders []IdentityProvider `json:"identityProviders,omitempty"`
// +optional
VPC *ClusterVPC `json:"vpc,omitempty"`
// +optional
Addons []*Addon `json:"addons,omitempty"`
// PrivateCluster allows configuring a fully-private cluster
// in which no node has outbound internet access, and private access
// to AWS services is enabled via VPC endpoints
// +optional
PrivateCluster *PrivateCluster `json:"privateCluster,omitempty"`
// NodeGroups For information and examples see [nodegroups](/usage/managing-nodegroups)
// +optional
NodeGroups []*NodeGroup `json:"nodeGroups,omitempty"`
// ManagedNodeGroups See [Nodegroups usage](/usage/managing-nodegroups)
// and [managed nodegroups](/usage/eks-managed-nodes/)
// +optional
ManagedNodeGroups []*ManagedNodeGroup `json:"managedNodeGroups,omitempty"`
// +optional
FargateProfiles []*FargateProfile `json:"fargateProfiles,omitempty"`
// +optional
AvailabilityZones []string `json:"availabilityZones,omitempty"`
// See [CloudWatch support](/usage/cloudwatch-cluster-logging/)
// +optional
CloudWatch *ClusterCloudWatch `json:"cloudWatch,omitempty"`
// +optional
SecretsEncryption *SecretsEncryption `json:"secretsEncryption,omitempty"`
Status *ClusterStatus `json:"-"`
// FLUX V1 DEPRECATION NOTICE. https://github.com/weaveworks/eksctl/issues/2963
// Git exposes configuration for Flux v1 and an earlier iteration of gitops
// +optional
Git *Git `json:"git,omitempty"`
// GitOps exposes configuration for Flux v2 and will continue to be used in
// future gitops plans, replacing the Git configuration above
// +optional
GitOps *GitOps `json:"gitops,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ClusterConfigList is a list of ClusterConfigs
type ClusterConfigList struct {
metav1.TypeMeta
metav1.ListMeta `json:"metadata"`
Items []ClusterConfig `json:"items"`
}
// ClusterConfigTypeMeta constructs TypeMeta for ClusterConfig
func ClusterConfigTypeMeta() metav1.TypeMeta {
return metav1.TypeMeta{
Kind: ClusterConfigKind,
APIVersion: SchemeGroupVersion.String(),
}
}
// NewClusterConfig creates new config for a cluster;
// it doesn't include initial nodegroup, so user must
// call NewNodeGroup to create one
func NewClusterConfig() *ClusterConfig {
cfg := &ClusterConfig{
TypeMeta: ClusterConfigTypeMeta(),
Metadata: &ClusterMeta{
Version: DefaultVersion,
},
IAM: NewClusterIAM(),
VPC: NewClusterVPC(),
CloudWatch: &ClusterCloudWatch{
ClusterLogging: &ClusterCloudWatchLogging{},
},
PrivateCluster: &PrivateCluster{},
}
return cfg
}
// NewClusterVPC creates new VPC config for a cluster
func NewClusterVPC() *ClusterVPC {
cidr := DefaultCIDR()
return &ClusterVPC{
Network: Network{
CIDR: &cidr,
},
ManageSharedNodeSecurityGroupRules: Enabled(),
NAT: DefaultClusterNAT(),
AutoAllocateIPv6: Disabled(),
ClusterEndpoints: &ClusterEndpoints{},
}
}
// NewClusterIAM creates a new ClusterIAM for a cluster
func NewClusterIAM() *ClusterIAM {
return &ClusterIAM{
WithOIDC: Disabled(),
}
}
// AppendAvailabilityZone appends a new AZ to the set
func (c *ClusterConfig) AppendAvailabilityZone(newAZ string) {
for _, az := range c.AvailabilityZones {
if az == newAZ {
return
}
}
c.AvailabilityZones = append(c.AvailabilityZones, newAZ)
}
// SetClusterStatus populates ClusterStatus using *eks.Cluster.
func (c *ClusterConfig) SetClusterStatus(cluster *eks.Cluster) error {
if networkConfig := cluster.KubernetesNetworkConfig; networkConfig != nil && networkConfig.ServiceIpv4Cidr != nil {
c.Status.KubernetesNetworkConfig = &KubernetesNetworkConfig{
ServiceIPv4CIDR: *networkConfig.ServiceIpv4Cidr,
}
}
data, err := base64.StdEncoding.DecodeString(*cluster.CertificateAuthority.Data)
if err != nil {
return errors.Wrap(err, "decoding certificate authority data")
}
c.Status.Endpoint = *cluster.Endpoint
c.Status.CertificateAuthorityData = data
c.Status.ARN = *cluster.Arn
return nil
}
// NewNodeGroup creates a new NodeGroup, and returns a pointer to it
func NewNodeGroup() *NodeGroup {
return &NodeGroup{
NodeGroupBase: &NodeGroupBase{
PrivateNetworking: false,
InstanceType: DefaultNodeType,
VolumeSize: &DefaultNodeVolumeSize,
IAM: &NodeGroupIAM{
WithAddonPolicies: NodeGroupIAMAddonPolicies{
ImageBuilder: Disabled(),
AutoScaler: Disabled(),
ExternalDNS: Disabled(),
CertManager: Disabled(),
AppMesh: Disabled(),
AppMeshPreview: Disabled(),
EBS: Disabled(),
FSX: Disabled(),
EFS: Disabled(),
AWSLoadBalancerController: Disabled(),
XRay: Disabled(),
CloudWatch: Disabled(),
},
},
ScalingConfig: &ScalingConfig{},
SSH: &NodeGroupSSH{
Allow: Disabled(),
PublicKeyPath: &DefaultNodeSSHPublicKeyPath,
},
VolumeType: &DefaultNodeVolumeType,
SecurityGroups: &NodeGroupSGs{
AttachIDs: []string{},
WithLocal: Enabled(),
WithShared: Enabled(),
},
DisableIMDSv1: Disabled(),
DisablePodIMDS: Disabled(),
InstanceSelector: &InstanceSelector{},
},
}
}
// NewManagedNodeGroup creates a new ManagedNodeGroup
func NewManagedNodeGroup() *ManagedNodeGroup {
var (
publicKey = DefaultNodeSSHPublicKeyPath
volumeSize = DefaultNodeVolumeSize
volumeType = DefaultNodeVolumeType
)
return &ManagedNodeGroup{
NodeGroupBase: &NodeGroupBase{
VolumeSize: &volumeSize,
VolumeType: &volumeType,
SSH: &NodeGroupSSH{
Allow: Disabled(),
PublicKeyName: &publicKey,
EnableSSM: Disabled(),
},
IAM: &NodeGroupIAM{
WithAddonPolicies: NodeGroupIAMAddonPolicies{
ImageBuilder: Disabled(),
AutoScaler: Disabled(),
ExternalDNS: Disabled(),
CertManager: Disabled(),
AppMesh: Disabled(),
AppMeshPreview: Disabled(),
EBS: Disabled(),
FSX: Disabled(),
EFS: Disabled(),
AWSLoadBalancerController: Disabled(),
XRay: Disabled(),
CloudWatch: Disabled(),
},
},
ScalingConfig: &ScalingConfig{},
SecurityGroups: &NodeGroupSGs{},
},
}
}
// NewNodeGroup creates new nodegroup inside cluster config,
// it returns pointer to the nodegroup for convenience
func (c *ClusterConfig) NewNodeGroup() *NodeGroup {
ng := NewNodeGroup()
c.NodeGroups = append(c.NodeGroups, ng)
return ng
}
// NodeGroup holds configuration attributes that are
// specific to a nodegroup
type NodeGroup struct {
*NodeGroupBase
//+optional
InstancesDistribution *NodeGroupInstancesDistribution `json:"instancesDistribution,omitempty"`
// +optional
ASGMetricsCollection []MetricsCollection `json:"asgMetricsCollection,omitempty"`
// CPUCredits configures [T3 Unlimited](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/burstable-performance-instances-unlimited-mode.html), valid only for T-type instances
// +optional
CPUCredits *string `json:"cpuCredits,omitempty"`
// Associate load balancers with auto scaling group
// +optional
ClassicLoadBalancerNames []string `json:"classicLoadBalancerNames,omitempty"`
// Associate target group with auto scaling group
// +optional
TargetGroupARNs []string `json:"targetGroupARNs,omitempty"`
// Taints taints to apply to the nodegroup
// +optional
Taints taintsWrapper `json:"taints,omitempty"`
// UpdateConfig configures how to update NodeGroups.
// +optional
UpdateConfig *NodeGroupUpdateConfig `json:"updateConfig,omitempty"`
// [Custom
// address](/usage/vpc-networking/#custom-cluster-dns-address) used for DNS
// lookups
// +optional
ClusterDNS string `json:"clusterDNS,omitempty"`
// [Customize `kubelet` config](/usage/customizing-the-kubelet/)
// +optional
KubeletExtraConfig *InlineDocument `json:"kubeletExtraConfig,omitempty"`
// ContainerRuntime defines the runtime (CRI) to use for containers on the node
// +optional
ContainerRuntime *string `json:"containerRuntime,omitempty"`
}
// GetContainerRuntime returns the container runtime.
func (n *NodeGroup) GetContainerRuntime() string {
if n.ContainerRuntime != nil {
return *n.ContainerRuntime
}
return ""
}
func (n *NodeGroup) InstanceTypeList() []string {
if HasMixedInstances(n) {
return n.InstancesDistribution.InstanceTypes
}
return []string{n.InstanceType}
}
// NGTaints implements NodePool
func (n *NodeGroup) NGTaints() []NodeGroupTaint {
return n.Taints
}
// BaseNodeGroup implements NodePool
func (n *NodeGroup) BaseNodeGroup() *NodeGroupBase {
return n.NodeGroupBase
}
// GitOps groups all configuration options related to enabling GitOps Toolkit on a
// cluster and linking it to a Git repository.
// Note: this will replace the older Git types
type GitOps struct {
// Flux holds options to enable Flux v2 on your cluster
Flux *Flux `json:"flux,omitempty"`
}
// Git groups all configuration options related to enabling GitOps on a
// cluster and linking it to a Git repository.
// [Gitops Guide](/gitops-quickstart/)
type Git struct {
// Repo holds options to enable Flux v1 on your cluster. DEPRECATED.
Repo *Repo `json:"repo,omitempty"`
// Operator holds options to configure the Helm Operator in conjunction with
// a Flux v1 installation. DEPRECATED.
// +optional
Operator Operator `json:"operator,omitempty"`
// BootstrapProfile holds options to install a BootstrapProfile on the cluster.
// DEPRECATED.
// +optional
BootstrapProfile *Profile `json:"bootstrapProfile,omitempty"` // one or many profiles to enable on this cluster once it is created
}
// FLUX V1 DEPRECATION NOTICE. https://github.com/weaveworks/eksctl/issues/2963
// NewGit returns a new empty Git configuration
func NewGit() *Git {
return &Git{
Repo: &Repo{},
Operator: Operator{},
BootstrapProfile: &Profile{},
}
}
// Flux groups all configuration options related to a Git repository used for
// GitOps Toolkit (Flux v2).
type Flux struct {
// The repository hosting service. Can be either Github or Gitlab.
GitProvider string `json:"gitProvider,omitempty"`
// Flags is an arbitrary map of string to string to pass any flags to Flux bootstrap
// via eksctl see https://fluxcd.io/docs/ for information on all flags
Flags FluxFlags `json:"flags,omitempty"`
}
// FluxFlags is a map of string for passing arbitrary flags to Flux bootstrap
type FluxFlags map[string]string
// Repo groups all configuration options related to a Git repository used for
// GitOps.
type Repo struct {
// The Git SSH URL to the repository which will contain the cluster configuration
// For example: `git@github.com:org/repo`
// DEPRECATED
URL string `json:"url,omitempty"`
// The git branch under which cluster configuration files will be committed & pushed, e.g. master
// DEPRECATED
// +optional
Branch string `json:"branch,omitempty"`
// Relative paths within the Git repository which the GitOps operator will monitor to find Kubernetes manifests to apply, e.g. ["kube-system", "base"]
// DEPRECATED
//+optional
Paths []string `json:"paths,omitempty"`
// The directory under which Flux configuration files will be written, e.g. flux/
// DEPRECATED
// +optional