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

Commit 72b3bc7

Browse files
committed
feat: Experimental support for worker nodes powered by Spot Fleet
See updated nodepool/config/templates/cluster.yaml for the detailed guide of configuration. This is the initial implementation for #112 Beware that this feature may change in backward-incompatible ways
1 parent e3eb8c7 commit 72b3bc7

File tree

9 files changed

+497
-95
lines changed

9 files changed

+497
-95
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
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

config/config_test.go

Lines changed: 4 additions & 41 deletions
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",
File renamed without changes.

nodepool/config/config.go

Lines changed: 22 additions & 0 deletions
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)