fix(common): Release common-4.0.1 (#415)

This commit is contained in:
Bernd Schorgers 2025-05-16 12:40:44 +02:00 committed by GitHub
parent a01a89cb13
commit 9a478444a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 163 additions and 15 deletions

View file

@ -3,7 +3,7 @@ apiVersion: v2
name: common name: common
description: Function library for Helm charts description: Function library for Helm charts
type: library type: library
version: 4.0.0 version: 4.0.1
kubeVersion: ">=1.28.0-0" kubeVersion: ">=1.28.0-0"
keywords: keywords:
- common - common
@ -46,6 +46,9 @@ annotations:
- kind: added - kind: added
description: |- description: |-
Added support for automatically determining the target service for Ingress paths if there is only one enabled Service Added support for automatically determining the target service for Ingress paths if there is only one enabled Service
- kind: added
description: |-
Added support for automatically determining the target service for Route backends if there is only one enabled Service
- kind: changed - kind: changed
description: |- description: |-
**Breaking**: Standardized resource name logic for all resources. This may cause changes in the generated resource names. **Breaking**: Standardized resource name logic for all resources. This may cause changes in the generated resource names.

View file

@ -1,6 +1,6 @@
# common # common
![Version: 4.0.0](https://img.shields.io/badge/Version-4.0.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![Version: 4.0.1](https://img.shields.io/badge/Version-4.0.1-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square)
Function library for Helm charts Function library for Helm charts
@ -31,7 +31,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
# Chart.yaml # Chart.yaml
dependencies: dependencies:
- name: common - name: common
version: 4.0.0 version: 4.0.1
repository: https://bjw-s-labs.github.io/helm-charts/ repository: https://bjw-s-labs.github.io/helm-charts/
``` ```

View file

@ -4,10 +4,26 @@ Return a Route object by its Identifier.
{{- define "bjw-s.common.lib.route.getByIdentifier" -}} {{- define "bjw-s.common.lib.route.getByIdentifier" -}}
{{- $rootContext := .rootContext -}} {{- $rootContext := .rootContext -}}
{{- $identifier := .id -}} {{- $identifier := .id -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $rootContext) | fromYaml ) }} {{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if (hasKey $enabledRoutes $identifier) -}} {{- if (hasKey $enabledRoutes $identifier) -}}
{{- $objectValues := get $enabledRoutes $identifier -}} {{- $objectValues := get $enabledRoutes $identifier -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledRoutes)) -}} {{- $object := include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledRoutes)) | fromYaml -}}
{{- /* Try to automatically determine the default Service identifier if needed and possible */ -}}
{{- if eq 1 (len $enabledServices) -}}
{{- range $object.rules -}}
{{- range .backendRefs }}
{{- $backendRef := . -}}
{{- if and (empty (dig "name" nil $backendRef)) (empty (dig "identifier" nil $backendRef)) -}}
{{- $_ := set $backendRef "identifier" ($enabledServices | keys | first) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $object | toYaml -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

View file

@ -5,6 +5,21 @@ Validate Route values
{{- $rootContext := .rootContext -}} {{- $rootContext := .rootContext -}}
{{- $routeObject := .object -}} {{- $routeObject := .object -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{/* Verify automatic Service detection */}}
{{- if not (eq 1 (len $enabledServices)) -}}
{{- range $routeObject.rules -}}
{{- $rule := . -}}
{{- range $rule.backendRefs }}
{{- $backendRef := . -}}
{{- if and (empty (dig "name" nil $backendRef)) (empty (dig "identifier" nil $backendRef)) -}}
{{- fail (printf "Either name or identifier is required because automatic Service detection is not possible. (route: %s)" $routeObject.identifier) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/* Route Types */}} {{/* Route Types */}}
{{- $routeKind := $routeObject.kind | default "HTTPRoute"}} {{- $routeKind := $routeObject.kind | default "HTTPRoute"}}
{{- if and (ne $routeKind "GRPCRoute") (ne $routeKind "HTTPRoute") (ne $routeKind "TCPRoute") (ne $routeKind "TLSRoute") (ne $routeKind "UDPRoute") }} {{- if and (ne $routeKind "GRPCRoute") (ne $routeKind "HTTPRoute") (ne $routeKind "TCPRoute") (ne $routeKind "TLSRoute") (ne $routeKind "UDPRoute") }}

View file

@ -60,6 +60,30 @@ tests:
port: 8080 port: 8080
weight: 1 weight: 1
- it: automatic service and port reference should pass
values:
- ../_values/service_main_default.yaml
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs: [{}]
documentSelector:
path: $[?(@.kind == "HTTPRoute")].metadata.name
value: release-name
asserts:
- equal:
path: spec.rules[0].backendRefs[0]
value:
group: ""
kind: Service
name: release-name
namespace: NAMESPACE
port: 8081
weight: 1
- it: custom service reference should pass - it: custom service reference should pass
set: set:
route.main: route.main:

View file

@ -41,3 +41,40 @@ tests:
asserts: asserts:
- failedTemplate: - failedTemplate:
errorMessage: "backend refs and request redirect filters cannot co-exist." errorMessage: "backend refs and request redirect filters cannot co-exist."
- it: automatic service determination should fail when no service is enabled
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- port: 8080
asserts:
- failedTemplate:
errorMessage: "Either name or identifier is required because automatic Service detection is not possible. (route: main)"
- it: automatic service determination should fail when >1 service is enabled
set:
service:
main:
controller: main
ports:
ui:
port: 8082
second:
controller: main
ports:
ui:
port: 8082
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- port: 8080
asserts:
- failedTemplate:
errorMessage: "Either name or identifier is required because automatic Service detection is not possible. (route: main)"

View file

@ -0,0 +1,54 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: service - fields - selector
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
- ../_values/service_main_default.yaml
tests:
- it: selector is configured by default
documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: release-name
asserts:
- equal:
path: spec.selector
value:
app.kubernetes.io/controller: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME
- it: additional selector labels can be configured
set:
service:
main:
extraSelectorLabels:
extraLabel: extraValue
documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: release-name
asserts:
- equal:
path: spec.selector
value:
app.kubernetes.io/controller: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME
extraLabel: extraValue
- it: selector can determine default controller automatically
set:
service:
main:
controller: ""
documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: release-name
asserts:
- equal:
path: spec.selector
value:
app.kubernetes.io/controller: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME

View file

@ -42,7 +42,6 @@ tests:
- failedTemplate: - failedTemplate:
errorMessage: "controller field is required because automatic controller detection is not possible. (service: main)" errorMessage: "controller field is required because automatic controller detection is not possible. (service: main)"
- it: no ports enabled should fail - it: no ports enabled should fail
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml

View file

@ -1,6 +1,6 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema", "$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.0/charts/library/common/values.schema.json", "$id": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.1/charts/library/common/values.schema.json",
"type": "object", "type": "object",
"properties": { "properties": {
"global": { "global": {

View file

@ -2,7 +2,7 @@
apiVersion: v2 apiVersion: v2
description: A common powered chart template. This can be useful for small projects that don't have their own chart. description: A common powered chart template. This can be useful for small projects that don't have their own chart.
name: app-template name: app-template
version: 4.0.0 version: 4.0.1
kubeVersion: ">=1.28.0-0" kubeVersion: ">=1.28.0-0"
maintainers: maintainers:
- name: bjw-s - name: bjw-s
@ -10,16 +10,16 @@ maintainers:
dependencies: dependencies:
- name: common - name: common
repository: https://bjw-s-labs.github.io/helm-charts repository: https://bjw-s-labs.github.io/helm-charts
version: 4.0.0 version: 4.0.1
sources: sources:
- https://github.com/bjw-s-labs/helm-charts - https://github.com/bjw-s-labs/helm-charts
annotations: annotations:
artifacthub.io/changes: |- artifacthub.io/changes: |-
- kind: changed - kind: changed
description: |- description: |-
Upgraded the common library to v4.0.0 Upgraded the common library to v4.0.1
links: links:
- name: Upgrade notes - name: Upgrade notes
url: https://bjw-s-labs.github.io/helm-charts/docs/app-template/upgrade-instructions/ url: https://bjw-s-labs.github.io/helm-charts/docs/app-template/upgrade-instructions/
- name: Detailed release notes - name: Detailed release notes
url: https://github.com/bjw-s-labs/helm-charts/releases/tag/common-4.0.0 url: https://github.com/bjw-s-labs/helm-charts/releases/tag/common-4.0.1

View file

@ -1,6 +1,6 @@
# app-template # app-template
![Version: 4.0.0](https://img.shields.io/badge/Version-4.0.0-informational?style=flat-square) ![Version: 4.0.1](https://img.shields.io/badge/Version-4.0.1-informational?style=flat-square)
A common powered chart template. This can be useful for small projects that don't have their own chart. A common powered chart template. This can be useful for small projects that don't have their own chart.
@ -12,7 +12,7 @@ Kubernetes: `>=1.28.0-0`
| Repository | Name | Version | | Repository | Name | Version |
|------------|------|---------| |------------|------|---------|
| https://bjw-s-labs.github.io/helm-charts | common | 4.0.0 | | https://bjw-s-labs.github.io/helm-charts | common | 4.0.1 |
## Installing the Chart ## Installing the Chart

View file

@ -726,7 +726,7 @@
"values": { "values": {
"description": "Values holds the values for this Helm release.", "description": "Values holds the values for this Helm release.",
"x-kubernetes-preserve-unknown-fields": true, "x-kubernetes-preserve-unknown-fields": true,
"$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.0/charts/library/common/values.schema.json" "$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.1/charts/library/common/values.schema.json"
}, },
"valuesFrom": { "valuesFrom": {
"description": "ValuesFrom holds references to resources containing Helm values for this HelmRelease,\nand information about how they should be merged.", "description": "ValuesFrom holds references to resources containing Helm values for this HelmRelease,\nand information about how they should be merged.",

View file

@ -727,7 +727,7 @@
"values": { "values": {
"description": "Values holds the values for this Helm release.", "description": "Values holds the values for this Helm release.",
"x-kubernetes-preserve-unknown-fields": true, "x-kubernetes-preserve-unknown-fields": true,
"$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.0/charts/library/common/values.schema.json" "$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.1/charts/library/common/values.schema.json"
}, },
"valuesFrom": { "valuesFrom": {
"description": "ValuesFrom holds references to resources containing Helm values for this HelmRelease, and information about how they should be merged.", "description": "ValuesFrom holds references to resources containing Helm values for this HelmRelease, and information about how they should be merged.",

View file

@ -1,3 +1,3 @@
{ {
"$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.0/charts/library/common/values.schema.json" "$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.1/charts/library/common/values.schema.json"
} }