-
Notifications
You must be signed in to change notification settings - Fork 272
/
snowmachineconfig.go
78 lines (65 loc) 路 2.92 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
package v1alpha1
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/aws/eks-anywhere/pkg/logger"
)
const (
SnowMachineConfigKind = "SnowMachineConfig"
DefaultSnowSshKeyName = "default"
DefaultSnowInstanceType = SbeCLarge
DefaultSnowPhysicalNetworkConnectorType = SFPPlus
MinimumContainerVolumeSize = 8
)
// Used for generating yaml 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: "",
InstanceType: DefaultSnowInstanceType,
SshKeyName: DefaultSnowSshKeyName,
PhysicalNetworkConnector: DefaultSnowPhysicalNetworkConnectorType,
},
}
}
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.ContainersVolume != nil && config.Spec.ContainersVolume.Size < MinimumContainerVolumeSize {
return fmt.Errorf("SnowMachineConfig ContainersVolume.Size must be no smaller than %d Gi", MinimumContainerVolumeSize)
}
// TODO: temporarily remove this validation since `devices` is a newly added, required field.
// This validation runs in snowmachineconfig webhook and ValidateUpdate fails when upgrading from older eks-a version
// without the `devices` field. We will add this validation back once users update their clusters to latest version.
// if len(config.Spec.Devices) == 0 {
// return errors.New("SnowMachineConfig Devices must contain at least one device IP")
// }
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)
}
}