Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

AWS: Add support for custom taints and labels #832

Merged
merged 3 commits into from
Aug 24, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ systemd:
--node-labels=$${NODE_LABELS} \
--pod-manifest-path=/etc/kubernetes/manifests \
--read-only-port=0 \
--register-with-taints=$${NODE_TAINTS} \
--volume-plugin-dir=/var/lib/kubelet/volumeplugins
ExecStop=-/usr/bin/rkt stop --uuid-file=/var/cache/kubelet-pod.uuid
Restart=always
Expand Down Expand Up @@ -104,7 +105,8 @@ storage:
KUBELET_IMAGE_URL=docker://quay.io/poseidon/kubelet
KUBELET_IMAGE_TAG=v1.18.6
KUBELET_IMAGE_ARGS="--exec=/usr/local/bin/kubelet"
NODE_LABELS="node.kubernetes.io/node"
NODE_LABELS="node.kubernetes.io/node,${node_labels}"
NODE_TAINTS="${taints}"
- path: /etc/sysctl.d/max-user-watches.conf
filesystem: root
contents:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ variable "instance_type" {
description = "EC2 instance type"
}

variable "labels" {
type = string
default = ""
description = "Custom labels to assign to worker nodes. Provide comma separated key=value pairs as labels. e.g. 'foo=oof,bar=,baz=zab'"
}

variable "taints" {
type = string
default = ""
description = "Comma separated list of taints. eg. 'clusterType=staging:NoSchedule,nodeType=storage:NoSchedule'"
}

variable "os_name" {
type = string
default = "flatcar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,7 @@ data "template_file" "worker-config" {
ssh_keys = jsonencode(var.ssh_keys)
cluster_dns_service_ip = cidrhost(var.service_cidr, 10)
cluster_domain_suffix = var.cluster_domain_suffix
node_labels = var.labels
taints = var.taints
}
}
34 changes: 33 additions & 1 deletion ci/aws/aws-cluster.lokocfg.envsubst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ storage:
EOF
]

worker_pool "$CLUSTER_ID-wp" {
worker_pool "$CLUSTER_ID-w1" {
count = 2
ssh_pubkeys = ["$PUB_KEY"]
disk_size = 30
Expand All @@ -59,6 +59,38 @@ EOF
]
}

worker_pool "$CLUSTER_ID-w2" {
count = 1
ssh_pubkeys = ["$PUB_KEY"]
disk_size = 30
instance_type = "t2.small"
spot_price = "0.01"
labels = "testing.io=yes,roleofnode=testing"
taints = "nodeType=storage:NoSchedule"

# TODO: remove this once https://github.com/kinvolk/lokomotive/issues/839 is fixed.
lb_http_port = 8080
knrt10 marked this conversation as resolved.
Show resolved Hide resolved
lb_https_port = 8443
tags = {
"deployment" = "ci"
}
clc_snippets = [
<<EOF
storage:
files:
- path: /opt/clc_snippet_hello
filesystem: root
contents:
inline: Hello, world!
mode: 0644
user:
id: 500
group:
id: 500
EOF
]
}

# Adds oidc flags to API server with default values.
# Acts as a smoke test to check if API server is functional after addition
# of extra flags.
Expand Down
6 changes: 6 additions & 0 deletions docs/configuration-reference/platforms/aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ cluster "aws" {
os_version = "current"
labels = "foo=bar,baz=zab"
taints = "nodeType=storage:NoSchedule"
disk_size = var.worker_disk_size
disk_type = var.worker_disk_type
Expand Down Expand Up @@ -228,6 +232,8 @@ worker_pool "my-worker-pool" {
| `worker_pool.ssh_pubkeys` | List of SSH public keys for user `core`. Each element must be specified in a valid OpenSSH public key format, as defined in RFC 4253 Section 6.6, e.g. "ssh-rsa AAAAB3N...". | - | list(string) | true |
| `worker_pool.os_channel` | Flatcar Container Linux channel to install from (stable, beta, alpha, edge). | "stable" | string | false |
| `worker_pool.os_version` | Flatcar Container Linux version to install. Version such as "2303.3.1" or "current". | "current" | string | false |
| `worker_pool.labels` | Custom labels to assign to worker nodes such as `foo=bar,baz=zab`. | - | string | false |
| `worker_pool.taints` | Taints to assign to worker nodes such as `nodeType=storage:NoSchedule`. | - | string | false |
| `worker_pool.disk_size` | Size of the EBS volume in GB. | 40 | number | false |
| `worker_pool.disk_type` | Type of the EBS volume (e.g. standard, gp2, io1). | "gp2" | string | false |
| `worker_pool.disk_iops` | IOPS of the EBS volume (e.g 100). | 0 | number | false |
Expand Down
12 changes: 6 additions & 6 deletions pkg/assets/generated_assets.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pkg/platform/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type workerPool struct {
InstanceType string `hcl:"instance_type,optional"`
OSChannel string `hcl:"os_channel,optional"`
OSVersion string `hcl:"os_version,optional"`
Labels string `hcl:"labels,optional"`
Taints string `hcl:"taints,optional"`
DiskSize int `hcl:"disk_size,optional"`
DiskType string `hcl:"disk_type,optional"`
DiskIOPS int `hcl:"disk_iops,optional"`
Expand Down
8 changes: 8 additions & 0 deletions pkg/platform/aws/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ module "worker-pool-{{ $index }}" {
os_version = "{{ $pool.OSVersion }}"
{{- end }}

{{- if $pool.Labels }}
labels = "{{ $pool.Labels }}"
{{- end}}

{{- if $pool.Taints }}
taints = "{{ $pool.Taints }}"
{{- end}}

{{- if $pool.DiskSize }}
disk_size = "{{ $pool.DiskSize }}"
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion test/components/kubernetes/kubelet_disruptive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build packet baremetal
// +build packet baremetal aws
// +build disruptivee2e

package kubernetes
Expand Down
2 changes: 1 addition & 1 deletion test/components/kubernetes/kubelet_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build packet baremetal
// +build packet baremetal aws
// +build e2e

package kubernetes //nolint:testpackage
Expand Down
54 changes: 54 additions & 0 deletions test/components/kubernetes/kubelet_taint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2020 The Lokomotive Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build aws
// +build e2e

package kubernetes_test

import (
"context"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

func TestNodeHasTaints(t *testing.T) {
client := testutil.CreateKubeClient(t)

nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{
LabelSelector: "testing.io=yes,roleofnode=testing",
})
if err != nil {
t.Errorf("could not list nodes: %v", err)
}

if len(nodes.Items) == 0 {
t.Fatalf("no worker nodes found")
}

for _, items := range nodes.Items {
for _, taint := range items.Spec.Taints {
taintKey := taint.Key
taintValue := taint.Value
taintEffect := taint.Effect

if taintKey != "nodeType" || taintValue != "storage" || taintEffect != "NoSchedule" {
t.Fatalf("expected taint: %s, got: %s=%s:%s", "nodeType=storage:NoSchedule", taintKey, taintValue, taintEffect)
}
}
}
}