-
Notifications
You must be signed in to change notification settings - Fork 278
/
cluster_types.go
996 lines (856 loc) Β· 27.2 KB
/
cluster_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
package v1alpha1
import (
"strconv"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"github.com/aws/eks-anywhere/pkg/logger"
)
const (
// PausedAnnotation is an annotation that can be applied to EKS-A cluster
// object to prevent a controller from processing a resource.
pausedAnnotation = "anywhere.eks.amazonaws.com/paused"
// ManagedByCLIAnnotation can be applied to an EKS-A Cluster to signal when the CLI is currently
// performing an operation so the controller should not take any action. When marked for deletion,
// the controller will remove the finalizer and let the cluster be deleted.
ManagedByCLIAnnotation = "anywhere.eks.amazonaws.com/managed-by-cli"
// ControlPlaneAnnotation is an annotation that can be applied to EKS-A machineconfig
// object to prevent a controller from making changes to that resource.
controlPlaneAnnotation = "anywhere.eks.amazonaws.com/control-plane"
clusterResourceType = "clusters.anywhere.eks.amazonaws.com"
// etcdAnnotation can be applied to EKS-A machineconfig CR for etcd, to prevent controller from making changes to it.
etcdAnnotation = "anywhere.eks.amazonaws.com/etcd"
// managementAnnotation points to the name of a management cluster
// cluster object.
managementAnnotation = "anywhere.eks.amazonaws.com/managed-by"
// defaultEksaNamespace is the default namespace for EKS-A resources when not specified.
defaultEksaNamespace = "default"
)
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// ClusterSpec defines the desired state of Cluster.
type ClusterSpec struct {
KubernetesVersion KubernetesVersion `json:"kubernetesVersion,omitempty"`
ControlPlaneConfiguration ControlPlaneConfiguration `json:"controlPlaneConfiguration,omitempty"`
WorkerNodeGroupConfigurations []WorkerNodeGroupConfiguration `json:"workerNodeGroupConfigurations,omitempty"`
DatacenterRef Ref `json:"datacenterRef,omitempty"`
IdentityProviderRefs []Ref `json:"identityProviderRefs,omitempty"`
GitOpsRef *Ref `json:"gitOpsRef,omitempty"`
ClusterNetwork ClusterNetwork `json:"clusterNetwork,omitempty"`
// +kubebuilder:validation:Optional
ExternalEtcdConfiguration *ExternalEtcdConfiguration `json:"externalEtcdConfiguration,omitempty"`
ProxyConfiguration *ProxyConfiguration `json:"proxyConfiguration,omitempty"`
RegistryMirrorConfiguration *RegistryMirrorConfiguration `json:"registryMirrorConfiguration,omitempty"`
ManagementCluster ManagementCluster `json:"managementCluster,omitempty"`
PodIAMConfig *PodIAMConfig `json:"podIamConfig,omitempty"`
// BundlesRef contains a reference to the Bundles containing the desired dependencies for the cluster
BundlesRef *BundlesRef `json:"bundlesRef,omitempty"`
}
// HasAWSIamConfig checks if AWSIamConfig is configured for the cluster.
func (c *Cluster) HasAWSIamConfig() bool {
for _, identityProvider := range c.Spec.IdentityProviderRefs {
if identityProvider.Kind == AWSIamConfigKind {
return true
}
}
return false
}
func (n *Cluster) Equal(o *Cluster) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
if n.Spec.KubernetesVersion != o.Spec.KubernetesVersion {
return false
}
if !n.Spec.ControlPlaneConfiguration.Equal(&o.Spec.ControlPlaneConfiguration) {
return false
}
if !WorkerNodeGroupConfigurationsSliceEqual(n.Spec.WorkerNodeGroupConfigurations, o.Spec.WorkerNodeGroupConfigurations) {
return false
}
if !n.Spec.DatacenterRef.Equal(&o.Spec.DatacenterRef) {
return false
}
if !RefSliceEqual(n.Spec.IdentityProviderRefs, o.Spec.IdentityProviderRefs) {
return false
}
if !n.Spec.GitOpsRef.Equal(o.Spec.GitOpsRef) {
return false
}
if !n.Spec.ClusterNetwork.Equal(&o.Spec.ClusterNetwork) {
return false
}
if !n.Spec.ExternalEtcdConfiguration.Equal(o.Spec.ExternalEtcdConfiguration) {
return false
}
if !n.Spec.ProxyConfiguration.Equal(o.Spec.ProxyConfiguration) {
return false
}
if !n.Spec.RegistryMirrorConfiguration.Equal(o.Spec.RegistryMirrorConfiguration) {
return false
}
if !n.ManagementClusterEqual(o) {
return false
}
if !n.Spec.BundlesRef.Equal(o.Spec.BundlesRef) {
return false
}
return true
}
func (n *Cluster) Validate() error {
return ValidateClusterConfigContent(n)
}
func (n *Cluster) SetDefaults() {
// TODO: move any defaults that can return error out of this package
// All the defaults here should be context unaware
if err := setClusterDefaults(n); err != nil {
logger.Error(err, "Failed to validate Cluster")
}
}
type ProxyConfiguration struct {
HttpProxy string `json:"httpProxy,omitempty"`
HttpsProxy string `json:"httpsProxy,omitempty"`
NoProxy []string `json:"noProxy,omitempty"`
}
func (n *ProxyConfiguration) Equal(o *ProxyConfiguration) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
return n.HttpProxy == o.HttpProxy && n.HttpsProxy == o.HttpsProxy && SliceEqual(n.NoProxy, o.NoProxy)
}
// RegistryMirrorConfiguration defines the settings for image registry mirror.
type RegistryMirrorConfiguration struct {
// Endpoint defines the registry mirror endpoint to use for pulling images
Endpoint string `json:"endpoint,omitempty"`
// Port defines the port exposed for registry mirror endpoint
Port string `json:"port,omitempty"`
// OCINamespaces defines the mapping from an upstream registry to a local namespace where upstream
// artifacts are placed into
OCINamespaces []OCINamespace `json:"ociNamespaces,omitempty"`
// CACertContent defines the contents registry mirror CA certificate
CACertContent string `json:"caCertContent,omitempty"`
// Authenticate defines if registry requires authentication
Authenticate bool `json:"authenticate,omitempty"`
// InsecureSkipVerify skips the registry certificate verification.
// Only use this solution for isolated testing or in a tightly controlled, air-gapped environment.
// Currently only supported for snow provider
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
}
// OCINamespace represents an entity in a local reigstry to group related images.
type OCINamespace struct {
// Name refers to the name of the upstream registry
Registry string `json:"registry"`
// Namespace refers to the name of a namespace in the local registry
Namespace string `json:"namespace"`
}
func (n *RegistryMirrorConfiguration) Equal(o *RegistryMirrorConfiguration) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
return n.Endpoint == o.Endpoint && n.Port == o.Port && n.CACertContent == o.CACertContent &&
n.InsecureSkipVerify == o.InsecureSkipVerify && n.Authenticate == o.Authenticate &&
OCINamespacesSliceEqual(n.OCINamespaces, o.OCINamespaces)
}
// OCINamespacesSliceEqual is used to check equality of the OCINamespaces fields of two RegistryMirrorConfiguration.
func OCINamespacesSliceEqual(a, b []OCINamespace) bool {
if len(a) != len(b) {
return false
}
m := make(map[string]int, len(a))
for _, v := range a {
m[generateOCINamespaceKey(v)]++
}
for _, v := range b {
k := generateOCINamespaceKey(v)
if _, ok := m[k]; !ok {
return false
}
m[k]--
if m[k] == 0 {
delete(m, k)
}
}
return len(m) == 0
}
func generateOCINamespaceKey(n OCINamespace) (key string) {
return n.Registry + n.Namespace
}
type ControlPlaneConfiguration struct {
// Count defines the number of desired control plane nodes. Defaults to 1.
Count int `json:"count,omitempty"`
// Endpoint defines the host ip and port to use for the control plane.
Endpoint *Endpoint `json:"endpoint,omitempty"`
// MachineGroupRef defines the machine group configuration for the control plane.
MachineGroupRef *Ref `json:"machineGroupRef,omitempty"`
// Taints define the set of taints to be applied on control plane nodes
Taints []corev1.Taint `json:"taints,omitempty"`
// Labels define the labels to assign to the node
Labels map[string]string `json:"labels,omitempty"`
// UpgradeRolloutStrategy determines the rollout strategy to use for rolling upgrades
// and related parameters/knobs
UpgradeRolloutStrategy *ControlPlaneUpgradeRolloutStrategy `json:"upgradeRolloutStrategy,omitempty"`
}
func TaintsSliceEqual(s1, s2 []corev1.Taint) bool {
if len(s1) != len(s2) {
return false
}
taints := make(map[corev1.Taint]struct{})
for _, taint := range s1 {
taints[taint] = struct{}{}
}
for _, taint := range s2 {
_, ok := taints[taint]
if !ok {
return false
}
}
return true
}
// MapEqual compares two maps to check whether or not they are equal.
func MapEqual(s1, s2 map[string]string) bool {
if len(s1) != len(s2) {
return false
}
for key, val := range s2 {
v, ok := s1[key]
if !ok {
return false
}
if val != v {
return false
}
}
return true
}
func (n *ControlPlaneConfiguration) Equal(o *ControlPlaneConfiguration) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
return n.Count == o.Count && n.Endpoint.Equal(o.Endpoint) && n.MachineGroupRef.Equal(o.MachineGroupRef) &&
TaintsSliceEqual(n.Taints, o.Taints) && MapEqual(n.Labels, o.Labels)
}
type Endpoint struct {
// Host defines the ip that you want to use to connect to the control plane
Host string `json:"host"`
}
func (n *Endpoint) Equal(o *Endpoint) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
return n.Host == o.Host
}
type WorkerNodeGroupConfiguration struct {
// Name refers to the name of the worker node group
Name string `json:"name,omitempty"`
// Count defines the number of desired worker nodes. Defaults to 1.
Count *int `json:"count,omitempty"`
// AutoScalingConfiguration defines the auto scaling configuration
AutoScalingConfiguration *AutoScalingConfiguration `json:"autoscalingConfiguration,omitempty"`
// MachineGroupRef defines the machine group configuration for the worker nodes.
MachineGroupRef *Ref `json:"machineGroupRef,omitempty"`
// Taints define the set of taints to be applied on worker nodes
Taints []corev1.Taint `json:"taints,omitempty"`
// Labels define the labels to assign to the node
Labels map[string]string `json:"labels,omitempty"`
// UpgradeRolloutStrategy determines the rollout strategy to use for rolling upgrades
// and related parameters/knobs
UpgradeRolloutStrategy *WorkerNodesUpgradeRolloutStrategy `json:"upgradeRolloutStrategy,omitempty"`
}
func generateWorkerNodeGroupKey(c WorkerNodeGroupConfiguration) (key string) {
key = c.Name
if c.MachineGroupRef != nil {
key += c.MachineGroupRef.Kind + c.MachineGroupRef.Name
}
if c.AutoScalingConfiguration != nil {
key += "autoscaling" + strconv.Itoa(c.AutoScalingConfiguration.MaxCount) + strconv.Itoa(c.AutoScalingConfiguration.MinCount)
}
if c.Count == nil {
return "nil" + key
}
return strconv.Itoa(*c.Count) + key
}
func WorkerNodeGroupConfigurationsSliceEqual(a, b []WorkerNodeGroupConfiguration) bool {
if len(a) != len(b) {
return false
}
m := make(map[string]int, len(a))
for _, v := range a {
m[generateWorkerNodeGroupKey(v)]++
}
for _, v := range b {
k := generateWorkerNodeGroupKey(v)
if _, ok := m[k]; !ok {
return false
}
m[k] -= 1
if m[k] == 0 {
delete(m, k)
}
}
if len(m) != 0 {
return false
}
return WorkerNodeGroupConfigurationSliceTaintsEqual(a, b) && WorkerNodeGroupConfigurationsLabelsMapEqual(a, b)
}
func WorkerNodeGroupConfigurationSliceTaintsEqual(a, b []WorkerNodeGroupConfiguration) bool {
m := make(map[string][]corev1.Taint, len(a))
for _, nodeGroup := range a {
m[nodeGroup.Name] = nodeGroup.Taints
}
for _, nodeGroup := range b {
if _, ok := m[nodeGroup.Name]; !ok {
// this method is not concerned with added/removed node groups,
// only with the comparison of taints on existing node groups
// if a node group is present in a but not b, or vise versa, it's immaterial
continue
} else {
if !TaintsSliceEqual(m[nodeGroup.Name], nodeGroup.Taints) {
return false
}
}
}
return true
}
func WorkerNodeGroupConfigurationsLabelsMapEqual(a, b []WorkerNodeGroupConfiguration) bool {
m := make(map[string]map[string]string, len(a))
for _, nodeGroup := range a {
m[nodeGroup.Name] = nodeGroup.Labels
}
for _, nodeGroup := range b {
if _, ok := m[nodeGroup.Name]; !ok {
// this method is not concerned with added/removed node groups,
// only with the comparison of labels on existing node groups
// if a node group is present in a but not b, or vise versa, it's immaterial
continue
} else {
if !MapEqual(m[nodeGroup.Name], nodeGroup.Labels) {
return false
}
}
}
return true
}
type ClusterNetwork struct {
// Comma-separated list of CIDR blocks to use for pod and service subnets.
// Defaults to 192.168.0.0/16 for pod subnet.
Pods Pods `json:"pods,omitempty"`
Services Services `json:"services,omitempty"`
// Deprecated. Use CNIConfig
CNI CNI `json:"cni,omitempty"`
// CNIConfig specifies the CNI plugin to be installed in the cluster
CNIConfig *CNIConfig `json:"cniConfig,omitempty"`
DNS DNS `json:"dns,omitempty"`
Nodes *Nodes `json:"nodes,omitempty"`
}
func (n *ClusterNetwork) Equal(o *ClusterNetwork) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
if !CNIPluginSame(*n, *o) {
return false
}
oldCNIConfig := getCNIConfig(o)
newCNIConfig := getCNIConfig(n)
if !newCNIConfig.Equal(oldCNIConfig) {
return false
}
return n.Pods.Equal(&o.Pods) &&
n.Services.Equal(&o.Services) &&
n.DNS.Equal(&o.DNS) &&
n.Nodes.Equal(o.Nodes)
}
func getCNIConfig(cn *ClusterNetwork) *CNIConfig {
/* Only needed since we're introducing CNIConfig to replace the deprecated CNI field. This way we can compare the individual fields
for the CNI plugin configuration*/
var tempCNIConfig *CNIConfig
if cn.CNIConfig == nil {
// This is for upgrading from release-0.7, to ensure that all oCNIConfig fields, such as policyEnforcementMode have the default values
switch cn.CNI {
case Cilium, CiliumEnterprise:
tempCNIConfig = &CNIConfig{Cilium: &CiliumConfig{}}
case Kindnetd:
tempCNIConfig = &CNIConfig{Kindnetd: &KindnetdConfig{}}
}
} else {
tempCNIConfig = cn.CNIConfig
}
return tempCNIConfig
}
func (n *Pods) Equal(o *Pods) bool {
return SliceEqual(n.CidrBlocks, o.CidrBlocks)
}
func (n *Services) Equal(o *Services) bool {
return SliceEqual(n.CidrBlocks, o.CidrBlocks)
}
func (n *DNS) Equal(o *DNS) bool {
return n.ResolvConf.Equal(o.ResolvConf)
}
func (n *CNIConfig) Equal(o *CNIConfig) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
if !n.Cilium.Equal(o.Cilium) {
return false
}
if !n.Kindnetd.Equal(o.Kindnetd) {
return false
}
return true
}
func (n *CiliumConfig) Equal(o *CiliumConfig) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
return n.PolicyEnforcementMode == o.PolicyEnforcementMode
}
func (n *KindnetdConfig) Equal(o *KindnetdConfig) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
return true
}
func UsersSliceEqual(a, b []UserConfiguration) bool {
if len(a) != len(b) {
return false
}
m := make(map[string][]string, len(a))
for _, v := range a {
m[v.Name] = v.SshAuthorizedKeys
}
for _, v := range b {
if _, ok := m[v.Name]; !ok {
return false
}
if !SliceEqual(v.SshAuthorizedKeys, m[v.Name]) {
return false
}
}
return true
}
func CNIPluginSame(n ClusterNetwork, o ClusterNetwork) bool {
if n.CNI != "" {
/*This shouldn't be required since we set CNIConfig and unset CNI as part of cluster_defaults. However, while upgrading an existing cluster, the eks-a controller
does not set any defaults (no mutating webhook), so it gets stuck in an error loop. Adding these checks to avoid that. We can remove it when removing the CNI field
in a later release*/
return o.CNI == n.CNI
}
if n.CNIConfig != nil {
if o.CNI != "" {
switch o.CNI {
case Cilium, CiliumEnterprise:
if n.CNIConfig.Cilium == nil {
return false
}
case Kindnetd:
if n.CNIConfig.Kindnetd == nil {
return false
}
default:
return false
}
return true
}
if o.CNIConfig != nil {
if (n.CNIConfig.Cilium != nil && o.CNIConfig.Cilium == nil) || (n.CNIConfig.Cilium == nil && o.CNIConfig.Cilium != nil) {
return false
}
if (n.CNIConfig.Kindnetd != nil && o.CNIConfig.Kindnetd == nil) || (n.CNIConfig.Kindnetd == nil && o.CNIConfig.Kindnetd != nil) {
return false
}
}
}
return true
}
func SliceEqual(a, b []string) bool {
if len(a) != len(b) {
return false
}
m := make(map[string]int, len(a))
for _, v := range a {
m[v]++
}
for _, v := range b {
if _, ok := m[v]; !ok {
return false
}
m[v] -= 1
if m[v] == 0 {
delete(m, v)
}
}
return len(m) == 0
}
func RefSliceEqual(a, b []Ref) bool {
if len(a) != len(b) {
return false
}
m := make(map[string]int, len(a))
for _, v := range a {
m[v.Name+v.Kind]++
}
for _, v := range b {
if _, ok := m[v.Name+v.Kind]; !ok {
return false
}
m[v.Name+v.Kind] -= 1
if m[v.Name+v.Kind] == 0 {
delete(m, v.Name+v.Kind)
}
}
return len(m) == 0
}
type Pods struct {
CidrBlocks []string `json:"cidrBlocks,omitempty"`
}
type Services struct {
CidrBlocks []string `json:"cidrBlocks,omitempty"`
}
type DNS struct {
// ResolvConf refers to the DNS resolver configuration
ResolvConf *ResolvConf `json:"resolvConf,omitempty"`
}
type ResolvConf struct {
// Path defines the path to the file that contains the DNS resolver configuration
Path string `json:"path,omitempty"`
}
type Nodes struct {
// CIDRMaskSize defines the mask size for node cidr in the cluster, default for ipv4 is 24. This is an optional field
CIDRMaskSize *int `json:"cidrMaskSize,omitempty"`
}
// Equal compares two Nodes definitions and return true if the are equivalent.
func (n *Nodes) Equal(o *Nodes) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
if n.CIDRMaskSize == o.CIDRMaskSize {
return true
}
if n.CIDRMaskSize == nil || o.CIDRMaskSize == nil {
return false
}
return *n.CIDRMaskSize == *o.CIDRMaskSize
}
func (n *ResolvConf) Equal(o *ResolvConf) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
return n.Path == o.Path
}
type KubernetesVersion string
const (
Kube118 KubernetesVersion = "1.18"
Kube119 KubernetesVersion = "1.19"
Kube120 KubernetesVersion = "1.20"
Kube121 KubernetesVersion = "1.21"
Kube122 KubernetesVersion = "1.22"
Kube123 KubernetesVersion = "1.23"
Kube124 KubernetesVersion = "1.24"
Kube125 KubernetesVersion = "1.25"
Kube126 KubernetesVersion = "1.26"
)
type CNI string
type CiliumPolicyEnforcementMode string
type CNIConfig struct {
Cilium *CiliumConfig `json:"cilium,omitempty"`
Kindnetd *KindnetdConfig `json:"kindnetd,omitempty"`
}
type CiliumConfig struct {
// PolicyEnforcementMode determines communication allowed between pods. Accepted values are default, always, never.
PolicyEnforcementMode CiliumPolicyEnforcementMode `json:"policyEnforcementMode,omitempty"`
}
type KindnetdConfig struct{}
const (
Cilium CNI = "cilium"
CiliumEnterprise CNI = "cilium-enterprise"
Kindnetd CNI = "kindnetd"
)
var validCNIs = map[CNI]struct{}{
Cilium: {},
Kindnetd: {},
}
const (
CiliumPolicyModeDefault CiliumPolicyEnforcementMode = "default"
CiliumPolicyModeAlways CiliumPolicyEnforcementMode = "always"
CiliumPolicyModeNever CiliumPolicyEnforcementMode = "never"
)
var validCiliumPolicyEnforcementModes = map[CiliumPolicyEnforcementMode]bool{
CiliumPolicyModeAlways: true,
CiliumPolicyModeDefault: true,
CiliumPolicyModeNever: true,
}
// ClusterStatus defines the observed state of Cluster.
type ClusterStatus struct {
// Descriptive message about a fatal problem while reconciling a cluster
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`
// EksdReleaseRef defines the properties of the EKS-D object on the cluster
EksdReleaseRef *EksdReleaseRef `json:"eksdReleaseRef,omitempty"`
// +optional
Conditions []clusterv1.Condition `json:"conditions,omitempty"`
}
type EksdReleaseRef struct {
// ApiVersion refers to the EKS-D API version
ApiVersion string `json:"apiVersion"`
// Kind refers to the Release kind for the EKS-D object
Kind string `json:"kind"`
// Name refers to the name of the EKS-D object on the cluster
Name string `json:"name"`
// Namespace refers to the namespace for the EKS-D release resources
Namespace string `json:"namespace"`
}
type BundlesRef struct {
// APIVersion refers to the Bundles APIVersion
APIVersion string `json:"apiVersion"`
// Name refers to the name of the Bundles object in the cluster
Name string `json:"name"`
// Namespace refers to the Bundles's namespace
Namespace string `json:"namespace"`
}
func (b *BundlesRef) Equal(o *BundlesRef) bool {
if b == nil || o == nil {
return b == o
}
return b.APIVersion == o.APIVersion && b.Name == o.Name && b.Namespace == o.Namespace
}
type Ref struct {
Kind string `json:"kind,omitempty"`
Name string `json:"name,omitempty"`
}
func (n *Ref) Equal(o *Ref) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
return n.Kind == o.Kind && n.Name == o.Name
}
// +kubebuilder:object:generate=false
// Interface for getting DatacenterRef fields for Cluster type.
type ProviderRefAccessor interface {
Kind() string
Name() string
}
// +kubebuilder:object:generate=false
// Interface for getting Kind field for Cluster type.
type KindAccessor interface {
Kind() string
ExpectedKind() string
}
// ExternalEtcdConfiguration defines the configuration options for using unstacked etcd topology.
type ExternalEtcdConfiguration struct {
Count int `json:"count,omitempty"`
// MachineGroupRef defines the machine group configuration for the etcd machines.
MachineGroupRef *Ref `json:"machineGroupRef,omitempty"`
}
func (n *ExternalEtcdConfiguration) Equal(o *ExternalEtcdConfiguration) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
return n.Count == o.Count && n.MachineGroupRef.Equal(o.MachineGroupRef)
}
type ManagementCluster struct {
Name string `json:"name,omitempty"`
}
func (n *ManagementCluster) Equal(o ManagementCluster) bool {
return n.Name == o.Name
}
type PodIAMConfig struct {
ServiceAccountIssuer string `json:"serviceAccountIssuer"`
}
func (n *PodIAMConfig) Equal(o *PodIAMConfig) bool {
if n == o {
return true
}
if n == nil || o == nil {
return false
}
return n.ServiceAccountIssuer == o.ServiceAccountIssuer
}
// AutoScalingConfiguration defines the configuration for the node autoscaling feature.
type AutoScalingConfiguration struct {
// MinCount defines the minimum number of nodes for the associated resource group.
// +optional
MinCount int `json:"minCount,omitempty"`
// MaxCount defines the maximum number of nodes for the associated resource group.
// +optional
MaxCount int `json:"maxCount,omitempty"`
}
// ControlPlaneUpgradeRolloutStrategy indicates rollout strategy for cluster.
type ControlPlaneUpgradeRolloutStrategy struct {
Type string `json:"type,omitempty"`
RollingUpdate ControlPlaneRollingUpdateParams `json:"rollingUpdate,omitempty"`
}
// ControlPlaneRollingUpdateParams is API for rolling update strategy knobs.
type ControlPlaneRollingUpdateParams struct {
MaxSurge int `json:"maxSurge"`
}
// WorkerNodesUpgradeRolloutStrategy indicates rollout strategy for cluster.
type WorkerNodesUpgradeRolloutStrategy struct {
Type string `json:"type,omitempty"`
RollingUpdate WorkerNodesRollingUpdateParams `json:"rollingUpdate,omitempty"`
}
// WorkerNodesRollingUpdateParams is API for rolling update strategy knobs.
type WorkerNodesRollingUpdateParams struct {
MaxSurge int `json:"maxSurge"`
MaxUnavailable int `json:"maxUnavailable"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// Cluster is the Schema for the clusters API.
type Cluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ClusterSpec `json:"spec,omitempty"`
Status ClusterStatus `json:"status,omitempty"`
}
func (c *Cluster) GetConditions() clusterv1.Conditions {
return c.Status.Conditions
}
func (c *Cluster) SetConditions(conditions clusterv1.Conditions) {
c.Status.Conditions = conditions
}
// +kubebuilder:object:generate=false
// Same as Cluster except stripped down for generation of yaml file during generate clusterconfig.
type ClusterGenerate struct {
metav1.TypeMeta `json:",inline"`
ObjectMeta `json:"metadata,omitempty"`
Spec ClusterSpec `json:"spec,omitempty"`
}
func (c *Cluster) Kind() string {
return c.TypeMeta.Kind
}
func (c *Cluster) ExpectedKind() string {
return ClusterKind
}
func (c *Cluster) PausedAnnotation() string {
return pausedAnnotation
}
func (c *Cluster) ControlPlaneAnnotation() string {
return controlPlaneAnnotation
}
func (c *Cluster) ResourceType() string {
return clusterResourceType
}
func (c *Cluster) EtcdAnnotation() string {
return etcdAnnotation
}
func (c *Cluster) IsSelfManaged() bool {
return c.Spec.ManagementCluster.Name == "" || c.Spec.ManagementCluster.Name == c.Name
}
func (c *Cluster) SetManagedBy(managementClusterName string) {
if c.Annotations == nil {
c.Annotations = map[string]string{}
}
c.Annotations[managementAnnotation] = managementClusterName
c.Spec.ManagementCluster.Name = managementClusterName
}
func (c *Cluster) SetSelfManaged() {
c.Spec.ManagementCluster.Name = c.Name
}
func (c *ClusterGenerate) SetSelfManaged() {
c.Spec.ManagementCluster.Name = c.Name
}
func (c *Cluster) ManagementClusterEqual(s2 *Cluster) bool {
return c.IsSelfManaged() && s2.IsSelfManaged() || c.Spec.ManagementCluster.Equal(s2.Spec.ManagementCluster)
}
func (c *Cluster) MachineConfigRefs() []Ref {
machineConfigRefMap := make(refSet, 1)
machineConfigRefMap.addIfNotNil(c.Spec.ControlPlaneConfiguration.MachineGroupRef)
for _, m := range c.Spec.WorkerNodeGroupConfigurations {
machineConfigRefMap.addIfNotNil(m.MachineGroupRef)
}
if c.Spec.ExternalEtcdConfiguration != nil {
machineConfigRefMap.addIfNotNil(c.Spec.ExternalEtcdConfiguration.MachineGroupRef)
}
return machineConfigRefMap.toSlice()
}
type refSet map[Ref]struct{}
func (r refSet) addIfNotNil(ref *Ref) bool {
if ref != nil {
return r.add(*ref)
}
return false
}
func (r refSet) add(ref Ref) bool {
if _, present := r[ref]; !present {
r[ref] = struct{}{}
return true
} else {
return false
}
}
func (r refSet) toSlice() []Ref {
refs := make([]Ref, 0, len(r))
for ref := range r {
refs = append(refs, ref)
}
return refs
}
func (c *Cluster) ConvertConfigToConfigGenerateStruct() *ClusterGenerate {
namespace := defaultEksaNamespace
if c.Namespace != "" {
namespace = c.Namespace
}
config := &ClusterGenerate{
TypeMeta: c.TypeMeta,
ObjectMeta: ObjectMeta{
Name: c.Name,
Annotations: c.Annotations,
Namespace: namespace,
},
Spec: c.Spec,
}
return config
}
func (c *Cluster) IsManaged() bool {
return !c.IsSelfManaged()
}
func (c *Cluster) ManagedBy() string {
return c.Spec.ManagementCluster.Name
}
// +kubebuilder:object:root=true
// ClusterList contains a list of Cluster.
type ClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Cluster `json:"items"`
}
func init() {
SchemeBuilder.Register(&Cluster{}, &ClusterList{})
}