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

Commit 56f08d5

Browse files
authored
Merge pull request #141 from mumoshu/fix-node-registration-for-spot-fleet-powered-workers
Fix node registration issue for spot-fleet-powered worker nodes
2 parents 3870415 + a4e5d25 commit 56f08d5

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

config/config.go

+12
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ type Cluster struct {
281281
TLSCertDurationDays int `yaml:"tlsCertDurationDays,omitempty"`
282282
HostedZone string `yaml:"hostedZone,omitempty"`
283283
HostedZoneID string `yaml:"hostedZoneId,omitempty"`
284+
Worker Worker
284285
providedEncryptService EncryptService
285286
}
286287

@@ -290,6 +291,17 @@ type Subnet struct {
290291
lastAllocatedAddr *net.IP
291292
}
292293

294+
// Just a place-holder to keep compatibility of cloud-config-worker between main cluster and node pool
295+
// Without this, {{if .Worker.SpotFleet.Enabled}} in the cloud-config-worker template fails with an obvious error like
296+
// "executing "CloudConfigWorker" at <.Worker>: can't evaluate field Worker in type *config.Config"
297+
type Worker struct {
298+
SpotFleet SpotFleet
299+
}
300+
301+
type SpotFleet struct {
302+
Enabled bool
303+
}
304+
293305
type Experimental struct {
294306
AuditLog AuditLog `yaml:"auditLog"`
295307
AwsEnvironment AwsEnvironment `yaml:"awsEnvironment"`

config/templates/cloud-config-worker

+46
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,22 @@ coreos:
211211
--stack {{.ClusterName}}
212212
{{end}}
213213

214+
{{if .Worker.SpotFleet.Enabled}}
215+
- name: tag-spot-instance.service
216+
enable: true
217+
command: start
218+
runtime: true
219+
content: |
220+
[Unit]
221+
Description=Tag this spot instance with cluster name
222+
After=network-online.target
223+
224+
[Service]
225+
Type=oneshot
226+
RemainAfterExit=true
227+
ExecStart=/opt/bin/tag-spot-instance
228+
{{end}}
229+
214230
{{ if $.ElasticFileSystemID }}
215231
- name: rpc-statd.service
216232
command: start
@@ -437,6 +453,36 @@ write_files:
437453
done
438454
echo done.
439455

456+
{{if .Worker.SpotFleet.Enabled}}
457+
- path: /opt/bin/tag-spot-instance
458+
owner: root:root
459+
permissions: 0700
460+
content: |
461+
#!/bin/bash -e
462+
463+
instance_id=$(curl http://169.254.169.254/latest/meta-data/instance-id)
464+
465+
sudo rkt run \
466+
--volume=ssl,kind=host,source=/etc/kubernetes/ssl,readOnly=false \
467+
--mount=volume=ssl,target=/etc/kubernetes/ssl \
468+
--uuid-file-save=/var/run/coreos/tag-spot-instance.uuid \
469+
--volume=dns,kind=host,source=/etc/resolv.conf,readOnly=true --mount volume=dns,target=/etc/resolv.conf \
470+
--net=host \
471+
--trust-keys-from-https \
472+
--insecure-options=ondisk \
473+
{{.AWSCliImageRepo}}:{{.AWSCliTag}} --exec=/bin/bash -- \
474+
-vxc \
475+
'echo tagging this spot instance; \
476+
instance_id="'$instance_id'"; \
477+
/usr/bin/aws \
478+
--region {{.Region}} ec2 create-tags \
479+
--resource $instance_id \
480+
--tags "Key=KubernetesCluster,Value={{.ClusterName}}"; \
481+
echo done.'
482+
483+
sudo rkt rm --uuid-file=/var/run/coreos/tag-spot-instance.uuid
484+
{{end}}
485+
440486
- path: /opt/bin/taint-and-uncordon
441487
owner: root:root
442488
permissions: 0700

nodepool/config/templates/stack-template.json

+7
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@
280280
"Resource": [ "*" ]
281281
},
282282
{{end}}
283+
{{if .Worker.SpotFleet.Enabled}}
284+
{
285+
"Action": "ec2:CreateTags",
286+
"Effect": "Allow",
287+
"Resource": "*"
288+
},
289+
{{end}}
283290
{
284291
"Action": [
285292
"ecr:GetAuthorizationToken",

0 commit comments

Comments
 (0)