Skip to content

Commit

Permalink
Merge pull request #12 from isovalent/pr/bruno/wait-for-total-control…
Browse files Browse the repository at this point in the history
…-plane-nodes

Optionally wait for a full control-plane.
  • Loading branch information
hhoover authored Oct 12, 2023
2 parents ac86510 + b4e0d83 commit a1331c2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ No modules.
| <a name="input_path_to_kubeconfig_file"></a> [path\_to\_kubeconfig\_file](#input\_path\_to\_kubeconfig\_file) | The path to the kubeconfig file to use. | `string` | n/a | yes |
| <a name="input_post_cilium_install_script"></a> [post\_cilium\_install\_script](#input\_post\_cilium\_install\_script) | A script to be run right after installing Cilium. | `string` | `""` | no |
| <a name="input_pre_cilium_install_script"></a> [pre\_cilium\_install\_script](#input\_pre\_cilium\_install\_script) | A script to be run right before installing Cilium. | `string` | `""` | no |
| <a name="input_total_control_plane_nodes"></a> [total\_control\_plane\_nodes](#input\_total\_control\_plane\_nodes) | The number of control-plane nodes expected in the cluster. | `number` | `3` | no |
| <a name="input_wait_for_total_control_plane_nodes"></a> [wait\_for\_total\_control\_plane\_nodes](#input\_wait\_for\_total\_control\_plane\_nodes) | Whether to wait for the expected number of control-plane nodes to be registered before applying any changes. | `bool` | `false` | no |

## Outputs

Expand Down
32 changes: 17 additions & 15 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@
// limitations under the License.

locals {
provisioner_environment = merge(var.extra_provisioner_environment_variables, local.provisioner_environment_variables) // The full set of environment variables passed to the provisioning script.
provisioner_environment_variables = { // The set of environment variables set by this module on the provisioning script.
CILIUM_HELM_CHART = var.cilium_helm_chart, // The Cilium Helm chart to deploy.
CILIUM_HELM_EXTRA_ARGS = var.cilium_helm_extra_args // Extra arguments to be passed to the 'helm upgrade --install' command that installs Cilium.
CILIUM_HELM_RELEASE_NAME = var.cilium_helm_release_name, // The name to use for the Cilium Helm release.
CILIUM_HELM_VALUES_FILE = var.cilium_helm_values_file_path, // The path to the Helm values file to use when installing Cilium.
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.
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.
provisioner_environment = merge(var.extra_provisioner_environment_variables, local.provisioner_environment_variables) // The full set of environment variables passed to the provisioning script.
provisioner_environment_variables = { // The set of environment variables set by this module on the provisioning script.
CILIUM_HELM_CHART = var.cilium_helm_chart, // The Cilium Helm chart to deploy.
CILIUM_HELM_EXTRA_ARGS = var.cilium_helm_extra_args // Extra arguments to be passed to the 'helm upgrade --install' command that installs Cilium.
CILIUM_HELM_RELEASE_NAME = var.cilium_helm_release_name, // The name to use for the Cilium Helm release.
CILIUM_HELM_VALUES_FILE = var.cilium_helm_values_file_path, // The path to the Helm values file to use when installing Cilium.
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.
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
}
provisioner_path = "${abspath(path.module)}/scripts/provisioner.sh"
}
Expand Down
12 changes: 11 additions & 1 deletion scripts/provisioner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ do
fi
done
set -e
sleep 10

# If asked to, wait for the total number of control-plane nodes to be registered.
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}" ]];
do
sleep 1
done
fi
set -e

# Create the target namespace if it does not exist.
kubectl create namespace "${CILIUM_NAMESPACE}" --dry-run=client -o yaml | kubectl apply -f -
Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,15 @@ variable "post_cilium_install_script" {
description = "A script to be run right after installing Cilium."
type = string
}

variable "total_control_plane_nodes" {
default = 3
description = "The number of control-plane nodes expected in the cluster."
type = number
}

variable "wait_for_total_control_plane_nodes" {
default = false
description = "Whether to wait for the expected number of control-plane nodes to be registered before applying any changes."
type = bool
}

0 comments on commit a1331c2

Please sign in to comment.