Skip to content

Commit

Permalink
Merge pull request coreos#222 from iameli/spot-instances
Browse files Browse the repository at this point in the history
kube-aws: add parameter for spot price
  • Loading branch information
colhom committed Feb 1, 2016
2 parents 0322996 + 766a30b commit 674dec5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions multi-node/aws/cluster.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ externalDNSName:
# Disk size (GiB) for worker nodes
#workerRootVolumeSize: 30

# Price (Dollars) to bid for spot instances. Omit for on-demand instances.
# workerSpotPrice: "0.05"

# Location of kube-aws artifacts used to deploy a new
# Kubernetes cluster. The necessary artifacts are already
# available in a public S3 bucket matching the version
Expand Down
8 changes: 8 additions & 0 deletions multi-node/aws/pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ func (c *Cluster) Create(tlsConfig *TLSConfig) error {
})
}

if c.cfg.WorkerSpotPrice != "" {
parameters = append(parameters, &cloudformation.Parameter{
ParameterKey: aws.String(parWorkerSpotPrice),
ParameterValue: aws.String(c.cfg.WorkerSpotPrice),
UsePreviousValue: aws.Bool(true),
})
}

if c.cfg.AvailabilityZone != "" {
parameters = append(parameters, &cloudformation.Parameter{
ParameterKey: aws.String(parAvailabilityZone),
Expand Down
1 change: 1 addition & 0 deletions multi-node/aws/pkg/cluster/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Config struct {
WorkerCount int `yaml:"workerCount"`
WorkerInstanceType string `yaml:"workerInstanceType"`
WorkerRootVolumeSize int `yaml:"workerRootVolumeSize"`
WorkerSpotPrice string `yaml:"workerSpotPrice"`
VPCCIDR string `yaml:"vpcCIDR"`
InstanceCIDR string `yaml:"instanceCIDR"`
ControllerIP string `yaml:"controllerIP"`
Expand Down
24 changes: 24 additions & 0 deletions multi-node/aws/pkg/cluster/stack_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
parWorkerKey = "WorkerKey"
parWorkerCount = "WorkerCount"
parNameWorkerRootVolumeSize = "WorkerRootVolumeSize"
parWorkerSpotPrice = "WorkerSpotPrice"
parAvailabilityZone = "AvailabilityZone"
parVPCCIDR = "VPCCIDR"
parInstanceCIDR = "InstanceCIDR"
Expand Down Expand Up @@ -500,6 +501,13 @@ func StackTemplateBody(defaultArtifactURL string) (string, error) {
},
},
},
"SpotPrice": map[string]interface{}{
"Fn::If": []interface{}{
"UseWorkerSpotInstances",
newRef(parWorkerSpotPrice),
newRef("AWS::NoValue"),
},
},
},
}

Expand Down Expand Up @@ -603,6 +611,12 @@ func StackTemplateBody(defaultArtifactURL string) (string, error) {
"Description": "Worker root volume size (GiB)",
}

par[parWorkerSpotPrice] = map[string]interface{}{
"Type": "String",
"Default": "",
"Description": "Spot instance price for workers (optional, omit for on-demand instances)",
}

par[parAvailabilityZone] = map[string]interface{}{
"Type": "String",
"Default": "",
Expand Down Expand Up @@ -668,6 +682,16 @@ func StackTemplateBody(defaultArtifactURL string) (string, error) {
"",
},
},
"UseWorkerSpotInstances": map[string]interface{}{
"Fn::Not": []interface{}{
map[string]interface{}{
"Fn::Equals": []interface{}{
newRef(parWorkerSpotPrice),
"",
},
},
},
},
}

tmpl := map[string]interface{}{
Expand Down

0 comments on commit 674dec5

Please sign in to comment.