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

Commit 31c612e

Browse files
authored
Merge pull request #113 from mumoshu/spot-fleet-for-workers
Experimental feature: Spot Fleet support for worker nodes
2 parents 8fe74d9 + d94e129 commit 31c612e

File tree

14 files changed

+723
-97
lines changed

14 files changed

+723
-97
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ format:
99

1010
.PHONY: test
1111
test: build
12-
./test
12+
./make/test
1313

1414
.PHONY: test-with-cover
1515
test-with-cover: build
16-
./test with-cover
16+
./make/test with-cover

cmd/nodepool/init.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func runCmdInit(cmd *cobra.Command, args []string) error {
129129
130130
Next steps:
131131
1. (Optional) Edit %s to parameterize the cluster.
132-
2. Use the "kube-aws nodepool render" command to render the stack template.
132+
2. Use the "kube-aws node-pools render" command to render the stack template.
133133
`
134134

135135
fmt.Printf(successMsg, nodePoolClusterConfigFilePath(), nodePoolClusterConfigFilePath())

config/config_test.go

+4-41
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import (
44
"bytes"
55
"fmt"
66
"github.com/coreos/kube-aws/netutil"
7+
"github.com/coreos/kube-aws/test/helper"
78
"gopkg.in/yaml.v2"
8-
"io/ioutil"
99
"net"
10-
"os"
1110
"reflect"
1211
"strings"
1312
"testing"
@@ -896,42 +895,6 @@ func TestValidateExistingVPC(t *testing.T) {
896895
}
897896
}
898897

899-
func withDummyCredentials(fn func(dir string)) {
900-
if _, err := ioutil.ReadDir("temp"); err != nil {
901-
if err := os.Mkdir("temp", 0755); err != nil {
902-
panic(err)
903-
}
904-
}
905-
906-
dir, err := ioutil.TempDir("temp", "dummy-credentials")
907-
908-
if err != nil {
909-
panic(err)
910-
}
911-
912-
defer os.Remove(dir)
913-
914-
for _, pairName := range []string{"ca", "apiserver", "worker", "admin", "etcd", "etcd-client"} {
915-
certFile := fmt.Sprintf("%s/%s.pem", dir, pairName)
916-
917-
if err := ioutil.WriteFile(certFile, []byte("dummycert"), 0644); err != nil {
918-
panic(err)
919-
}
920-
921-
defer os.Remove(certFile)
922-
923-
keyFile := fmt.Sprintf("%s/%s-key.pem", dir, pairName)
924-
925-
if err := ioutil.WriteFile(keyFile, []byte("dummykey"), 0644); err != nil {
926-
panic(err)
927-
}
928-
929-
defer os.Remove(keyFile)
930-
}
931-
932-
fn(dir)
933-
}
934-
935898
func TestValidateUserData(t *testing.T) {
936899
cluster := newDefaultClusterWithDeps(&dummyEncryptService{})
937900

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

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

968-
withDummyCredentials(func(dir string) {
931+
helper.WithDummyCredentials(func(dir string) {
969932
var stackTemplateOptions = StackTemplateOptions{
970933
TLSAssetsDir: dir,
971934
ControllerTmplFile: "templates/cloud-config-controller",
@@ -1049,7 +1012,7 @@ routeTableId: rtb-1a2b3c4d
10491012
}
10501013
providedConfig.providedEncryptService = &dummyEncryptService{}
10511014

1052-
withDummyCredentials(func(dummyTlsAssetsDir string) {
1015+
helper.WithDummyCredentials(func(dummyTlsAssetsDir string) {
10531016
var stackTemplateOptions = StackTemplateOptions{
10541017
TLSAssetsDir: dummyTlsAssetsDir,
10551018
ControllerTmplFile: "templates/cloud-config-controller",

e2e/run

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
KUBE_AWS_CMD=${KUBE_AWS_CMD:-$GOPATH/src/github.com/coreos/kube-aws/bin/kube-aws}
44
E2E_DIR=$(cd $(dirname $0); pwd)
55
WORK_DIR=${E2E_DIR}/assets/${KUBE_AWS_CLUSTER_NAME}
6+
NODE_POOL_ASSETS_DIR=${E2E_DIR}/assets/${KUBE_AWS_CLUSTER_NAME}/node-pools/${KUBE_AWS_POOL_NAME}
67
SRC_DIR=$(cd $(dirname $0); cd ..; pwd)
78
KUBECONFIG=${WORK_DIR}/kubeconfig
89

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

213-
nodepool() {
214+
nodepool_init() {
214215
cd ${WORK_DIR}
215216

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

222+
if [ "${KUBE_AWS_SPOT_FLEET_ENABLED}" != "" ]; then
223+
echo Writing ${NODE_POOL_ASSETS_DIR}/cluster.yaml
224+
echo -e "worker:\n spotFleet:\n targetCapacity: 3\n" >> ${NODE_POOL_ASSETS_DIR}/cluster.yaml
225+
fi
226+
}
227+
228+
nodepool() {
229+
cd ${WORK_DIR}
230+
231+
nodepool_init
232+
221233
${KUBE_AWS_CMD} node-pools render stack --node-pool-name ${KUBE_AWS_POOL_NAME}
222234
${KUBE_AWS_CMD} node-pools up --node-pool-name ${KUBE_AWS_POOL_NAME} --export
223235
${KUBE_AWS_CMD} node-pools up --node-pool-name ${KUBE_AWS_POOL_NAME} --s3-uri ${KUBE_AWS_S3_URI}

filereader/jsontemplate/jsontemplate.go

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ func GetBytes(filename string, data interface{}) ([]byte, error) {
3434
}
3535

3636
func getContextString(buf []byte, offset, lineCount int) string {
37+
// Prevent index out of range errors when we meet errors at the very end of json
38+
bufsize := len(buf)
39+
if offset >= bufsize {
40+
if bufsize > 0 {
41+
offset = bufsize - 1
42+
} else {
43+
offset = 0
44+
}
45+
}
3746

3847
linesSeen := 0
3948
var leftLimit int

test renamed to make/test

File renamed without changes.

nodepool/cluster/cluster.go

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func (c *Cluster) Create(stackBody string, s3URI string) error {
5858
return c.stackProvisioner().CreateStackAndWait(cfSvc, s3Svc, stackBody, s3URI)
5959
}
6060

61+
func (c *Cluster) ValidateStack(stackBody string, s3URI string) (string, error) {
62+
return c.stackProvisioner().Validate(stackBody, s3URI)
63+
}
64+
6165
func (c *Cluster) Info() (*Info, error) {
6266
var info Info
6367
{

nodepool/config/config.go

+22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type ProvidedConfig struct {
3232
cfg.KubeClusterSettings `yaml:",inline"`
3333
cfg.WorkerSettings `yaml:",inline"`
3434
cfg.DeploymentSettings `yaml:",inline"`
35+
Worker `yaml:"worker,omitempty"`
3536
EtcdEndpoints string `yaml:"etcdEndpoints,omitempty"`
3637
NodePoolName string `yaml:"nodePoolName,omitempty"`
3738
providedEncryptService cfg.EncryptService
@@ -133,6 +134,7 @@ func NewDefaultCluster() *ProvidedConfig {
133134
return &ProvidedConfig{
134135
DeploymentSettings: defaults.DeploymentSettings,
135136
WorkerSettings: defaults.WorkerSettings,
137+
Worker: NewDefaultWorker(),
136138
}
137139
}
138140

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

153+
//Computed defaults
154+
launchSpecs := []LaunchSpecification{}
155+
for _, spec := range c.Worker.SpotFleet.LaunchSpecifications {
156+
if spec.RootVolumeType == "" {
157+
spec.RootVolumeType = c.Worker.SpotFleet.RootVolumeType
158+
}
159+
if spec.RootVolumeSize == 0 {
160+
spec.RootVolumeSize = c.Worker.SpotFleet.UnitRootVolumeSize * spec.WeightedCapacity
161+
}
162+
if spec.RootVolumeType == "io1" && spec.RootVolumeIOPS == 0 {
163+
spec.RootVolumeIOPS = c.Worker.SpotFleet.UnitRootVolumeIOPS * spec.WeightedCapacity
164+
}
165+
launchSpecs = append(launchSpecs, spec)
166+
}
167+
c.Worker.SpotFleet.LaunchSpecifications = launchSpecs
168+
151169
if err := c.valid(); err != nil {
152170
return nil, fmt.Errorf("invalid cluster: %v", err)
153171
}
@@ -193,6 +211,10 @@ func (c ProvidedConfig) valid() error {
193211
return err
194212
}
195213

214+
if err := c.Worker.Valid(); err != nil {
215+
return err
216+
}
217+
196218
return nil
197219
}
198220

0 commit comments

Comments
 (0)