Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Experimental feature: Spot Fleet support for worker nodes #113

Merged
merged 5 commits into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ format:

.PHONY: test
test: build
./test
./make/test

.PHONY: test-with-cover
test-with-cover: build
./test with-cover
./make/test with-cover
2 changes: 1 addition & 1 deletion cmd/nodepool/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func runCmdInit(cmd *cobra.Command, args []string) error {

Next steps:
1. (Optional) Edit %s to parameterize the cluster.
2. Use the "kube-aws nodepool render" command to render the stack template.
2. Use the "kube-aws node-pools render" command to render the stack template.
`

fmt.Printf(successMsg, nodePoolClusterConfigFilePath(), nodePoolClusterConfigFilePath())
Expand Down
45 changes: 4 additions & 41 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"bytes"
"fmt"
"github.com/coreos/kube-aws/netutil"
"github.com/coreos/kube-aws/test/helper"
"gopkg.in/yaml.v2"
"io/ioutil"
"net"
"os"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -896,42 +895,6 @@ func TestValidateExistingVPC(t *testing.T) {
}
}

func withDummyCredentials(fn func(dir string)) {
if _, err := ioutil.ReadDir("temp"); err != nil {
if err := os.Mkdir("temp", 0755); err != nil {
panic(err)
}
}

dir, err := ioutil.TempDir("temp", "dummy-credentials")

if err != nil {
panic(err)
}

defer os.Remove(dir)

for _, pairName := range []string{"ca", "apiserver", "worker", "admin", "etcd", "etcd-client"} {
certFile := fmt.Sprintf("%s/%s.pem", dir, pairName)

if err := ioutil.WriteFile(certFile, []byte("dummycert"), 0644); err != nil {
panic(err)
}

defer os.Remove(certFile)

keyFile := fmt.Sprintf("%s/%s-key.pem", dir, pairName)

if err := ioutil.WriteFile(keyFile, []byte("dummykey"), 0644); err != nil {
panic(err)
}

defer os.Remove(keyFile)
}

fn(dir)
}

func TestValidateUserData(t *testing.T) {
cluster := newDefaultClusterWithDeps(&dummyEncryptService{})

Expand All @@ -941,7 +904,7 @@ func TestValidateUserData(t *testing.T) {
{"us-west-1b", "10.0.2.0/16", nil},
}

withDummyCredentials(func(dir string) {
helper.WithDummyCredentials(func(dir string) {
var stackTemplateOptions = StackTemplateOptions{
TLSAssetsDir: dir,
ControllerTmplFile: "templates/cloud-config-controller",
Expand All @@ -965,7 +928,7 @@ func TestRenderStackTemplate(t *testing.T) {
{"us-west-1b", "10.0.2.0/16", nil},
}

withDummyCredentials(func(dir string) {
helper.WithDummyCredentials(func(dir string) {
var stackTemplateOptions = StackTemplateOptions{
TLSAssetsDir: dir,
ControllerTmplFile: "templates/cloud-config-controller",
Expand Down Expand Up @@ -1049,7 +1012,7 @@ routeTableId: rtb-1a2b3c4d
}
providedConfig.providedEncryptService = &dummyEncryptService{}

withDummyCredentials(func(dummyTlsAssetsDir string) {
helper.WithDummyCredentials(func(dummyTlsAssetsDir string) {
var stackTemplateOptions = StackTemplateOptions{
TLSAssetsDir: dummyTlsAssetsDir,
ControllerTmplFile: "templates/cloud-config-controller",
Expand Down
14 changes: 13 additions & 1 deletion e2e/run
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
KUBE_AWS_CMD=${KUBE_AWS_CMD:-$GOPATH/src/github.com/coreos/kube-aws/bin/kube-aws}
E2E_DIR=$(cd $(dirname $0); pwd)
WORK_DIR=${E2E_DIR}/assets/${KUBE_AWS_CLUSTER_NAME}
NODE_POOL_ASSETS_DIR=${E2E_DIR}/assets/${KUBE_AWS_CLUSTER_NAME}/node-pools/${KUBE_AWS_POOL_NAME}
SRC_DIR=$(cd $(dirname $0); cd ..; pwd)
KUBECONFIG=${WORK_DIR}/kubeconfig

Expand Down Expand Up @@ -210,14 +211,25 @@ ssh_worker() {
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${KUBE_AWS_SSH_KEY} core@$(worker_host) "$@"
}

nodepool() {
nodepool_init() {
cd ${WORK_DIR}

${KUBE_AWS_CMD} node-pools init --node-pool-name ${KUBE_AWS_POOL_NAME} \
--availability-zone ${KUBE_AWS_AVAILABILITY_ZONE} \
--key-name ${KUBE_AWS_KEY_NAME} \
--kms-key-arn ${KUBE_AWS_KMS_KEY_ARN}

if [ "${KUBE_AWS_SPOT_FLEET_ENABLED}" != "" ]; then
echo Writing ${NODE_POOL_ASSETS_DIR}/cluster.yaml
echo -e "worker:\n spotFleet:\n targetCapacity: 3\n" >> ${NODE_POOL_ASSETS_DIR}/cluster.yaml
fi
}

nodepool() {
cd ${WORK_DIR}

nodepool_init

${KUBE_AWS_CMD} node-pools render stack --node-pool-name ${KUBE_AWS_POOL_NAME}
${KUBE_AWS_CMD} node-pools up --node-pool-name ${KUBE_AWS_POOL_NAME} --export
${KUBE_AWS_CMD} node-pools up --node-pool-name ${KUBE_AWS_POOL_NAME} --s3-uri ${KUBE_AWS_S3_URI}
Expand Down
9 changes: 9 additions & 0 deletions filereader/jsontemplate/jsontemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func GetBytes(filename string, data interface{}) ([]byte, error) {
}

func getContextString(buf []byte, offset, lineCount int) string {
// Prevent index out of range errors when we meet errors at the very end of json
bufsize := len(buf)
if offset >= bufsize {
if bufsize > 0 {
offset = bufsize - 1
} else {
offset = 0
}
}

linesSeen := 0
var leftLimit int
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions nodepool/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (c *Cluster) Create(stackBody string, s3URI string) error {
return c.stackProvisioner().CreateStackAndWait(cfSvc, s3Svc, stackBody, s3URI)
}

func (c *Cluster) ValidateStack(stackBody string, s3URI string) (string, error) {
return c.stackProvisioner().Validate(stackBody, s3URI)
}

func (c *Cluster) Info() (*Info, error) {
var info Info
{
Expand Down
22 changes: 22 additions & 0 deletions nodepool/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ProvidedConfig struct {
cfg.KubeClusterSettings `yaml:",inline"`
cfg.WorkerSettings `yaml:",inline"`
cfg.DeploymentSettings `yaml:",inline"`
Worker `yaml:"worker,omitempty"`
EtcdEndpoints string `yaml:"etcdEndpoints,omitempty"`
NodePoolName string `yaml:"nodePoolName,omitempty"`
providedEncryptService cfg.EncryptService
Expand Down Expand Up @@ -133,6 +134,7 @@ func NewDefaultCluster() *ProvidedConfig {
return &ProvidedConfig{
DeploymentSettings: defaults.DeploymentSettings,
WorkerSettings: defaults.WorkerSettings,
Worker: NewDefaultWorker(),
}
}

Expand All @@ -148,6 +150,22 @@ func ClusterFromBytes(data []byte) (*ProvidedConfig, error) {
c.InstanceCIDR = "10.0.1.0/24"
}

//Computed defaults
launchSpecs := []LaunchSpecification{}
for _, spec := range c.Worker.SpotFleet.LaunchSpecifications {
if spec.RootVolumeType == "" {
spec.RootVolumeType = c.Worker.SpotFleet.RootVolumeType
}
if spec.RootVolumeSize == 0 {
spec.RootVolumeSize = c.Worker.SpotFleet.UnitRootVolumeSize * spec.WeightedCapacity
}
if spec.RootVolumeType == "io1" && spec.RootVolumeIOPS == 0 {
spec.RootVolumeIOPS = c.Worker.SpotFleet.UnitRootVolumeIOPS * spec.WeightedCapacity
}
launchSpecs = append(launchSpecs, spec)
}
c.Worker.SpotFleet.LaunchSpecifications = launchSpecs

if err := c.valid(); err != nil {
return nil, fmt.Errorf("invalid cluster: %v", err)
}
Expand Down Expand Up @@ -193,6 +211,10 @@ func (c ProvidedConfig) valid() error {
return err
}

if err := c.Worker.Valid(); err != nil {
return err
}

return nil
}

Expand Down
Loading