/
machinepool.go
72 lines (61 loc) · 2.4 KB
/
machinepool.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
package validation
import (
"fmt"
"strings"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/aws"
)
var (
validArchitectures = map[types.Architecture]bool{
types.ArchitectureAMD64: true,
types.ArchitectureARM64: true,
}
// validArchitectureValues lists the supported arches for AWS
validArchitectureValues = func() []string {
v := make([]string, 0, len(validArchitectures))
for m := range validArchitectures {
v = append(v, string(m))
}
return v
}()
)
// ValidateMachinePool checks that the specified machine pool is valid.
func ValidateMachinePool(platform *aws.Platform, p *aws.MachinePool, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
for i, zone := range p.Zones {
if !strings.HasPrefix(zone, platform.Region) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("zones").Index(i), zone, fmt.Sprintf("Zone not in configured region (%s)", platform.Region)))
}
}
if p.IOPS < 0 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("iops"), p.IOPS, "Storage IOPS must be positive"))
}
if p.Size < 0 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("size"), p.Size, "Storage size must be positive"))
}
return allErrs
}
// ValidateAMIID check the AMI ID is set for a machine pool.
func ValidateAMIID(platform *aws.Platform, p *aws.MachinePool, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
pool := &aws.MachinePool{AMIID: platform.AMIID}
pool.Set(platform.DefaultMachinePlatform)
pool.Set(p)
// regions is a list of regions for which the user should set AMI ID as copying the AMI to these regions
// is known to not be supported.
regions := sets.NewString("us-iso-east-1", "cn-north-1", "cn-northwest-1")
if pool.AMIID == "" && regions.Has(platform.Region) {
allErrs = append(allErrs, field.Required(fldPath, fmt.Sprintf("AMI ID must be provided for regions %s", strings.Join(regions.List(), ", "))))
}
return allErrs
}
// ValidateMachinePoolArchitecture checks that a valid architecture is set for a machine pool.
func ValidateMachinePoolArchitecture(pool *types.MachinePool, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if !validArchitectures[pool.Architecture] {
allErrs = append(allErrs, field.NotSupported(fldPath, pool.Architecture, validArchitectureValues))
}
return allErrs
}