From 25773d09f6426783821fd4e89c155f50f855f0e5 Mon Sep 17 00:00:00 2001 From: Simon Emms Date: Sat, 6 Jul 2024 21:16:31 +0000 Subject: [PATCH] feat(kubernetes): add kured to automatically reboot nodes --- modules/kubernetes/README.md | 2 ++ modules/kubernetes/kured.tf | 47 +++++++++++++++++++++++++++++++++ modules/kubernetes/variables.tf | 6 +++++ 3 files changed, 55 insertions(+) create mode 100644 modules/kubernetes/kured.tf diff --git a/modules/kubernetes/README.md b/modules/kubernetes/README.md index 23abc58..399355c 100644 --- a/modules/kubernetes/README.md +++ b/modules/kubernetes/README.md @@ -27,6 +27,7 @@ No modules. | [helm_release.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | | [helm_release.hcloud_ccm](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | | [helm_release.hcloud_csi](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | +| [helm_release.kured](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | | [kubernetes_annotations.hcloud_ccm](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/annotations) | resource | | [kubernetes_namespace.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource | | [kubernetes_secret_v1.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret_v1) | resource | @@ -44,6 +45,7 @@ No modules. | [k3s\_cluster\_cidr](#input\_k3s\_cluster\_cidr) | CIDR used for the k3s cluster | `string` | `"10.244.0.0/16"` | no | | [kube\_context](#input\_kube\_context) | Kubernetes context to use | `string` | `"default"` | no | | [kubeconfig](#input\_kubeconfig) | Kubeconfig for the cluster | `string` | n/a | yes | +| [kured\_version](#input\_kured\_version) | Version of Kured to use - defaults to latest | `string` | `null` | no | | [worker\_pools](#input\_worker\_pools) | Cluster autoscaler configuration |
list(object({
cloud_init = string
firewall_id = string
image = string
labels = list(object({
key = string
value = string
}))
network_id = string
pool = object({
instanceType = string
minSize = number
maxSize = number
name = string
region = string
})
ssh_key_id = string
taints = list(object({
key = string
value = string
effect = string
}))
}))
| `[]` | no | ## Outputs diff --git a/modules/kubernetes/kured.tf b/modules/kubernetes/kured.tf new file mode 100644 index 0000000..8c4890b --- /dev/null +++ b/modules/kubernetes/kured.tf @@ -0,0 +1,47 @@ +# Copyright 2024 Simon Emms +# +# 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. + +resource "helm_release" "kured" { + chart = "kured" + name = "kured" + atomic = true + cleanup_on_fail = true + create_namespace = true + namespace = "kured" + repository = "https://kubereboot.github.io/charts" + reset_values = true + version = var.kured_version + wait = true + + dynamic "set" { + for_each = flatten([ + for i, taint in local.control_plane_taints : + [ + for k, v in taint : + [ + { + name = "tolerations[${i}].${k}" + value = v + }, + ] + ] + ]) + iterator = each + + content { + name = each.value.name + value = each.value.value + } + } +} diff --git a/modules/kubernetes/variables.tf b/modules/kubernetes/variables.tf index 8d3b860..1659ef5 100644 --- a/modules/kubernetes/variables.tf +++ b/modules/kubernetes/variables.tf @@ -59,6 +59,12 @@ variable "kube_context" { default = "default" } +variable "kured_version" { + type = string + description = "Version of Kured to use - defaults to latest" + default = null +} + variable "worker_pools" { type = list(object({ cloud_init = string