Skip to content

Commit

Permalink
Merge pull request #703 from weaveworks/clusterconfig-taints
Browse files Browse the repository at this point in the history
Add taints to nodegroup config
  • Loading branch information
errordeveloper authored Apr 5, 2019
2 parents 9a210da + d168ea1 commit 3df2b52
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions examples/05-advanced-nodegroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ nodeGroups:
desiredCapacity: 4
labels:
nodegroup-type: very-special-science-workloads
taints:
special: "true:NoSchedule"
privateNetworking: true
availabilityZones: ["eu-west-2a"] # use single AZ to optimise data transfer between isntances
preBootstrapCommand:
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/eksctl.io/v1alpha4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ type NodeGroup struct {
// +optional
Labels map[string]string `json:"labels,omitempty"`

// +optional
Taints map[string]string `json:"taints,omitempty"`

// TODO move to separate struct
// +optional
AllowSSH bool `json:"allowSSH"`
Expand Down
14 changes: 14 additions & 0 deletions pkg/cfn/builder/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ var _ = Describe("CloudFormation template builder API", func() {
Expect(kubeletEnv.Permissions).To(Equal("0644"))
Expect(strings.Split(kubeletEnv.Content, "\n")).To(Equal([]string{
"NODE_LABELS=",
"NODE_TAINTS=",
}))

kubeletDropInUnit := getFile(cc, "/etc/systemd/system/kubelet.service.d/10-eksclt.al2.conf")
Expand Down Expand Up @@ -1066,6 +1067,7 @@ var _ = Describe("CloudFormation template builder API", func() {
Expect(kubeletEnv.Permissions).To(Equal("0644"))
Expect(strings.Split(kubeletEnv.Content, "\n")).To(Equal([]string{
"NODE_LABELS=",
"NODE_TAINTS=",
}))

kubeletDropInUnit := getFile(cc, "/etc/systemd/system/kubelet.service.d/10-eksclt.al2.conf")
Expand Down Expand Up @@ -1102,6 +1104,9 @@ var _ = Describe("CloudFormation template builder API", func() {
ng.Labels = map[string]string{
"os": "al2",
}
ng.Taints = map[string]string{
"key1": "value1:NoSchedule",
}

ng.OverrideBootstrapCommand = &overrideBootstrapCommand

Expand Down Expand Up @@ -1131,6 +1136,7 @@ var _ = Describe("CloudFormation template builder API", func() {
Expect(kubeletEnv.Permissions).To(Equal("0644"))
Expect(strings.Split(kubeletEnv.Content, "\n")).To(Equal([]string{
"NODE_LABELS=os=al2",
"NODE_TAINTS=key1=value1:NoSchedule",
}))

kubeletDropInUnit := getFile(cc, "/etc/systemd/system/kubelet.service.d/10-eksclt.al2.conf")
Expand Down Expand Up @@ -1197,6 +1203,7 @@ var _ = Describe("CloudFormation template builder API", func() {
Expect(kubeletEnv.Permissions).To(Equal("0644"))
Expect(strings.Split(kubeletEnv.Content, "\n")).To(Equal([]string{
"NODE_LABELS=os=al2",
"NODE_TAINTS=",
}))

kubeletDropInUnit := getFile(cc, "/etc/systemd/system/kubelet.service.d/10-eksclt.al2.conf")
Expand Down Expand Up @@ -1270,6 +1277,7 @@ var _ = Describe("CloudFormation template builder API", func() {
Expect(kubeletEnv.Permissions).To(Equal("0644"))
Expect(strings.Split(kubeletEnv.Content, "\n")).To(Equal([]string{
"NODE_LABELS=",
"NODE_TAINTS=",
"MAX_PODS=29",
"CLUSTER_DNS=172.20.0.10",
}))
Expand Down Expand Up @@ -1329,6 +1337,7 @@ var _ = Describe("CloudFormation template builder API", func() {
Expect(kubeletEnv.Permissions).To(Equal("0644"))
Expect(strings.Split(kubeletEnv.Content, "\n")).To(Equal([]string{
"NODE_LABELS=",
"NODE_TAINTS=",
"MAX_PODS=29",
"CLUSTER_DNS=172.20.0.10",
}))
Expand Down Expand Up @@ -1364,6 +1373,9 @@ var _ = Describe("CloudFormation template builder API", func() {
ng.Labels = map[string]string{
"os": "ubuntu",
}
ng.Taints = map[string]string{
"key1": "value1:NoSchedule",
}

ng.ClusterDNS = "169.254.20.10"

Expand Down Expand Up @@ -1399,6 +1411,7 @@ var _ = Describe("CloudFormation template builder API", func() {
Expect(kubeletEnv.Permissions).To(Equal("0644"))
Expect(strings.Split(kubeletEnv.Content, "\n")).To(Equal([]string{
"NODE_LABELS=os=ubuntu",
"NODE_TAINTS=key1=value1:NoSchedule",
"MAX_PODS=29",
"CLUSTER_DNS=169.254.20.10",
}))
Expand Down Expand Up @@ -1470,6 +1483,7 @@ var _ = Describe("CloudFormation template builder API", func() {
Expect(kubeletEnv.Permissions).To(Equal("0644"))
Expect(strings.Split(kubeletEnv.Content, "\n")).To(Equal([]string{
"NODE_LABELS=os=ubuntu",
"NODE_TAINTS=",
"MAX_PODS=29",
"CLUSTER_DNS=169.254.20.10",
}))
Expand Down
8 changes: 4 additions & 4 deletions pkg/nodebootstrap/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/nodebootstrap/assets/10-eksclt.al2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[Service]
# Local metadata parameters: REGION, AWS_DEFAULT_REGION
EnvironmentFile=/etc/eksctl/metadata.env
# Global and static parameters: MAX_PODS, CLUSTER_DNS, NODE_LABELS
# Global and static parameters: MAX_PODS, CLUSTER_DNS, NODE_LABELS, NODE_TAINTS
EnvironmentFile=/etc/eksctl/kubelet.env
# Local non-static parameters: NODE_IP, INSTANCE_ID
EnvironmentFile=/etc/eksctl/kubelet.local.env
Expand All @@ -12,6 +12,7 @@ ExecStart=
ExecStart=/usr/bin/kubelet \
--node-ip=${NODE_IP} \
--node-labels=${NODE_LABELS},alpha.eksctl.io/instance-id=${INSTANCE_ID} \
--register-node=true --register-with-taints=${NODE_TAINTS} \
--allow-privileged=true \
--cloud-provider=aws \
--container-runtime=docker \
Expand Down
1 change: 1 addition & 0 deletions pkg/nodebootstrap/assets/bootstrap.ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ systemctl reset-failed
"network-plugin=cni"
"cgroup-driver=cgroupfs"
"register-node=true"
"register-with-taints=${NODE_TAINTS}"
"kubeconfig=/etc/eksctl/kubeconfig.yaml"
"feature-gates=RotateKubeletServerCertificate=true"
"anonymous-auth=false"
Expand Down
12 changes: 8 additions & 4 deletions pkg/nodebootstrap/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,17 @@ func makeKubeletConfigYAML(spec *api.ClusterConfig, ng *api.NodeGroup) ([]byte,
}

func makeCommonKubeletEnvParams(spec *api.ClusterConfig, ng *api.NodeGroup) []string {
labels := []string{}
for k, v := range ng.Labels {
labels = append(labels, fmt.Sprintf("%s=%s", k, v))
kvs := func(kv map[string]string) string {
var params []string
for k, v := range kv {
params = append(params, fmt.Sprintf("%s=%s", k, v))
}
return strings.Join(params, ",")
}

return []string{
fmt.Sprintf("NODE_LABELS=%s", strings.Join(labels, ",")),
fmt.Sprintf("NODE_LABELS=%s", kvs(ng.Labels)),
fmt.Sprintf("NODE_TAINTS=%s", kvs(ng.Taints)),
}
}

Expand Down

0 comments on commit 3df2b52

Please sign in to comment.