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 */}}