Skip to content

Commit 981056a

Browse files
authored
Disable rand, extra args (shalb#5)
* s3 url output * get kubeconfig as data object * extra_args * disable randomize
1 parent ed827f3 commit 981056a

File tree

8 files changed

+34
-13
lines changed

8 files changed

+34
-13
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ module
5858
|------|-------------|------|---------|:--------:|
5959
| cluster\_name | Cluster name | `string` | n/a | yes |
6060
| domain | DNS zone record to assign to NLB | `string` | n/a | yes |
61-
| extra\_api\_args | A list of additional arguments for kubeapi | `map` | `{}` | no |
61+
| extra\_api\_args | A map of additional arguments for kubeapi. Key - argument without --, and it value. See examples. | `map` | `{}` | no |
62+
| extra\_args | A list of additional arguments for k3s server | `list` | `[]` | no |
6263
| k3s\_version | Version of k3s engine: https://github.com/rancher/k3s/releases | `string` | n/a | yes |
6364
| key\_name | The key name to use for the instances | `string` | n/a | yes |
6465
| kubeconfig\_filename | Name of file to save kubeconfig local. | `string` | `"./kubeconfig"` | no |

data.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ data "template_file" "init-master" {
2424
s3_bucket = var.s3_bucket
2525
node_labels = local.master_node_labels
2626
node_taints = local.master_node_taints
27-
extra_api_args = local.extra_api_args
28-
kubeconfig_name = local.kubeconfig_filename
27+
extra_args = "${local.custom_args} ${local.extra_api_args}"
28+
kubeconfig_name = local.s3_kubeconfig_filename
2929
}
3030
}
3131

examples/simple/terraform.tfvars

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,15 @@ s3_bucket = "cluster-dev-k3s"
1010
cluster_name = "k3s-test"
1111
key_name = "arti-key"
1212
worker_node_groups = []
13+
14+
extra_api_args = {
15+
oidc-issuer-url = "https://example.com/my"
16+
oidc-username-claim = "email"
17+
oidc-groups-claim = "groups"
18+
oidc-client-id = "login"
19+
allow-privileged = "true"
20+
}
21+
22+
extra_args = [
23+
"--disable traefik"
24+
]

files/k3s.tpl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ software_install() {
2424
fi
2525
%{ endif }
2626
START_ARGS="server --cluster-domain ${cluster_domain} --secrets-encryption --node-name $(curl http://169.254.169.254/latest/meta-data/local-hostname)"
27-
START_ARGS="$${START_ARGS} ${extra_api_args}"
27+
START_ARGS="$${START_ARGS} ${extra_args}"
2828
%{ endif }
2929

3030
%{ if instance_role == "worker" }

kubeconfig.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "null_resource" "wait_cluster_ready" {
22
provisioner "local-exec" {
33
# command = "until (curl --connect-timeout 2 https://${local.cluster_domain}:6443/ping --insecure) >/dev/null 2>&1; do sleep 1; echo waiting for k3s; done"
4-
command = "until (aws s3 cp s3://${var.s3_bucket}/${var.cluster_name}/${local.kubeconfig_filename} ./kubeconfig_tmp && for i in $(seq 10); do kubectl version --kubeconfig ./kubeconfig_tmp --request-timeout=5s || exit 1; sleep 1; done) >/dev/null 2>&1; do sleep 1; echo waiting for kubeconfig; done"
4+
command = "until (aws s3 cp s3://${var.s3_bucket}/${var.cluster_name}/${local.s3_kubeconfig_filename} ./kubeconfig_tmp && for i in $(seq 10); do kubectl version --kubeconfig ./kubeconfig_tmp --request-timeout=5s || exit 1; sleep 1; done) >/dev/null 2>&1; do sleep 1; echo waiting for kubeconfig; done"
55
}
66
depends_on = [
77
aws_autoscaling_group.master,
@@ -11,7 +11,7 @@ resource "null_resource" "wait_cluster_ready" {
1111

1212
# Not really secure as it will keep entire file as a plain text in tfstate
1313
data "aws_s3_bucket_object" "get_kubeconfig" {
14-
key = "${var.cluster_name}/${local.kubeconfig_filename}"
14+
key = "${var.cluster_name}/${local.s3_kubeconfig_filename}"
1515
bucket = var.s3_bucket
1616
depends_on = [
1717
null_resource.wait_cluster_ready

locals.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
resource "random_pet" "kubeconfig_sufix" {}
1+
22
locals {
3-
name = var.cluster_name
4-
cluster_dns_zone = "${var.cluster_name}.${var.domain}"
5-
cluster_domain = "cp.${local.cluster_dns_zone}"
6-
kubeconfig_filename = "kubeconfig${random_pet.kubeconfig_sufix.id}"
3+
name = var.cluster_name
4+
cluster_dns_zone = "${var.cluster_name}.${var.domain}"
5+
cluster_domain = "cp.${local.cluster_dns_zone}"
6+
s3_kubeconfig_filename = "kubeconfig"
77
common_tags = {
88
"kubernetes.io/cluster/${var.cluster_name}" = "owned"
99
KubernetesCluster = var.cluster_name
@@ -63,6 +63,7 @@ locals {
6363
[for key, value in var.extra_api_args :
6464
"--kube-apiserver-arg \"${key}=${value}\""
6565
])
66+
custom_args = join(" ", var.extra_args)
6667
}
6768

6869
resource null_resource "validate_domain_length" {

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ output "kubeconfig" {
77
}
88

99
output "kubeconfig_s3_url" {
10-
value = "s3://${var.s3_bucket}/${var.cluster_name}/${local.kubeconfig_filename}"
10+
value = "s3://${var.s3_bucket}/${var.cluster_name}/${local.s3_kubeconfig_filename}"
1111
}

variables.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,18 @@ variable worker_node_groups {
8181
}
8282

8383
variable extra_api_args {
84-
description = "A list of additional arguments for kubeapi"
84+
description = "A map of additional arguments for kubeapi. Key - argument without --, and it value. See examples."
8585
type = map
8686
default = {}
8787
}
8888

89+
variable extra_args {
90+
description = "A list of additional arguments for k3s server"
91+
type = list
92+
default = []
93+
}
94+
95+
8996
variable master_iam_instance_profile {
9097
description = "IAM instance profile to be attached to master instances"
9198
type = string

0 commit comments

Comments
 (0)