mirror of
https://github.com/bjw-s-labs/helm-charts.git
synced 2025-07-03 00:27:04 +02:00
feat(common): Release 3.7.3 (#393)
This commit is contained in:
parent
ade6955579
commit
245e1631c9
14 changed files with 167 additions and 99 deletions
|
@ -3,7 +3,7 @@ apiVersion: v2
|
|||
name: common
|
||||
description: Function library for Helm charts
|
||||
type: library
|
||||
version: 3.7.2
|
||||
version: 3.7.3
|
||||
kubeVersion: ">=1.22.0-0"
|
||||
keywords:
|
||||
- common
|
||||
|
@ -12,12 +12,13 @@ home: https://github.com/bjw-s/helm-charts/tree/main/charts/library/common
|
|||
maintainers:
|
||||
- name: bjw-s
|
||||
email: me@bjw-s.dev
|
||||
sources:
|
||||
- https://github.com/bjw-s/helm-charts
|
||||
annotations:
|
||||
org.opencontainers.image.source: "https://github.com/bjw-s/helm-charts"
|
||||
artifacthub.io/changes: |-
|
||||
- kind: fixed
|
||||
description: |-
|
||||
The Apache 2.0 LICENSE file has been added to the chart.
|
||||
Fixed name suffix for HTTPRoute
|
||||
- kind: fixed
|
||||
description: |-
|
||||
Fixed non-deterministic selection of primary service and port.
|
||||
Fixed incorrect default backendRefs values in HTTPRoute
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# common
|
||||
|
||||
 
|
||||
 
|
||||
|
||||
Function library for Helm charts
|
||||
|
||||
|
@ -27,7 +27,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
|
|||
# Chart.yaml
|
||||
dependencies:
|
||||
- name: common
|
||||
version: 3.7.2
|
||||
version: 3.7.3
|
||||
repository: https://bjw-s.github.io/helm-charts/
|
||||
```
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@ metadata:
|
|||
spec:
|
||||
parentRefs:
|
||||
{{- range $routeObject.parentRefs }}
|
||||
- group: {{ default "gateway.networking.k8s.io" .group }}
|
||||
kind: {{ default "Gateway" .kind }}
|
||||
- group: {{ .group | default "gateway.networking.k8s.io" }}
|
||||
kind: {{ .kind | default "Gateway" }}
|
||||
name: {{ required (printf "parentRef name is required for %v %v" $routeKind $routeObject.name) .name }}
|
||||
namespace: {{ required (printf "parentRef namespace is required for %v %v" $routeKind $routeObject.name) .namespace }}
|
||||
{{- if .sectionName }}
|
||||
|
@ -66,11 +66,11 @@ spec:
|
|||
{{ if $service -}}
|
||||
{{ $servicePrimaryPort = include "bjw-s.common.lib.service.primaryPort" (dict "rootContext" $rootContext "serviceObject" $service) | fromYaml -}}
|
||||
{{- end }}
|
||||
- group: {{ default "" .group | quote}}
|
||||
kind: {{ default "Service" .kind }}
|
||||
name: {{ default .name $service.name }}
|
||||
namespace: {{ default $rootContext.Release.Namespace .namespace }}
|
||||
port: {{ default .port $servicePrimaryPort.port }}
|
||||
- group: {{ .group | default "" | quote}}
|
||||
kind: {{ .kind | default "Service" }}
|
||||
name: {{ $service.name | default .name }}
|
||||
namespace: {{ .namespace | default $rootContext.Release.Namespace }}
|
||||
port: {{ .port | default $servicePrimaryPort.port }}
|
||||
weight: {{ include "bjw-s.common.lib.defaultKeepNonNullValue" (dict "value" .weight "default" 1) }}
|
||||
{{- end }}
|
||||
{{- if or (eq $routeKind "HTTPRoute") (eq $routeKind "GRPCRoute") }}
|
||||
|
|
|
@ -9,7 +9,7 @@ Validate Role values
|
|||
{{- $rules := $roleValues.rules -}}
|
||||
|
||||
{{- if not (mustHas $type $typeList) -}}
|
||||
{{- fail (printf "You selected: `%s`. Type must be one of:\n%s\n" $type ($typeList|toYaml)) -}}
|
||||
{{- fail (printf "\nYou selected: `%s`. Type must be one of:\n%s\n" $type ($typeList|toYaml)) -}}
|
||||
{{- end -}}
|
||||
{{- if not $rules -}}
|
||||
{{- fail "Rules can't be empty" -}}
|
||||
|
|
|
@ -10,7 +10,7 @@ Validate RoleBinding values
|
|||
{{- $roleRef := required "A roleRef is required" $roleBindingValues.roleRef -}}
|
||||
|
||||
{{- if not (mustHas $type $typeList) -}}
|
||||
{{- fail (printf "You selected: `%s`. Type must be one of:\n%s\n" $type ($typeList|toYaml)) -}}
|
||||
{{- fail (printf "\nYou selected: `%s`. Type must be one of:\n%s\n" $type ($typeList|toYaml)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not (hasKey $roleRef "identifier") -}}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
{{/*
|
||||
Return the enabled routes.
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.route.enabledRoutes" -}}
|
||||
{{- $rootContext := .rootContext -}}
|
||||
{{- $enabledRoutes := dict -}}
|
||||
|
||||
{{- range $name, $route := $rootContext.Values.route -}}
|
||||
{{- if kindIs "map" $route -}}
|
||||
{{- /* Enable Route by default, but allow override */ -}}
|
||||
{{- $routeEnabled := true -}}
|
||||
{{- if hasKey $route "enabled" -}}
|
||||
{{- $routeEnabled = $route.enabled -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $routeEnabled -}}
|
||||
{{- $_ := set $enabledRoutes $name . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $enabledRoutes | toYaml -}}
|
||||
{{- end -}}
|
|
@ -1,21 +0,0 @@
|
|||
{{/* Return the name of the primary route object */}}
|
||||
{{- define "bjw-s.common.lib.route.primary" -}}
|
||||
{{- $enabledRoutes := dict -}}
|
||||
{{- range $name, $route := .Values.route -}}
|
||||
{{- if $route.enabled -}}
|
||||
{{- $_ := set $enabledRoutes $name . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $result := "" -}}
|
||||
{{- range $name, $route := $enabledRoutes -}}
|
||||
{{- if and (hasKey $route "primary") $route.primary -}}
|
||||
{{- $result = $name -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not $result -}}
|
||||
{{- $result = keys $enabledRoutes | first -}}
|
||||
{{- end -}}
|
||||
{{- $result -}}
|
||||
{{- end -}}
|
|
@ -15,7 +15,8 @@ Convert Route values to an object
|
|||
{{- $objectName = printf "%s-%s" $objectName $override -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- if ne $identifier (include "bjw-s.common.lib.route.primary" $rootContext) -}}
|
||||
{{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $rootContext) | fromYaml ) }}
|
||||
{{- if and (not $objectValues.primary) (gt (len $enabledRoutes) 1) -}}
|
||||
{{- if not (eq $objectName $identifier) -}}
|
||||
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
|
||||
{{- end -}}
|
||||
|
|
|
@ -1,24 +1,19 @@
|
|||
{{/* Renders the Route objects required by the chart */}}
|
||||
{{/*
|
||||
Renders the Route objects required by the chart
|
||||
*/}}
|
||||
{{- define "bjw-s.common.render.routes" -}}
|
||||
{{- /* Generate named routes as required */ -}}
|
||||
{{- range $key, $route := .Values.route }}
|
||||
{{- /* Enable Route by default, but allow override */ -}}
|
||||
{{- $routeEnabled := true -}}
|
||||
{{- if hasKey $route "enabled" -}}
|
||||
{{- $routeEnabled = $route.enabled -}}
|
||||
{{- end -}}
|
||||
{{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $) | fromYaml ) -}}
|
||||
{{- range $key, $route := $enabledRoutes -}}
|
||||
{{- $routeValues := (mustDeepCopy $route) -}}
|
||||
|
||||
{{- if $routeEnabled -}}
|
||||
{{- $routeValues := (mustDeepCopy $route) -}}
|
||||
{{- /* Create object from the raw Route values */ -}}
|
||||
{{- $routeObject := (include "bjw-s.common.lib.route.valuesToObject" (dict "rootContext" $ "id" $key "values" $routeValues)) | fromYaml -}}
|
||||
|
||||
{{- /* Create object from the raw Route values */ -}}
|
||||
{{- $routeObject := (include "bjw-s.common.lib.route.valuesToObject" (dict "rootContext" $ "id" $key "values" $routeValues)) | fromYaml -}}
|
||||
{{- /* Perform validations on the Route before rendering */ -}}
|
||||
{{- include "bjw-s.common.lib.route.validate" (dict "rootContext" $ "object" $routeObject) -}}
|
||||
|
||||
{{- /* Perform validations on the Route before rendering */ -}}
|
||||
{{- include "bjw-s.common.lib.route.validate" (dict "rootContext" $ "object" $routeObject) -}}
|
||||
|
||||
{{- /* Include the Route class */ -}}
|
||||
{{- include "bjw-s.common.class.route" (dict "rootContext" $ "object" $routeObject) | nindent 0 -}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- /* Include the Route class */ -}}
|
||||
{{- include "bjw-s.common.class.route" (dict "rootContext" $ "object" $routeObject) | nindent 0 -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
|
|
@ -19,7 +19,10 @@ tests:
|
|||
rules: {}
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: "You selected: `InvalidRole`. Type must be one of:"
|
||||
errorMessage: |
|
||||
You selected: `InvalidRole`. Type must be one of:
|
||||
- Role
|
||||
- ClusterRole
|
||||
|
||||
- it: role rules can't be empty
|
||||
set:
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
---
|
||||
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
|
||||
suite: route names
|
||||
templates:
|
||||
- common.yaml
|
||||
values:
|
||||
- ../_values/controllers_main_default_container.yaml
|
||||
tests:
|
||||
- it: default name
|
||||
set:
|
||||
route.main:
|
||||
enabled: true
|
||||
parentRefs:
|
||||
- name: test
|
||||
namespace: test
|
||||
documentSelector:
|
||||
path: $[?(@.kind == "HTTPRoute")].metadata.name
|
||||
value: RELEASE-NAME
|
||||
asserts:
|
||||
- exists:
|
||||
path: metadata.name
|
||||
|
||||
- it: custom name suffix
|
||||
set:
|
||||
route.main:
|
||||
enabled: true
|
||||
parentRefs:
|
||||
- name: test
|
||||
namespace: test
|
||||
nameOverride: http
|
||||
documentSelector:
|
||||
path: $[?(@.kind == "HTTPRoute")].metadata.name
|
||||
value: RELEASE-NAME-http
|
||||
asserts:
|
||||
- exists:
|
||||
path: metadata.name
|
||||
|
||||
- it: custom name suffix with template
|
||||
set:
|
||||
route.main:
|
||||
enabled: true
|
||||
parentRefs:
|
||||
- name: test
|
||||
namespace: test
|
||||
nameOverride: "{{ .Chart.Name }}"
|
||||
documentSelector:
|
||||
path: $[?(@.kind == "HTTPRoute")].metadata.name
|
||||
value: RELEASE-NAME-common-test
|
||||
asserts:
|
||||
- exists:
|
||||
path: metadata.name
|
||||
|
||||
- it: multiple routes
|
||||
set:
|
||||
route:
|
||||
main:
|
||||
parentRefs:
|
||||
- name: main
|
||||
namespace: main
|
||||
test:
|
||||
parentRefs:
|
||||
- name: test
|
||||
namespace: test
|
||||
asserts:
|
||||
- documentSelector:
|
||||
path: $[?(@.kind == "HTTPRoute")].metadata.name
|
||||
value: RELEASE-NAME-main
|
||||
exists:
|
||||
path: metadata.name
|
||||
- documentSelector:
|
||||
path: $[?(@.kind == "HTTPRoute")].metadata.name
|
||||
value: RELEASE-NAME-test
|
||||
exists:
|
||||
path: metadata.name
|
|
@ -6,45 +6,39 @@ templates:
|
|||
values:
|
||||
- ../_values/controllers_main_default_container.yaml
|
||||
tests:
|
||||
- it: default should pass
|
||||
- it: an HTTPRoute is not created by default
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- documentIndex: 0
|
||||
not: true
|
||||
isKind:
|
||||
of: HTTPRoute
|
||||
- not: true
|
||||
containsDocument:
|
||||
kind: HTTPRoute
|
||||
apiVersion: gateway.networking.k8s.io/v1alpha2
|
||||
name: RELEASE-NAME
|
||||
|
||||
- it: explicitly disabled should pass
|
||||
- it: an HTTPRoute is not created when disabled
|
||||
set:
|
||||
route.main.enabled: false
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- documentIndex: 0
|
||||
not: true
|
||||
isKind:
|
||||
of: HTTPRoute
|
||||
- not: true
|
||||
containsDocument:
|
||||
kind: HTTPRoute
|
||||
apiVersion: gateway.networking.k8s.io/v1alpha2
|
||||
name: RELEASE-NAME
|
||||
|
||||
- it: explicitly enabled should pass
|
||||
- it: an HTTPRoute is created when explicitly enabled
|
||||
set:
|
||||
route.main:
|
||||
enabled: true
|
||||
parentRefs:
|
||||
- name: test
|
||||
namespace: test
|
||||
documentSelector:
|
||||
path: $[?(@.kind == "HTTPRoute")].metadata.name
|
||||
value: RELEASE-NAME
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 2
|
||||
- documentIndex: 0
|
||||
not: true
|
||||
isKind:
|
||||
of: HTTPRoute
|
||||
- documentIndex: 1
|
||||
isKind:
|
||||
of: HTTPRoute
|
||||
- exists:
|
||||
path: metadata.name
|
||||
|
||||
- it: multiple enabled should pass
|
||||
- it: multiple HTTPRoute are created when configured
|
||||
set:
|
||||
route:
|
||||
main:
|
||||
|
@ -56,15 +50,13 @@ tests:
|
|||
- name: test
|
||||
namespace: test
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 3
|
||||
- documentIndex: 0
|
||||
not: true
|
||||
isKind:
|
||||
of: HTTPRoute
|
||||
- documentIndex: 1
|
||||
isKind:
|
||||
of: HTTPRoute
|
||||
- documentIndex: 2
|
||||
isKind:
|
||||
of: HTTPRoute
|
||||
- documentSelector:
|
||||
path: $[?(@.kind == "HTTPRoute")].metadata.name
|
||||
value: RELEASE-NAME-main
|
||||
exists:
|
||||
path: metadata.name
|
||||
- documentSelector:
|
||||
path: $[?(@.kind == "HTTPRoute")].metadata.name
|
||||
value: RELEASE-NAME-test
|
||||
exists:
|
||||
path: metadata.name
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema",
|
||||
"$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.7.2/charts/library/common/values.schema.json",
|
||||
"$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.7.3/charts/library/common/values.schema.json",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"global": {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
apiVersion: v2
|
||||
description: A common powered chart template. This can be useful for small projects that don't have their own chart.
|
||||
name: app-template
|
||||
version: 3.7.2
|
||||
version: 3.7.3
|
||||
kubeVersion: ">=1.22.0-0"
|
||||
maintainers:
|
||||
- name: bjw-s
|
||||
|
@ -10,14 +10,14 @@ maintainers:
|
|||
dependencies:
|
||||
- name: common
|
||||
repository: https://bjw-s.github.io/helm-charts
|
||||
version: 3.7.2
|
||||
version: 3.7.3
|
||||
sources:
|
||||
- https://github.com/bjw-s/helm-charts
|
||||
annotations:
|
||||
artifacthub.io/changes: |-
|
||||
- kind: fixed
|
||||
description: |-
|
||||
The Apache 2.0 LICENSE file has been added to the chart.
|
||||
Fixed name suffix for HTTPRoute
|
||||
- kind: fixed
|
||||
description: |-
|
||||
Fixed non-deterministic selection of primary service and port.
|
||||
Fixed incorrect default backendRefs values in HTTPRoute
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue