From 04ba6d169f9eb6ca31533d3ae2c83b2a1571ccf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20M=2E=20Cust=C3=B3dio?= Date: Fri, 13 Oct 2023 09:46:29 +0100 Subject: [PATCH 1/2] Improve the logic around waiting for control-plane. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bruno M. Custódio --- locals.tf | 7 +++---- scripts/provisioner.sh | 12 ++++++++++-- variables.tf | 6 ++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/locals.tf b/locals.tf index 950c92f..2e8ce9e 100644 --- a/locals.tf +++ b/locals.tf @@ -22,16 +22,15 @@ locals { CILIUM_HELM_VALUES_OVERRIDE_FILE = var.cilium_helm_values_override_file_path, // The path to the Helm values override file to use when installing Cilium. CILIUM_HELM_VERSION = var.cilium_helm_version, // The version of the Cilium Helm chart to deploy. CILIUM_NAMESPACE = var.cilium_namespace, // The namespace where to deploy Cilium. + CONTROL_PLANE_NODES_LABEL_SELECTOR = var.control_plane_nodes_label_selector, // The label selector used to filter control-plane nodes. DEPLOY_ETCD_CLUSTER = var.deploy_etcd_cluster // Whether to deploy an 'etcd' cluster suitable for usage as the Cilium key-value store. INSTALL_KUBE_PROMETHEUS_CRDS = true, // Whether to install (some of) the 'kube-prometheus' CRDs (such as 'ServiceMonitor'). IPSEC_KEY = var.ipsec_key, // The IPsec key to be used for transparent encryption. KUBECONFIG = var.path_to_kubeconfig_file // The path to the kubeconfig file that will be created and output. PRE_CILIUM_INSTALL_SCRIPT = var.pre_cilium_install_script != "" ? base64encode(var.pre_cilium_install_script) : "" // The script to execute before installing Cilium. POST_CILIUM_INSTALL_SCRIPT = var.post_cilium_install_script != "" ? base64encode(var.post_cilium_install_script) : "" // The script to execute after installing Cilium. - TOTAL_CONTROL_PLANE_NODES = var.total_control_plane_nodes - WAIT_FOR_TOTAL_CONTROL_PLANE_NODES = var.wait_for_total_control_plane_nodes + TOTAL_CONTROL_PLANE_NODES = var.total_control_plane_nodes // The number of control-plane nodes expected in the cluster. + WAIT_FOR_TOTAL_CONTROL_PLANE_NODES = var.wait_for_total_control_plane_nodes // Whether to wait for the expected number of control-plane nodes to be registered before applying any changes. } provisioner_path = "${abspath(path.module)}/scripts/provisioner.sh" } - - diff --git a/scripts/provisioner.sh b/scripts/provisioner.sh index 80d7e51..40e5edc 100755 --- a/scripts/provisioner.sh +++ b/scripts/provisioner.sh @@ -52,9 +52,17 @@ set -e set +e if [[ "${WAIT_FOR_TOTAL_CONTROL_PLANE_NODES}" == "true" ]]; then - until [[ $(kubectl get node -l node-role.kubernetes.io/control-plane --no-headers | wc -l) == "${TOTAL_CONTROL_PLANE_NODES}" ]]; + WAIT_FOR_TOTAL_CONTROL_PLANE_NODES_ATTEMPT_NUM=1 + until [[ $(kubectl get node -l "${CONTROL_PLANE_NODES_LABEL_SELECTOR}" --no-headers | wc -l) == "${TOTAL_CONTROL_PLANE_NODES}" ]]; do - sleep 1 + if [[ ${WAIT_FOR_TOTAL_CONTROL_PLANE_NODES_ATTEMPT_NUM} -gt 180 ]]; + then + echo "Timed out while waiting for the total number of control-plane nodes." + exit 1 + else + WAIT_FOR_TOTAL_CONTROL_PLANE_NODES_ATTEMPT_NUM=$((WAIT_FOR_TOTAL_CONTROL_PLANE_NODES_ATTEMPT_NUM+1)) + sleep 1 + fi done fi set -e diff --git a/variables.tf b/variables.tf index 61c7391..c08038b 100644 --- a/variables.tf +++ b/variables.tf @@ -57,6 +57,12 @@ variable "deploy_etcd_cluster" { type = bool } +variable "control_plane_nodes_label_selector" { + default = "node-role.kubernetes.io/control-plane" + description = "The label selector used to filter control-plane nodes." + type = string +} + variable "extra_provisioner_environment_variables" { default = {} description = "A map of extra environment variables to include when executing the provisioning script." From 7bbda04c7e3a8e49646e76dba11bb7cf061bf1ee Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 13 Oct 2023 08:47:17 +0000 Subject: [PATCH 2/2] terraform-docs: automated action --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e6924b6..3059816 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ No modules. | [cilium\_helm\_values\_override\_file\_path](#input\_cilium\_helm\_values\_override\_file\_path) | The path to the file containing the values to use when installing Cilium. These values will override the ones in 'cilium\_helm\_values\_file\_path'. | `string` | n/a | yes | | [cilium\_helm\_version](#input\_cilium\_helm\_version) | The version of the Cilium Helm chart to install. | `string` | n/a | yes | | [cilium\_namespace](#input\_cilium\_namespace) | The namespace in which to install Cilium. | `string` | `"kube-system"` | no | +| [control\_plane\_nodes\_label\_selector](#input\_control\_plane\_nodes\_label\_selector) | The label selector used to filter control-plane nodes. | `string` | `"node-role.kubernetes.io/control-plane"` | no | | [deploy\_etcd\_cluster](#input\_deploy\_etcd\_cluster) | Whether to deploy an 'etcd' cluster suitable for usage as the Cilium key-value store (HIGHLY EXPERIMENTAL). | `bool` | `false` | no | | [extra\_provisioner\_environment\_variables](#input\_extra\_provisioner\_environment\_variables) | A map of extra environment variables to include when executing the provisioning script. | `map(string)` | `{}` | no | | [ipsec\_key](#input\_ipsec\_key) | The IPsec key to use for transparent encryption. Leave empty for none to be created (in which case encryption should be disabled in Helm as well). | `string` | `""` | no |