Skip to content

Commit 9fea206

Browse files
authored
introduce the var to delete the kube-proxy so we can test the cilium … (#26)
* introduce the var to delete the kube-proxy so we can test the cilium kpr properly
1 parent 1cd6eb8 commit 9fea206

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@
33
An opinionated Terraform module that can be used to install and manage Cilium on top of a Kubernetes cluster.
44

55
<!-- BEGIN_TF_DOCS -->
6-
## Requirements
6+
### Requirements
77

88
| Name | Version |
99
|------|---------|
1010
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.2.0 |
1111
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 3.1.1 |
1212

13-
## Providers
13+
### Providers
1414

1515
| Name | Version |
1616
|------|---------|
1717
| <a name="provider_null"></a> [null](#provider\_null) | >= 3.1.1 |
1818

19-
## Modules
19+
### Modules
2020

2121
No modules.
2222

23-
## Resources
23+
### Resources
2424

2525
| Name | Type |
2626
|------|------|
2727
| [null_resource.main](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
2828

29-
## Inputs
29+
### Inputs
3030

3131
| Name | Description | Type | Default | Required |
3232
|------|-------------|------|---------|:--------:|
@@ -39,17 +39,19 @@ No modules.
3939
| <a name="input_cilium_namespace"></a> [cilium\_namespace](#input\_cilium\_namespace) | The namespace in which to install Cilium. | `string` | `"kube-system"` | no |
4040
| <a name="input_control_plane_nodes_label_selector"></a> [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 |
4141
| <a name="input_deploy_etcd_cluster"></a> [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 |
42+
| <a name="input_disable_kube_proxy"></a> [disable\_kube\_proxy](#input\_disable\_kube\_proxy) | Whether to disable the kube proxy so the cluster uses kube-proxy replacement | `bool` | `false` | no |
4243
| <a name="input_extra_provisioner_environment_variables"></a> [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 |
4344
| <a name="input_install_kube_prometheus_servicemonitor_crd"></a> [install\_kube\_prometheus\_servicemonitor\_crd](#input\_install\_kube\_prometheus\_servicemonitor\_crd) | Whether to install the 'kube-prometheus' ServiceMonitor CRD. | `bool` | `true` | no |
4445
| <a name="input_ipsec_key"></a> [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 |
4546
| <a name="input_kube_prometheus_crds_version"></a> [kube\_prometheus\_crds\_version](#input\_kube\_prometheus\_crds\_version) | Version of the 'kube-prometheus' ServiceMonitor CRD to install. | `string` | `"v0.13.0"` | no |
47+
| <a name="input_kube_proxy_namespace"></a> [kube\_proxy\_namespace](#input\_kube\_proxy\_namespace) | Whether to disable the kube proxy so the cluster uses kube-proxy replacement | `string` | `"kube-system"` | no |
4648
| <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 |
4749
| <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 |
4850
| <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 |
4951
| <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 |
5052
| <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 |
5153

52-
## Outputs
54+
### Outputs
5355

5456
No outputs.
5557
<!-- END_TF_DOCS -->

locals.tf

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ locals {
3232
POST_CILIUM_INSTALL_SCRIPT = var.post_cilium_install_script != "" ? base64encode(var.post_cilium_install_script) : "" // The script to execute after installing Cilium.
3333
TOTAL_CONTROL_PLANE_NODES = var.total_control_plane_nodes // The number of control-plane nodes expected in the cluster.
3434
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.
35+
DISABLE_KUBE_PROXY = var.disable_kube_proxy // Wether to disable the kube proxy after the cilium
36+
KUBE_PROXY_NAMESPACE = var.kube_proxy_namespace // the namespace contains the kube-proxy, it should be kube-system most of the case but leave this as the var in case we found some k8s distribution use something else
3537
}
3638
provisioner_path = "${abspath(path.module)}/scripts/provisioner.sh"
3739
}

scripts/provisioner.sh

+15
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,18 @@ if [[ "${POST_CILIUM_INSTALL_SCRIPT}" != "" ]];
133133
then
134134
base64 --decode <<< "${POST_CILIUM_INSTALL_SCRIPT}" | bash
135135
fi
136+
137+
# try to delete the kube-proxy and clear the iptabls using the cilum pods after we install the cilium
138+
if [[ "${DISABLE_KUBE_PROXY}" == "true" ]]; then
139+
kubectl -n "${KUBE_PROXY_NAMESPACE}" delete daemonset kube-proxy || true
140+
kubectl -n "${KUBE_PROXY_NAMESPACE}" delete cm kube-proxy || true
141+
kubectl wait --for=condition=Ready pod -l k8s-app=cilium -n "${CILIUM_NAMESPACE}"
142+
pods=$(kubectl get pods -l k8s-app=cilium -o name -n "${CILIUM_NAMESPACE}")
143+
if [ -n "$pods" ]; then
144+
while IFS= read -r pod; do
145+
kubectl -n "${CILIUM_NAMESPACE}" exec $pod -- sh -c 'iptables-save | grep -v KUBE | iptables-restore'
146+
done <<< "$pods"
147+
else
148+
echo "No pods found with label k8s-app=cilium in cilium namespace"
149+
fi
150+
fi

variables.tf

+13
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ variable "install_kube_prometheus_servicemonitor_crd" {
110110
type = bool
111111
}
112112

113+
variable "disable_kube_proxy" {
114+
default = false
115+
description = "Whether to disable the kube proxy so the cluster uses kube-proxy replacement"
116+
type = bool
117+
}
118+
119+
variable "kube_proxy_namespace" {
120+
default = "kube-system"
121+
description = "Whether to disable the kube proxy so the cluster uses kube-proxy replacement"
122+
type = string
123+
}
124+
125+
113126
variable "kube_prometheus_crds_version" {
114127
default = "v0.13.0"
115128
description = "Version of the 'kube-prometheus' ServiceMonitor CRD to install."

0 commit comments

Comments
 (0)