From 72cbacc0cda420389d83efc6e0c9580401acb878 Mon Sep 17 00:00:00 2001 From: Bernd Schorgers Date: Thu, 12 Jun 2025 13:19:46 +0200 Subject: [PATCH] fix(common): Release v4.1.1 (#428) --- charts/library/common/Chart.yaml | 24 ++-------- charts/library/common/README.md | 4 +- .../common/templates/lib/pod/_getOption.tpl | 30 ++++++------- .../lib/routes/_autoDetectService.tpl | 4 ++ .../pod/field_nodeSelector_test.yaml | 18 ++++++++ .../route/field_backendRefs_test.yaml | 45 +++++++++++++++++++ charts/library/common/values.schema.json | 2 +- 7 files changed, 88 insertions(+), 39 deletions(-) diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index 84bdc6a4..5399a662 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -3,7 +3,7 @@ apiVersion: v2 name: common description: Function library for Helm charts type: library -version: 4.1.0 +version: 4.1.1 kubeVersion: ">=1.28.0-0" keywords: - common @@ -18,25 +18,7 @@ annotations: artifacthub.io/changes: |- - kind: fixed description: |- - Fixed a bug where probes were not being configured correctly for Services that autodetect their controller. + Fixed an edge-case bug where specifying a merge defaultPodOptionsStrategy could crash the chart. - kind: fixed description: |- - Fixed a bug where topologySpreadConstraints field did not properly render Helm templates. - - kind: added - description: |- - Added support for configuring the `serviceName` field for StatefulSets. - - kind: added - description: |- - Added support for automatically selecting the ServiceAccount when only one is defined. - - kind: added - description: |- - - Added support for referencing target service for ServiceMonitors by identifier. - - kind: added - description: |- - Added support for automatically determining the target service for ServiceMonitors if there is only one enabled Service. - - kind: added - description: |- - Added support for always adding the identifier suffix even if there is only a single resource. - links: - - name: Updated documentation - url: https://bjw-s-labs.github.io/helm-charts/docs/common-library/resources/names/ + Fixed Route automatic service detection if there are no rules defined. diff --git a/charts/library/common/README.md b/charts/library/common/README.md index c9ba7f72..c2aed192 100644 --- a/charts/library/common/README.md +++ b/charts/library/common/README.md @@ -1,6 +1,6 @@ # common -![Version: 4.1.0](https://img.shields.io/badge/Version-4.1.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) +![Version: 4.1.1](https://img.shields.io/badge/Version-4.1.1-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) Function library for Helm charts @@ -31,7 +31,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g. # Chart.yaml dependencies: - name: common - version: 4.1.0 + version: 4.1.1 repository: https://bjw-s-labs.github.io/helm-charts/ ``` diff --git a/charts/library/common/templates/lib/pod/_getOption.tpl b/charts/library/common/templates/lib/pod/_getOption.tpl index f18d7887..353bab65 100644 --- a/charts/library/common/templates/lib/pod/_getOption.tpl +++ b/charts/library/common/templates/lib/pod/_getOption.tpl @@ -5,32 +5,32 @@ Returns the value for the specified field {{- $rootContext := .ctx.rootContext -}} {{- $controllerObject := .ctx.controllerObject -}} {{- $option := .option -}} - {{- $default := default "" .default -}} + {{- $default := default nil .default -}} {{- $value := $default -}} {{- $defaultPodOptionsStrategy := dig "defaultPodOptionsStrategy" "overwrite" $rootContext.Values -}} - {{- /* Set to the default if it is set */ -}} - {{- $defaultOption := dig $option nil (default dict $rootContext.Values.defaultPodOptions) -}} - {{- if kindIs "bool" $defaultOption -}} - {{- $value = $defaultOption -}} - {{- else if not (empty $defaultOption) -}} - {{- $value = $defaultOption -}} + {{- /* Set to the default Pod option if one is set */ -}} + {{- $defaultPodOption := dig $option nil (default dict $rootContext.Values.defaultPodOptions) -}} + {{- if kindIs "bool" $defaultPodOption -}} + {{- $value = $defaultPodOption -}} + {{- else if not (empty $defaultPodOption) -}} + {{- $value = $defaultPodOption -}} {{- end -}} {{- /* See if a pod-specific override is needed */ -}} - {{- $podOption := dig $option nil (default dict $controllerObject.pod) -}} + {{- $podSpecificOption := dig $option nil (default dict $controllerObject.pod) -}} - {{- if kindIs "bool" $podOption -}} - {{- $value = $podOption -}} - {{- else if kindIs "map" $podOption -}} + {{- if kindIs "bool" $podSpecificOption -}} + {{- $value = $podSpecificOption -}} + {{- else if kindIs "map" $podSpecificOption -}} {{- if eq "merge" $defaultPodOptionsStrategy -}} - {{- $value = merge $podOption $value -}} + {{- $value = merge $podSpecificOption $value -}} {{- else if eq "overwrite" $defaultPodOptionsStrategy -}} - {{- $value = $podOption -}} + {{- $value = $podSpecificOption -}} {{- end -}} - {{- else if not (empty $podOption) -}} - {{- $value = $podOption -}} + {{- else if not (empty $podSpecificOption) -}} + {{- $value = $podSpecificOption -}} {{- end -}} {{- if kindIs "bool" $value -}} diff --git a/charts/library/common/templates/lib/routes/_autoDetectService.tpl b/charts/library/common/templates/lib/routes/_autoDetectService.tpl index ed882bba..f11d0929 100644 --- a/charts/library/common/templates/lib/routes/_autoDetectService.tpl +++ b/charts/library/common/templates/lib/routes/_autoDetectService.tpl @@ -7,6 +7,10 @@ Autodetects the service for a Route object {{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) -}} {{- if eq 1 (len $enabledServices) -}} + {{- if empty $routeObject.rules -}} + {{- $_ := set $routeObject "rules" (list (dict "backendRefs" (list dict))) -}} + {{- end -}} + {{- range $routeObject.rules -}} {{- range .backendRefs }} {{- $backendRef := . -}} diff --git a/charts/library/common/test-chart/unittests/pod/field_nodeSelector_test.yaml b/charts/library/common/test-chart/unittests/pod/field_nodeSelector_test.yaml index 6a897995..a1da7e4c 100644 --- a/charts/library/common/test-chart/unittests/pod/field_nodeSelector_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_nodeSelector_test.yaml @@ -47,3 +47,21 @@ tests: path: spec.template.spec.nodeSelector value: disktype: hdd + + - it: empty defaultPodOptions with pod override can be merged + set: + defaultPodOptionsStrategy: merge + defaultPodOptions: {} + controllers: + main: + pod: + nodeSelector: + location: apartment + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.spec.nodeSelector + value: + location: apartment diff --git a/charts/library/common/test-chart/unittests/route/field_backendRefs_test.yaml b/charts/library/common/test-chart/unittests/route/field_backendRefs_test.yaml index 0789cc13..12dcb890 100644 --- a/charts/library/common/test-chart/unittests/route/field_backendRefs_test.yaml +++ b/charts/library/common/test-chart/unittests/route/field_backendRefs_test.yaml @@ -136,3 +136,48 @@ tests: statusCode: 301 - notExists: path: spec.rules[0].backendRefs[0] + + - it: automatic service and port reference should pass with empty rules + values: + - ../_values/service_main_default.yaml + set: + route.main: + parentRefs: + - name: parentName + namespace: parentNamespace + rules: [] + 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: automatic service and port reference should pass with absent rules field + values: + - ../_values/service_main_default.yaml + set: + route.main: + parentRefs: + - name: parentName + namespace: parentNamespace + 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 diff --git a/charts/library/common/values.schema.json b/charts/library/common/values.schema.json index 091d2f25..bcbeb8b2 100644 --- a/charts/library/common/values.schema.json +++ b/charts/library/common/values.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema", - "$id": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.1.0/charts/library/common/values.schema.json", + "$id": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.1.1/charts/library/common/values.schema.json", "type": "object", "properties": { "global": {