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

Commit

Permalink
Remove Spot instance detection
Browse files Browse the repository at this point in the history
This will be superseeded by dynamic setting of labels and taints
based on AWS tags
  • Loading branch information
errm committed Nov 13, 2018
1 parent 6aa77c1 commit a4fe2f9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 113 deletions.
17 changes: 8 additions & 9 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type Node struct {
ReservedMemory string
ClusterDNS string
Region string
Spot bool
}

type metadataClient interface {
Expand All @@ -61,7 +60,14 @@ func New(e ec2iface.EC2API, m metadataClient, region *string) (*Node, error) {
return nil, err
}
instance := output.Reservations[0].Instances[0]
node := Node{Instance: instance, MaxPods: maxPods(instance.InstanceType), ReservedCPU: reservedCPU(instance.InstanceType), ReservedMemory: reservedMemory(instance.InstanceType), ClusterDNS: clusterDNS(instance.PrivateIpAddress), Region: *region, Spot: spot(instance.InstanceLifecycle)}
node := Node{
Instance: instance,
MaxPods: maxPods(instance.InstanceType),
ReservedCPU: reservedCPU(instance.InstanceType),
ReservedMemory: reservedMemory(instance.InstanceType),
ClusterDNS: clusterDNS(instance.PrivateIpAddress),
Region: *region,
}
if node.ClusterName() == "" {
sleepFor := b.Duration(tries)
log.Printf("The kubernetes.io/cluster/<name> tag is not yet set, will try again in %s", sleepFor)
Expand All @@ -86,13 +92,6 @@ func (n *Node) ClusterName() string {
return ""
}

func spot(lifecycleType *string) bool {
if lifecycleType != nil && *lifecycleType == ec2.InstanceLifecycleTypeSpot {
return true
}
return false
}

func instanceID(m metadataClient) (*string, error) {
result, err := m.GetMetadata("instance-id")
if err != nil {
Expand Down
71 changes: 7 additions & 64 deletions pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,57 +360,6 @@ func TestMemory(t *testing.T) {
}
}

func TestSpot(t *testing.T) {
tests := []struct {
lifecycleType string
expected bool
}{
{

lifecycleType: ec2.InstanceLifecycleTypeSpot,
expected: true,
},
{

lifecycleType: ec2.InstanceLifecycleTypeScheduled,
expected: false,
},
{
// OnDemand instances do not return this field
lifecycleType: "",
expected: false,
},
{

lifecycleType: "something-unexpected",
expected: false,
},
}

for _, test := range tests {
e := &mockEC2{
tags: [][]*ec2.Tag{
{tag("kubernetes.io/cluster/cluster-name", "owned")},
},
lifecycleType: test.lifecycleType,
}
metadata := mockMetadata{
data: map[string]string{
"instance-id": "1234",
},
}
region := "us-west-2"
node, err := New(e, metadata, &region)
if err != nil {
t.Errorf("unexpected error: %s", err)
}

if node.Spot != test.expected {
t.Errorf("expected Spot for %v to be: %v, but it was %v", test.lifecycleType, test.expected, node.Spot)
}
}
}

func tag(key, value string) *ec2.Tag {
return &ec2.Tag{
Key: &key,
Expand All @@ -421,10 +370,9 @@ func tag(key, value string) *ec2.Tag {
type mockEC2 struct {
PrivateIPAddress string
ec2iface.EC2API
tags [][]*ec2.Tag
instanceType string
err error
lifecycleType string
tags [][]*ec2.Tag
instanceType string
err error
}

func (m *mockEC2) DescribeInstances(input *ec2.DescribeInstancesInput) (*ec2.DescribeInstancesOutput, error) {
Expand All @@ -434,20 +382,15 @@ func (m *mockEC2) DescribeInstances(input *ec2.DescribeInstancesInput) (*ec2.Des
var tags []*ec2.Tag
//Pop the first set of tags
tags, m.tags = m.tags[0], m.tags[1:]
var lifecycleType *string
if m.lifecycleType != "" {
lifecycleType = &m.lifecycleType
}
if len(input.InstanceIds) > 0 {
return &ec2.DescribeInstancesOutput{
Reservations: []*ec2.Reservation{{
Instances: []*ec2.Instance{
{
InstanceId: input.InstanceIds[0],
Tags: tags,
InstanceType: &m.instanceType,
PrivateIpAddress: &m.PrivateIPAddress,
InstanceLifecycle: lifecycleType,
InstanceId: input.InstanceIds[0],
Tags: tags,
InstanceType: &m.instanceType,
PrivateIpAddress: &m.PrivateIPAddress,
},
},
},
Expand Down
36 changes: 3 additions & 33 deletions pkg/system/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestConfigure(t *testing.T) {
t.Errorf("unexpected error %v", err)
}

if len(fs.files) != 7 {
t.Errorf("expected 7 files, got %v", len(fs.files))
if len(fs.files) != 6 {
t.Errorf("expected 6 files, got %v", len(fs.files))
}

expected := `apiVersion: v1
Expand Down Expand Up @@ -100,7 +100,7 @@ ExecStart=/usr/bin/kubelet \
--kubeconfig=/var/lib/kubelet/kubeconfig \
--feature-gates=RotateKubeletServerCertificate=true \
--anonymous-auth=false \
--client-ca-file=/etc/kubernetes/pki/ca.crt $KUBELET_ARGS $KUBELET_MAX_PODS $KUBELET_KUBE_RESERVED $KUBELET_SPOT_ARGS $KUBELET_EXTRA_ARGS
--client-ca-file=/etc/kubernetes/pki/ca.crt $KUBELET_ARGS $KUBELET_MAX_PODS $KUBELET_KUBE_RESERVED $KUBELET_EXTRA_ARGS
Restart=always
StartLimitInterval=0
Expand All @@ -126,11 +126,6 @@ Environment='KUBELET_KUBE_RESERVED=--kube-reserved=cpu=60m,memory=960Mi'
`
fs.Check(t, "/etc/systemd/system/kubelet.service.d/30-kube-reserved.conf", expected, 0640)

expected = `[Service]
Environment='KUBELET_SPOT_ARGS=--node-labels="node-role.kubernetes.io/worker=true" --register-with-taints="node-role.kubernetes.io/worker=true:PreferNoSchedule"'
`
fs.Check(t, "/etc/systemd/system/kubelet.service.d/40-spot-args.conf", expected, 0640)

expected = `thisisthecertdata
`
fs.Check(t, "/etc/kubernetes/pki/ca.crt", expected, 0640)
Expand Down Expand Up @@ -170,30 +165,6 @@ func TestConfigureNoReserved(t *testing.T) {
fs.Check(t, "/etc/systemd/system/kubelet.service.d/30-kube-reserved.conf", expected, 0640)
}

func TestConfigureSpotInstance(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, "", "", true)
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]
Environment='KUBELET_SPOT_ARGS=--node-labels="node-role.kubernetes.io/spot-worker=true"'
`
fs.Check(t, "/etc/systemd/system/kubelet.service.d/40-spot-args.conf", expected, 0640)
}

func instance(ip, dnsName string, maxPods int, reservedCPU, reservedMemory string, spot bool) *node.Node {
return &node.Node{
Instance: &ec2.Instance{
Expand All @@ -205,7 +176,6 @@ func instance(ip, dnsName string, maxPods int, reservedCPU, reservedMemory strin
Region: "us-east-1",
ReservedCPU: reservedCPU,
ReservedMemory: reservedMemory,
Spot: spot,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/system/templates/etc/systemd/system/kubelet.service
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ExecStart=/usr/bin/kubelet \
--kubeconfig=/var/lib/kubelet/kubeconfig \
--feature-gates=RotateKubeletServerCertificate=true \
--anonymous-auth=false \
--client-ca-file=/etc/kubernetes/pki/ca.crt $KUBELET_ARGS $KUBELET_MAX_PODS $KUBELET_KUBE_RESERVED $KUBELET_SPOT_ARGS $KUBELET_EXTRA_ARGS
--client-ca-file=/etc/kubernetes/pki/ca.crt $KUBELET_ARGS $KUBELET_MAX_PODS $KUBELET_KUBE_RESERVED $KUBELET_EXTRA_ARGS

Restart=always
StartLimitInterval=0
Expand Down

This file was deleted.

0 comments on commit a4fe2f9

Please sign in to comment.