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

Commit

Permalink
If instance type is unknown, don't configure kube-reserved
Browse files Browse the repository at this point in the history
  • Loading branch information
errm committed Sep 18, 2018
1 parent b2c595b commit a5c1b43
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func reservedCPU(instanceType *string) string {
}
}
if reserved == 0.0 {
reserved = 60.0
return ""
}
return fmt.Sprintf("%.0fm", reserved)
}
Expand All @@ -147,7 +147,7 @@ func reservedMemory(instanceType *string) string {
}
}
if reserved == 0.0 {
reserved = 960.0
return ""
}
return fmt.Sprintf("%.0fMi", reserved)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestReservedCPU(t *testing.T) {
{

instanceType: "unexpected.instance",
expected: "60m",
expected: "",
},
}

Expand Down Expand Up @@ -332,7 +332,7 @@ func TestMemory(t *testing.T) {
{

instanceType: "unexpected.instance",
expected: "960Mi",
expected: "",
},
}

Expand Down
30 changes: 26 additions & 4 deletions pkg/system/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestConfigure(t *testing.T) {
hn := &FakeHostname{}
init := &FakeInit{}

i := instance("10.6.28.199", "ip-10-6-28-199.us-west-2.compute.internal", 18)
i := instance("10.6.28.199", "ip-10-6-28-199.us-west-2.compute.internal", 18, "60m", "960Mi")
c := cluster(
"aws-om-cluster",
"https://74770F6B05F7A8FB0F02CFB5F7AF530C.yl4.us-west-2.eks.amazonaws.com",
Expand Down Expand Up @@ -143,7 +143,29 @@ Environment='KUBELET_KUBE_RESERVED=--kube-reserved=cpu=60m,memory=960Mi'
}
}

func instance(ip, dnsName string, maxPods int) *node.Node {
func TestConfigureNoReserved(t *testing.T) {
fs := &FakeFileSystem{}
hn := &FakeHostname{}
init := &FakeInit{}

i := instance("10.6.28.199", "ip-10-6-28-199.us-west-2.compute.internal", 18, "", "")
c := cluster(
"aws-om-cluster",
"https://74770F6B05F7A8FB0F02CFB5F7AF530C.yl4.us-west-2.eks.amazonaws.com",
"dGhpc2lzdGhlY2VydGRhdGE=",
)
system := System{Filesystem: fs, Hostname: hn, Init: init}
err := system.Configure(i, c)

if err != nil {
t.Errorf("unexpected error %v", err)
}

expected := `[Service]`
fs.Check(t, "/etc/systemd/system/kubelet.service.d/30-kube-reserved.conf", expected, 0640)
}

func instance(ip, dnsName string, maxPods int, reservedCPU, reservedMemory string) *node.Node {
return &node.Node{
Instance: &ec2.Instance{
PrivateIpAddress: &ip,
Expand All @@ -152,8 +174,8 @@ func instance(ip, dnsName string, maxPods int) *node.Node {
MaxPods: maxPods,
ClusterDNS: "172.20.0.10",
Region: "us-east-1",
ReservedCPU: "60m",
ReservedMemory: "960Mi",
ReservedCPU: reservedCPU,
ReservedMemory: reservedMemory,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[Service]
{{- if and .Node.ReservedCPU .Node.ReservedMemory }}
Environment='KUBELET_KUBE_RESERVED=--kube-reserved=cpu={{.Node.ReservedCPU}},memory={{.Node.ReservedMemory}}'
{{ end -}}

0 comments on commit a5c1b43

Please sign in to comment.