-
Notifications
You must be signed in to change notification settings - Fork 274
/
snowmachineconfig.go
139 lines (116 loc) Β· 5.08 KB
/
snowmachineconfig.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
package v1alpha1
import (
"errors"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/aws/eks-anywhere/pkg/logger"
)
const (
SnowMachineConfigKind = "SnowMachineConfig"
DefaultSnowSSHKeyName = ""
DefaultSnowInstanceType = SbeCLarge
DefaultSnowPhysicalNetworkConnectorType = SFPPlus
DefaultOSFamily = Ubuntu
MinimumContainerVolumeSizeUbuntu = 8
MinimumContainerVolumeSizeBottlerocket = 25
)
// NewSnowMachineConfigGenerate generates snowMachineConfig example for generate clusterconfig command.
func NewSnowMachineConfigGenerate(name string) *SnowMachineConfigGenerate {
return &SnowMachineConfigGenerate{
TypeMeta: metav1.TypeMeta{
Kind: SnowMachineConfigKind,
APIVersion: SchemeBuilder.GroupVersion.String(),
},
ObjectMeta: ObjectMeta{
Name: name,
},
Spec: SnowMachineConfigSpec{
AMIID: "",
Devices: []string{""},
InstanceType: DefaultSnowInstanceType,
SshKeyName: DefaultSnowSSHKeyName,
PhysicalNetworkConnector: DefaultSnowPhysicalNetworkConnectorType,
OSFamily: DefaultOSFamily,
Network: SnowNetwork{
DirectNetworkInterfaces: []SnowDirectNetworkInterface{
{
Index: 1,
DHCP: true,
Primary: true,
},
},
},
},
}
}
func (s *SnowMachineConfigGenerate) APIVersion() string {
return s.TypeMeta.APIVersion
}
func (s *SnowMachineConfigGenerate) Kind() string {
return s.TypeMeta.Kind
}
func (s *SnowMachineConfigGenerate) Name() string {
return s.ObjectMeta.Name
}
func validateSnowMachineConfig(config *SnowMachineConfig) error {
if config.Spec.InstanceType != SbeCLarge && config.Spec.InstanceType != SbeCXLarge && config.Spec.InstanceType != SbeC2XLarge && config.Spec.InstanceType != SbeC4XLarge {
return fmt.Errorf("SnowMachineConfig InstanceType %s is not supported, please use one of the following: %s, %s, %s, %s ", config.Spec.InstanceType, SbeCLarge, SbeCXLarge, SbeC2XLarge, SbeC4XLarge)
}
if config.Spec.PhysicalNetworkConnector != SFPPlus && config.Spec.PhysicalNetworkConnector != QSFP && config.Spec.PhysicalNetworkConnector != RJ45 {
return fmt.Errorf("SnowMachineConfig PhysicalNetworkConnector %s is not supported, please use one of the following: %s, %s, %s ", config.Spec.PhysicalNetworkConnector, SFPPlus, QSFP, RJ45)
}
if len(config.Spec.Devices) == 0 {
return errors.New("SnowMachineConfig Devices must contain at least one device IP")
}
if len(config.Spec.OSFamily) <= 0 {
return errors.New("SnowMachineConfig OSFamily must be specified")
}
if config.Spec.OSFamily != Bottlerocket && config.Spec.OSFamily != Ubuntu {
return fmt.Errorf("SnowMachineConfig OSFamily %s is not supported, please use one of the following: %s, %s", config.Spec.OSFamily, Bottlerocket, Ubuntu)
}
if err := validateSnowMachineConfigNetwork(config.Spec.Network); err != nil {
return err
}
return validateSnowMachineConfigContainerVolume(config)
}
func validateSnowMachineConfigContainerVolume(config *SnowMachineConfig) error {
// The Bottlerocket AWS Variant AMI only has 2 Gi of data volume, which is insufficient to store EKS-A and user container volumes.
// Thus the ContainersVolume is required and its size must be no smaller than 25 Gi.
if config.Spec.OSFamily == Bottlerocket {
if config.Spec.ContainersVolume == nil {
return errors.New("SnowMachineConfig ContainersVolume must be specified for Bottlerocket OS")
}
if config.Spec.ContainersVolume.Size < MinimumContainerVolumeSizeBottlerocket {
return fmt.Errorf("SnowMachineConfig ContainersVolume.Size must be no smaller than %d Gi for Bottlerocket OS", MinimumContainerVolumeSizeBottlerocket)
}
}
if config.Spec.OSFamily == Ubuntu && config.Spec.ContainersVolume != nil && config.Spec.ContainersVolume.Size < MinimumContainerVolumeSizeUbuntu {
return fmt.Errorf("SnowMachineConfig ContainersVolume.Size must be no smaller than %d Gi for Ubuntu OS", MinimumContainerVolumeSizeUbuntu)
}
return nil
}
func validateSnowMachineConfigNetwork(network SnowNetwork) error {
if len(network.DirectNetworkInterfaces) <= 0 {
return errors.New("SnowMachineConfig Network.DirectNetworkInterfaces length must be no smaller than 1")
}
primaryDNICount := 0
for _, dni := range network.DirectNetworkInterfaces {
if dni.Primary {
primaryDNICount++
}
}
if primaryDNICount != 1 {
return errors.New("SnowMachineConfig Network.DirectNetworkInterfaces list must contain one and only one primary DNI")
}
return nil
}
func setSnowMachineConfigDefaults(config *SnowMachineConfig) {
if config.Spec.InstanceType == "" {
config.Spec.InstanceType = DefaultSnowInstanceType
logger.V(1).Info("SnowMachineConfig InstanceType is empty. Using default", "default instance type", DefaultSnowInstanceType)
}
if config.Spec.PhysicalNetworkConnector == "" {
config.Spec.PhysicalNetworkConnector = DefaultSnowPhysicalNetworkConnectorType
logger.V(1).Info("SnowMachineConfig PhysicalNetworkConnector is empty. Using default", "default physical network connector", DefaultSnowPhysicalNetworkConnectorType)
}
}