Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/helm_lib/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
type: library
name: deckhouse_lib_helm
version: 1.72.14
version: 1.72.14-a
description: "Helm utils template definitions for Deckhouse modules."
31 changes: 24 additions & 7 deletions charts/helm_lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
| [helm_lib_module_ephemeral_storage_only_logs](#helm_lib_module_ephemeral_storage_only_logs) |
| **Module Gateway** |
| [helm_lib_module_gateway](#helm_lib_module_gateway) |
| [helm_lib_module_gateway_enabled](#helm_lib_module_gateway_enabled) |
| **Module Generate Common Name** |
| [helm_lib_module_generate_common_name](#helm_lib_module_generate_common_name) |
| **Module Https** |
Expand All @@ -86,10 +87,10 @@
| [helm_lib_module_common_image_no_fail](#helm_lib_module_common_image_no_fail) |
| [helm_lib_module_image_digest](#helm_lib_module_image_digest) |
| [helm_lib_module_image_digest_no_fail](#helm_lib_module_image_digest_no_fail) |
| **Module Ingress Class** |
| **Module Ingress** |
| [helm_lib_module_ingress_class](#helm_lib_module_ingress_class) |
| **Module Ingress Snippets** |
| [helm_lib_module_ingress_configuration_snippet](#helm_lib_module_ingress_configuration_snippet) |
| [helm_lib_module_ingress_enabled](#helm_lib_module_ingress_enabled) |
| **Module Init Container** |
| [helm_lib_module_init_container_chown_nobody_volume](#helm_lib_module_init_container_chown_nobody_volume) |
| [helm_lib_module_init_container_chown_deckhouse_volume](#helm_lib_module_init_container_chown_deckhouse_volume) |
Expand Down Expand Up @@ -874,6 +875,16 @@ list:
- Template context with .Values, .Chart, etc
- An empty dict to update with current default gateway name and namespace


### helm_lib_module_gateway_enabled

returns whether Gateway API is enabled from module settings or if not exists from global config

#### Usage

`{{- if eq (include "helm_lib_module_gateway_enabled" .) "true" }} `


## Module Generate Common Name

### helm_lib_module_generate_common_name
Expand Down Expand Up @@ -1092,7 +1103,7 @@ list:
- Template context with .Values, .Chart, etc
- Container name

## Module Ingress Class
## Module Ingress

### helm_lib_module_ingress_class

Expand All @@ -1102,11 +1113,7 @@ list:

`{{ include "helm_lib_module_ingress_class" . }} `

#### Arguments

- Template context with .Values, .Chart, etc

## Module Ingress Snippets

### helm_lib_module_ingress_configuration_snippet

Expand All @@ -1120,6 +1127,16 @@ list:

- Template context with .Values, .Chart, etc


### helm_lib_module_ingress_enabled

returns whether Ingress is enabled from module settings or if not exists from global config

#### Usage

`{{- if eq (include "helm_lib_module_ingress_enabled" .) "true" }} `


## Module Init Container

### helm_lib_module_init_container_chown_nobody_volume
Expand Down
44 changes: 40 additions & 4 deletions charts/helm_lib/templates/_module_gateway.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,28 @@
{{- $result := index . 1 -}} {{- /* An empty dict to update with current default gateway name and namespace */ -}}
{{- $g := dict -}}

{{- $module_values := (index $context.Values (include "helm_lib_module_camelcase_name" $context)) -}}
{{- $moduleValues := (index $context.Values (include "helm_lib_module_camelcase_name" $context)) -}}

{{- if hasKey $module_values "gatewayAPIGateway" -}}
{{- $g = $module_values.gatewayAPIGateway -}}
{{- if and
(hasKey $moduleValues "gatewayAPI")
(hasKey $moduleValues.gatewayAPI "gateway")
-}}
{{- $g = $moduleValues.gatewayAPI.gateway -}}
{{- else if hasKey $moduleValues "gatewayAPIGateway" -}}
{{- /* Deprecated module schema. */ -}}
{{- $g = $moduleValues.gatewayAPIGateway -}}
{{- else if and
(hasKey $context.Values.global.modules "gatewayAPI")
(hasKey $context.Values.global.modules.gatewayAPI "gateway")
-}}
{{- $g = $context.Values.global.modules.gatewayAPI.gateway -}}
{{- else if hasKey $context.Values.global.modules "gatewayAPIGateway" -}}
{{- /* Deprecated global schema. */ -}}
{{- $g = $context.Values.global.modules.gatewayAPIGateway -}}
{{- else if and (hasKey $context.Values.global "discovery") (hasKey $context.Values.global.discovery "gatewayAPIDefaultGateway") -}}
{{- else if and
(hasKey $context.Values.global "discovery")
(hasKey $context.Values.global.discovery "gatewayAPIDefaultGateway")
-}}
{{- $g = $context.Values.global.discovery.gatewayAPIDefaultGateway -}}
{{- end -}}

Expand All @@ -20,3 +35,24 @@
{{- $_ := set $result "namespace" $g.namespace -}}
{{- end -}}
{{- end -}}

{{- /* Usage: {{- if eq (include "helm_lib_module_gateway_enabled" .) "true" }} */ -}}
{{- /* returns whether Gateway API is enabled from module settings or if not exists from global config */ -}}
{{- define "helm_lib_module_gateway_enabled" -}}
{{- $context := . -}}
{{- $moduleValues := index $context.Values (include "helm_lib_module_camelcase_name" $context) -}}

{{- if and
(hasKey $moduleValues "gatewayAPI")
(hasKey $moduleValues.gatewayAPI "enabled")
-}}
{{- $moduleValues.gatewayAPI.enabled -}}
{{- else if and
(hasKey $context.Values.global.modules "gatewayAPI")
(hasKey $context.Values.global.modules.gatewayAPI "enabled")
-}}
{{- $context.Values.global.modules.gatewayAPI.enabled -}}
{{- else -}}
true
{{- end -}}
{{- end -}}
57 changes: 57 additions & 0 deletions charts/helm_lib/templates/_module_ingress.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{- /* Usage: {{ include "helm_lib_module_ingress_class" . }} */ -}}
{{- /* returns ingress class from module settings or if not exists from global config */ -}}
{{- define "helm_lib_module_ingress_class" -}}
{{- $context := . -}}
{{- $moduleValues := index $context.Values (include "helm_lib_module_camelcase_name" $context) -}}

{{- if and
(hasKey $moduleValues "ingress")
(hasKey $moduleValues.ingress "ingressClass")
-}}
{{- $moduleValues.ingress.ingressClass -}}
{{- else if hasKey $moduleValues "ingressClass" -}}
{{- /* Deprecated module schema. */ -}}
{{- $moduleValues.ingressClass -}}
{{- else if and
(hasKey $context.Values.global.modules "ingress")
(hasKey $context.Values.global.modules.ingress "ingressClass")
-}}
{{- $context.Values.global.modules.ingress.ingressClass -}}
{{- else if hasKey $context.Values.global.modules "ingressClass" -}}
{{- /* Deprecated global schema. */ -}}
{{- $context.Values.global.modules.ingressClass -}}
{{- end -}}
{{- end -}}

{{- /* Usage: nginx.ingress.kubernetes.io/configuration-snippet: | {{ include "helm_lib_module_ingress_configuration_snippet" . | nindent 6 }} */ -}}
{{- /* returns nginx ingress additional headers (e.g. HSTS) if HTTPS is enabled */ -}}
{{- define "helm_lib_module_ingress_configuration_snippet" -}}
{{- $context := . -}} {{- /* Template context with .Values, .Chart, etc */ -}}

{{- $mode := include "helm_lib_module_https_mode" $context -}}

{{- if or (eq "CertManager" $mode) (eq "CustomCertificate" $mode) -}}
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
{{- end -}}
{{- end -}}

{{- /* Usage: {{- if eq (include "helm_lib_module_ingress_enabled" .) "true" }} */ -}}
{{- /* returns whether Ingress is enabled from module settings or if not exists from global config */ -}}
{{- define "helm_lib_module_ingress_enabled" -}}
{{- $context := . -}}
{{- $moduleValues := index $context.Values (include "helm_lib_module_camelcase_name" $context) -}}

{{- if and
(hasKey $moduleValues "ingress")
(hasKey $moduleValues.ingress "enabled")
-}}
{{- $moduleValues.ingress.enabled -}}
{{- else if and
(hasKey $context.Values.global.modules "ingress")
(hasKey $context.Values.global.modules.ingress "enabled")
-}}
{{- $context.Values.global.modules.ingress.enabled -}}
{{- else -}}
true
{{- end -}}
{{- end -}}
13 changes: 0 additions & 13 deletions charts/helm_lib/templates/_module_ingress_class.tpl

This file was deleted.

11 changes: 0 additions & 11 deletions charts/helm_lib/templates/_module_ingress_snippets.tpl

This file was deleted.

2 changes: 2 additions & 0 deletions tests/templates/helm_lib_module_gateway_enabled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- $result := include "helm_lib_module_gateway_enabled" . }}
result: "{{ $result }}"
2 changes: 2 additions & 0 deletions tests/templates/helm_lib_module_ingress_enabled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- $result := include "helm_lib_module_ingress_enabled" . }}
result: "{{ $result }}"
100 changes: 100 additions & 0 deletions tests/tests/helm_lib_module_gateway_enabled_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
suite: helm_lib_module_gateway_enabled definition
templates:
- helm_lib_module_gateway_enabled.yaml
tests:
- it: should return true by default
set:
global:
modules: {}
asserts:
- equal:
path: "result"
value: "true"

- it: should return true when gatewayAPI objects exist without enabled
set:
global:
modules:
gatewayAPI: {}
testModule:
gatewayAPI: {}
asserts:
- equal:
path: "result"
value: "true"

- it: should return true when only global gatewayAPI is enabled
set:
global:
modules:
gatewayAPI:
enabled: true
asserts:
- equal:
path: "result"
value: "true"

- it: should return false when global gatewayAPI is disabled
set:
global:
modules:
gatewayAPI:
enabled: false
asserts:
- equal:
path: "result"
value: "false"

- it: should return false when module gatewayAPI is disabled
set:
global:
modules:
gatewayAPI:
enabled: true
testModule:
gatewayAPI:
enabled: false
asserts:
- equal:
path: "result"
value: "false"

- it: should return false when only module gatewayAPI is disabled
set:
global:
modules: {}
testModule:
gatewayAPI:
enabled: false
asserts:
- equal:
path: "result"
value: "false"

- it: should return true when module and global gatewayAPI are enabled
set:
global:
modules:
gatewayAPI:
enabled: true
testModule:
gatewayAPI:
enabled: true
asserts:
- equal:
path: "result"
value: "true"

- it: should prioritize module enable over global disable
set:
global:
modules:
gatewayAPI:
enabled: false
testModule:
gatewayAPI:
enabled: true
asserts:
- equal:
path: "result"
value: "true"
Loading
Loading