From 931df7567ea67e3a600169781890db109d4b862b Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Mon, 7 Jul 2025 15:42:44 +0300 Subject: [PATCH] common: fix gluetun and add test (#37090) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes #36999 ⚒️ Fixes #36770 **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [x] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code - [ ] 📜 Documentation Changes **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [x] ⚖️ My code follows the style guidelines of this project - [x] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made changes to the documentation - [x] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [x] ⬆️ I increased versions for any altered app according to semantic versioning - [x] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):`, `chore(chart-name):`, `docs(chart-name):` or `fix(docs):` **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Signed-off-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Signed-off-by: Alfred Göppel <43101280+alfi0812@users.noreply.github.com> Co-authored-by: Alfred Göppel <43101280+alfi0812@users.noreply.github.com> --- .../tests/addons/gluetun_test.yaml | 29 ++++++++++++++-- charts/library/common/Chart.yaml | 2 +- .../common/templates/addons/_gluetun.tpl | 33 +++++++++++-------- .../templates/lib/util/_chartcontext.tpl | 8 +++++ 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/charts/library/common-test/tests/addons/gluetun_test.yaml b/charts/library/common-test/tests/addons/gluetun_test.yaml index 6b4dede7cca..e1cf0f7d9d6 100644 --- a/charts/library/common-test/tests/addons/gluetun_test.yaml +++ b/charts/library/common-test/tests/addons/gluetun_test.yaml @@ -10,6 +10,7 @@ tests: resources: limits: nvidia.com/gpu: 1 + addons: gluetun: enabled: true @@ -26,6 +27,9 @@ tests: key1: value1 key2: value2 key3: value3 + FIREWALL: "on" + FIREWALL_OUTBOUND_SUBNETS: "10.0.0/8, 192.168.0/16" + FIREWALL_INPUT_PORTS: "8080 , 8443" workload: &workload main: enabled: true @@ -44,6 +48,15 @@ tests: startup: enabled: false service: + main: + enabled: true + primary: false + ports: + main: + enabled: true + primary: true + protocol: http + port: 8089 service-name1: enabled: true primary: true @@ -54,14 +67,14 @@ tests: port: 8080 asserts: - hasDocuments: - count: 3 + count: 4 - documentIndex: &SecretDocument 0 isKind: of: Secret - documentIndex: &DeploymentDocument 1 isKind: of: Deployment - - documentIndex: &ServiceDocument 2 + - documentIndex: &ServiceDocument 3 isKind: of: Service - documentIndex: *SecretDocument @@ -157,6 +170,18 @@ tests: content: name: key3 value: value3 + - documentIndex: *DeploymentDocument + contains: + path: spec.template.spec.containers[1].env + content: + name: FIREWALL_OUTBOUND_SUBNETS + value: 10.0.0/8,192.168.0/16,172.16.0.0/16,172.17.0.0/16 + - documentIndex: *DeploymentDocument + contains: + path: spec.template.spec.containers[1].env + content: + name: FIREWALL_INPUT_PORTS + value: 8080,8443,8089 - documentIndex: *DeploymentDocument contains: path: spec.template.spec.containers[1].volumeMounts diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index 7e8819cf48b..87f618656c4 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -48,4 +48,4 @@ sources: - https://hub.docker.com/_/ - https://hub.docker.com/r/mikefarah/yq type: library -version: 28.12.6 +version: 28.12.7 diff --git a/charts/library/common/templates/addons/_gluetun.tpl b/charts/library/common/templates/addons/_gluetun.tpl index ea0ca301701..c93e4f48750 100644 --- a/charts/library/common/templates/addons/_gluetun.tpl +++ b/charts/library/common/templates/addons/_gluetun.tpl @@ -11,24 +11,27 @@ It will include / inject the required templates based on the given values. {{- $fw := $glue.container.env.FIREWALL -}} {{- if (eq $fw "on") -}} - {{- $nets := list -}} - {{- if and (hasKey $glue.container.env "FIREWALL_OUTBOUND_SUBNETS") (ne $glue.container.env.FIREWALL_OUTBOUND_SUBNETS "") -}} - {{- $nets = splitList "," $glue.container.env.FIREWALL_OUTBOUND_SUBNETS -}} - {{- end -}} - + {{- $nets := $glue.container.env.FIREWALL_OUTBOUND_SUBNETS | default list -}} + {{- if $nets -}}{{- $nets = $nets | splitList "," -}}{{- end -}} {{- $nets = mustAppend $nets $.Values.chartContext.podCIDR -}} {{- $nets = mustAppend $nets $.Values.chartContext.svcCIDR -}} - {{- $nets = mustUniq $nets -}} + + {{- $cleanNets := list -}} + {{- range $nets -}}{{- $cleanNets = mustAppend $cleanNets (. | nospace) -}}{{- end -}} + {{- $nets = $cleanNets | mustUniq -}} {{- $_ := set $glue.container.env "FIREWALL_OUTBOUND_SUBNETS" (join "," $nets) -}} - {{- $inputPorts := list -}} - {{- if hasKey $glue.container.env "FIREWALL_INPUT_PORTS" -}} - {{- $inputPorts = splitList "," $glue.container.env.FIREWALL_INPUT_PORTS -}} + {{- $inputPorts := $glue.container.env.FIREWALL_INPUT_PORTS | default list -}} + {{- if $inputPorts -}}{{- $inputPorts = $inputPorts | splitList "," -}}{{- end -}} + {{- if and + $.Values.service $.Values.service.main $.Values.service.main.ports + $.Values.service.main.ports.main $.Values.service.main.ports.main.port + -}} + {{- $inputPorts = mustAppend $inputPorts ($.Values.service.main.ports.main.port | toString) -}} {{- end -}} - {{- if and $.Values.service $.Values.service.main $.Values.service.main.ports $.Values.service.main.ports.main $.Values.service.main.ports.main.port -}} - {{- $inputPorts = mustAppend $inputPorts $.Values.service.main.ports.main.port -}} - {{- end -}} - {{- $inputPorts = $inputPorts | mustUniq -}} + {{- $cleanInputPorts := list -}} + {{- range $inputPorts -}}{{- $cleanInputPorts = mustAppend $cleanInputPorts (. | nospace) -}}{{- end -}} + {{- $inputPorts = $cleanInputPorts | mustUniq -}} {{- $_ := set $glue.container.env "FIREWALL_INPUT_PORTS" (join "," $inputPorts) -}} {{- end -}} @@ -52,7 +55,9 @@ It will include / inject the required templates based on the given values. {{- $_ := set $secValues "enabled" true -}} {{- $_ := set $.Values.secret $secretName $secValues -}} - {{- $persistence := (dict "enabled" true "type" "secret" "objectName" $secretName "targetSelector" dict "items" list ) -}} + {{- $persistence := (dict + "enabled" true "type" "secret" "objectName" $secretName "targetSelector" dict "items" list + ) -}} {{- if $secValues.defaultMode -}} {{- $_ := set $persistence "defaultMode" $secValues.defaultMode -}} {{- end -}} diff --git a/charts/library/common/templates/lib/util/_chartcontext.tpl b/charts/library/common/templates/lib/util/_chartcontext.tpl index c135d74fe0c..567dd6e15c8 100644 --- a/charts/library/common/templates/lib/util/_chartcontext.tpl +++ b/charts/library/common/templates/lib/util/_chartcontext.tpl @@ -33,6 +33,14 @@ {{- $podCIDR := "172.16.0.0/16" -}} {{- $svcCIDR := "172.17.0.0/16" -}} + {{- if $rootCtx.Values.global.podCIDR -}} + {{- $podCIDR = $rootCtx.Values.global.podCIDR -}} + {{- end -}} + + {{- if $rootCtx.Values.global.svcCIDR -}} + {{- $svcCIDR = $rootCtx.Values.global.svcCIDR -}} + {{- end -}} + {{/* TODO: Find ways to implement CIDR detection */}} {{/* If there is ingress, get data from the primary */}}