Add support for spot instances

Fixes #58
This commit is contained in:
Justin Santa Barbara 2016-07-10 23:56:16 -04:00
parent 4ac0395a9f
commit f771c2af4c
4 changed files with 16 additions and 0 deletions

View File

@ -12,6 +12,9 @@ launchConfiguration/{{ $m.Name }}.masters.{{ ClusterName }}:
userData: resources/nodeup.sh _kubernetes_master
rootVolumeSize: {{ or $m.Spec.RootVolumeSize "20" }}
rootVolumeType: {{ or $m.Spec.RootVolumeType "gp2" }}
{{ if $m.Spec.MaxPrice }}
spotPrice: "{{ $m.Spec.MaxPrice }}"
{{ end }}
autoscalingGroup/{{ $m.Name}}.masters.{{ ClusterName }}:
minSize: 1

View File

@ -56,6 +56,9 @@ launchConfiguration/{{ $nodeset.Name }}.{{ ClusterName }}:
userData: resources/nodeup.sh _kubernetes_pool
rootVolumeSize: {{ or $nodeset.Spec.RootVolumeSize "20" }}
rootVolumeType: {{ or $nodeset.Spec.RootVolumeType "gp2" }}
{{ if $nodeset.Spec.MaxPrice }}
spotPrice: "{{ $nodeset.Spec.MaxPrice }}"
{{ end }}
autoscalingGroup/{{ $nodeset.Name }}.{{ ClusterName }}:
launchConfiguration: launchConfiguration/{{ $nodeset.Name }}.{{ ClusterName }}

View File

@ -41,6 +41,9 @@ type InstanceGroupSpec struct {
RootVolumeType *string `json:"rootVolumeType",omitempty`
Zones []string `json:"zones,omitempty"`
// MaxPrice indicates this is a spot-pricing group, with the specified value as our max-price bid
MaxPrice *string `json:"maxPrice,omitempty"`
}
// PerformAssignmentsInstanceGroups populates InstanceGroups with default values

View File

@ -31,6 +31,9 @@ type LaunchConfiguration struct {
// RootVolumeType is the type of the EBS root volume to use (e.g. gp2)
RootVolumeType *string
// SpotPrice is set to the spot-price bid if this is a spot pricing request
SpotPrice *string
ID *string
}
@ -85,6 +88,7 @@ func (e *LaunchConfiguration) Find(c *fi.Context) (*LaunchConfiguration, error)
SSHKey: &SSHKey{Name: lc.KeyName},
AssociatePublicIP: lc.AssociatePublicIpAddress,
IAMInstanceProfile: &IAMInstanceProfile{Name: lc.IamInstanceProfile},
SpotPrice: lc.SpotPrice,
}
securityGroups := []*SecurityGroup{}
@ -215,6 +219,7 @@ func (_ *LaunchConfiguration) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *La
}
request.SecurityGroups = securityGroupIDs
request.AssociatePublicIpAddress = e.AssociatePublicIP
request.SpotPrice = e.SpotPrice
// Build up the actual block device mappings
{
@ -281,6 +286,7 @@ type terraformLaunchConfiguration struct {
RootBlockDevice *terraformBlockDevice `json:"root_block_device,omitempty"`
EphemeralBlockDevice []*terraformBlockDevice `json:"ephemeral_block_device,omitempty"`
Lifecycle *terraformLifecycle `json:"lifecycle,omitempty"`
SpotPrice *string `json:"spot_price,omitempty"`
}
type terraformBlockDevice struct {
@ -313,6 +319,7 @@ func (_ *LaunchConfiguration) RenderTerraform(t *terraform.TerraformTarget, a, e
NamePrefix: fi.String(*e.Name + "-"),
ImageID: image.ImageId,
InstanceType: e.InstanceType,
SpotPrice: e.SpotPrice,
}
if e.SSHKey != nil {