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

Support EC2 instance tags per node role #1027

Merged
merged 2 commits into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion core/controlplane/config/templates/cloud-config-worker
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,25 @@ write_files:

instance_id=$(curl http://169.254.169.254/latest/meta-data/instance-id)

TAGS=""
TAGS="${TAGS}Key=\"kubernetes.io/cluster/{{ .ClusterName }}\",Value=\"owned\" "
TAGS="${TAGS}Key=\"kube-aws:node-pool:name\",Value=\"{{.NodePoolName}}\" "
TAGS="${TAGS}Key=\"Name\",Value=\"{{.ClusterName}}-{{.StackName}}-kube-aws-worker\" "

{{if .Autoscaling.ClusterAutoscaler.Enabled -}}
TAGS="${TAGS}Key=\"{{.Autoscaling.ClusterAutoscaler.AutoDiscoveryTagKey}}\",Value=\"\" "
{{end -}}

{{range $k, $v := .StackTags -}}
TAGS="${TAGS}Key=\"{{$k}}\",Value=\"{{$v}}\" "
{{end -}}

{{range $k, $v := .InstanceTags -}}
TAGS="${TAGS}Key=\"{{$k}}\",Value=\"{{$v}}\" "
{{end -}}

echo Tagging this EC2 instance with: "$TAGS"

rkt run \
--volume=ssl,kind=host,source=/etc/kubernetes/ssl,readOnly=false \
--mount=volume=ssl,target=/etc/kubernetes/ssl \
Expand All @@ -896,7 +915,7 @@ write_files:
/usr/bin/aws \
--region {{.Region}} ec2 create-tags \
--resource $instance_id \
--tags '"'"'Key=kubernetes.io/cluster/{{.ClusterName}},Value=""'"'"' '"'"'Key=Name,Value="{{.ClusterName}}-{{.StackName}}-kube-aws-worker"'"'"' '"'"'Key="kube-aws:node-pool:name",Value="{{.NodePoolName}}"'"'"'
--tags '"$TAGS"'
echo done.'

rkt rm --uuid-file=/var/run/coreos/tag-spot-instance.uuid || :
Expand Down
14 changes: 13 additions & 1 deletion core/controlplane/config/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ kmsKeyArn: "{{.KMSKeyARN}}"
# # CAUTION: Don't use t2.micro or the cluster won't work. See https://github.com/kubernetes/kubernetes/issues/18975
# instanceType: t2.medium
#
# # EC2 instance tags for controller nodes
# instanceTags:
# instanceRole: controller
#
# rootVolume:
# # Disk size (GiB) for controller node
# size: 30
Expand Down Expand Up @@ -343,6 +347,10 @@ worker:
# # CAUTION: Don't use t2.micro or the cluster won't work. See https://github.com/kubernetes/kubernetes/issues/16122
# instanceType: t2.medium
#
# # EC2 instance tags for worker nodes
# instanceTags:
# instanceRole: worker
#
# rootVolume:
# # Disk size (GiB) for worker nodes
# size: 30
Expand Down Expand Up @@ -397,7 +405,7 @@ worker:
# # IAM role to grant the Spot fleet permission to bid on, launch, and terminate instances on your behalf
# # See http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet-requests.html#spot-fleet-prerequisites
# #
# # Defaults to "arn:aws:iam::youraccountid:role/aws-ec2-spot-fleet-role" assuming you've arrived "Spot Requests" in EC2 Dashboard
# # Defaults to "arn:aws:iam::youraccountid:role/aws-ec2-spot-fleet-tagging-role" assuming you've arrived "Spot Requests" in EC2 Dashboard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like part of #1024 slipped in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct. Sorry but I had no time to test this in isolation, as noted in Depends on #1024 in the PR description!

# # hence the role is automatically created for you
# iamFleetRoleArn: "arn:aws:iam::youraccountid:role/kube-aws-doesnt-create-this-for-you"
#
Expand Down Expand Up @@ -577,6 +585,10 @@ worker:
# # Instance type for etcd node
# instanceType: t2.medium
#
# # EC2 instance tags for etcd nodes
# instanceTags:
# instanceRole: etcd
#
# rootVolume:
# # Root volume size (GiB) for etcd node
# size: 30
Expand Down
14 changes: 14 additions & 0 deletions core/controlplane/config/templates/stack-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
],
"MinSize": "{{.MinControllerCount}}",
"Tags": [
{{range $k, $v := $.Controller.InstanceTags -}}
{
"Key": "{{$k}}",
"PropagateAtLaunch": "true",
"Value": "{{$v}}"
},
{{end -}}
{
"Key": "kubernetes.io/cluster/{{.ClusterName}}",
"PropagateAtLaunch": "true",
Expand Down Expand Up @@ -647,6 +654,13 @@
],
"MinSize": "1",
"Tags": [
{{range $k, $v := $.Etcd.InstanceTags -}}
{
"Key": "{{$k}}",
"PropagateAtLaunch": "true",
"Value": "{{$v}}"
},
{{end -}}
{
"Key": "kubernetes.io/cluster/{{$.ClusterName}}",
"PropagateAtLaunch": "true",
Expand Down
7 changes: 7 additions & 0 deletions core/nodepool/config/templates/stack-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@
"Value": ""
},
{{end}}
{{range $k, $v := .InstanceTags -}}
{
"Key": "{{$k}}",
"PropagateAtLaunch": "true",
"Value": "{{$v}}"
},
{{end -}}
{
"Key": "kubernetes.io/cluster/{{ .ClusterName }}",
"PropagateAtLaunch": "true",
Expand Down
3 changes: 2 additions & 1 deletion model/ec2_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ type EC2Instance struct {
CreateTimeout string `yaml:"createTimeout,omitempty"`
InstanceType string `yaml:"instanceType,omitempty"`
RootVolume `yaml:"rootVolume,omitempty"`
Tenancy string `yaml:"tenancy,omitempty"`
Tenancy string `yaml:"tenancy,omitempty"`
InstanceTags map[string]string `yaml:"instanceTags,omitempty"`
}
2 changes: 1 addition & 1 deletion model/spot_fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (f *SpotFleet) UnmarshalYAML(unmarshal func(interface{}) error) error {

func (f SpotFleet) IAMFleetRoleRef() string {
if f.IAMFleetRoleARN == "" {
return `{"Fn::Join":["", [ "arn:aws:iam::", {"Ref":"AWS::AccountId"}, ":role/aws-ec2-spot-fleet-role" ]]}`
return `{"Fn::Join":["", [ "arn:aws:iam::", {"Ref":"AWS::AccountId"}, ":role/aws-ec2-spot-fleet-tagging-role" ]]}`
} else {
return fmt.Sprintf(`"%s"`, f.IAMFleetRoleARN)
}
Expand Down