Enable min size 0 in gce

This commit is contained in:
Marcin Wielgus 2017-05-16 17:11:26 +02:00
parent faad1da0ad
commit bfa105e959
3 changed files with 14 additions and 6 deletions

View File

@ -287,7 +287,7 @@ func (asg *Asg) TemplateNodeInfo() (*schedulercache.NodeInfo, error) {
} }
func buildAsgFromSpec(value string, awsManager *AwsManager) (*Asg, error) { func buildAsgFromSpec(value string, awsManager *AwsManager) (*Asg, error) {
spec, err := dynamic.SpecFromString(value) spec, err := dynamic.SpecFromString(value, false)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse node group spec: %v", err) return nil, fmt.Errorf("failed to parse node group spec: %v", err)

View File

@ -237,7 +237,7 @@ func (mig *Mig) TemplateNodeInfo() (*schedulercache.NodeInfo, error) {
} }
func buildMig(value string, gceManager *GceManager) (*Mig, error) { func buildMig(value string, gceManager *GceManager) (*Mig, error) {
spec, err := dynamic.SpecFromString(value) spec, err := dynamic.SpecFromString(value, true)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse node group spec: %v", err) return nil, fmt.Errorf("failed to parse node group spec: %v", err)

View File

@ -30,16 +30,18 @@ type NodeGroupSpec struct {
MinSize int `json:"minSize"` MinSize int `json:"minSize"`
// Max size of the autoscaling target // Max size of the autoscaling target
MaxSize int `json:"maxSize"` MaxSize int `json:"maxSize"`
supportScaleToZero bool
} }
// SpecFromString parses a node group spec represented in the form of `<minSize>:<maxSize>:<name>` and produces a node group spec object // SpecFromString parses a node group spec represented in the form of `<minSize>:<maxSize>:<name>` and produces a node group spec object
func SpecFromString(value string) (*NodeGroupSpec, error) { func SpecFromString(value string, supportScaleToZero bool) (*NodeGroupSpec, error) {
tokens := strings.SplitN(value, ":", 3) tokens := strings.SplitN(value, ":", 3)
if len(tokens) != 3 { if len(tokens) != 3 {
return nil, fmt.Errorf("wrong nodes configuration: %s", value) return nil, fmt.Errorf("wrong nodes configuration: %s", value)
} }
spec := NodeGroupSpec{} spec := NodeGroupSpec{supportScaleToZero: supportScaleToZero}
if size, err := strconv.Atoi(tokens[0]); err == nil { if size, err := strconv.Atoi(tokens[0]); err == nil {
spec.MinSize = size spec.MinSize = size
@ -64,9 +66,15 @@ func SpecFromString(value string) (*NodeGroupSpec, error) {
// Validate produces an error if there's an invalid field in the node group spec // Validate produces an error if there's an invalid field in the node group spec
func (s NodeGroupSpec) Validate() error { func (s NodeGroupSpec) Validate() error {
if s.supportScaleToZero {
if s.MinSize < 0 {
return fmt.Errorf("min size must be >= 0")
}
} else {
if s.MinSize <= 0 { if s.MinSize <= 0 {
return fmt.Errorf("min size must be >= 1") return fmt.Errorf("min size must be >= 1")
} }
}
if s.MaxSize < s.MinSize { if s.MaxSize < s.MinSize {
return fmt.Errorf("max size must be greater or equal to min size") return fmt.Errorf("max size must be greater or equal to min size")
} }