github.com/kubernetes-incubator/kube-aws@v0.16.4/pkg/api/mixed_instances.go (about) 1 package api 2 3 import "fmt" 4 5 type MixedInstances struct { 6 Enabled bool `yaml:"enabled,omitempty"` 7 OnDemandAllocationStrategy string `yaml:"onDemandAllocationStrategy,omitempty"` 8 OnDemandBaseCapacity int `yaml:"onDemandBaseCapacity,omitempty"` 9 OnDemandPercentageAboveBaseCapacity int `yaml:"onDemandPercentageAboveBaseCapacity,omitempty"` 10 SpotAllocationStrategy string `yaml:"spotAllocationStrategy,omitempty"` 11 SpotInstancePools int `yaml:"spotInstancePools,omitempty"` 12 SpotMaxPrice string `yaml:"spotMaxPrice,omitempty"` 13 InstanceTypes []string `yaml:"instanceTypes,omitempty"` 14 } 15 16 func (mi MixedInstances) Validate() error { 17 // See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-autoscaling-autoscalinggroup-instancesdistribution.html for valid values 18 if mi.OnDemandAllocationStrategy != "" && mi.OnDemandAllocationStrategy != "prioritized" { 19 return fmt.Errorf("`mixedInstances.onDemandAllocationStrategy` must be equal to 'prioritized' if specified") 20 } 21 if mi.OnDemandBaseCapacity < 0 { 22 return fmt.Errorf("`mixedInstances.onDemandBaseCapacity` (%d) must be zero or greater if specified", mi.OnDemandBaseCapacity) 23 } 24 if mi.OnDemandPercentageAboveBaseCapacity < 0 || mi.OnDemandPercentageAboveBaseCapacity > 100 { 25 return fmt.Errorf("`mixedInstances.onDemandPercentageAboveBaseCapacity` (%d) must be in range 0-100", mi.OnDemandPercentageAboveBaseCapacity) 26 } 27 if mi.SpotAllocationStrategy != "" && mi.SpotAllocationStrategy != "lowest-price" { 28 return fmt.Errorf("`mixedInstances.spotAllocationStrategy` must be equal to 'lowest-price' if specified") 29 } 30 if mi.SpotInstancePools < 0 || mi.SpotInstancePools > 20 { 31 return fmt.Errorf("`mixedInstances.spotInstancePools` (%d) must be in range 0-20", mi.SpotInstancePools) 32 } 33 if len(mi.SpotMaxPrice) > 255 { 34 return fmt.Errorf("`mixedInstances.spotMaxPrice` can have a maximum length of 255") 35 } 36 37 return nil 38 }