diff --git a/.ci/mkdocs/requirements.txt b/.ci/mkdocs/requirements.txt index f597a3ff..7f9a03cc 100644 --- a/.ci/mkdocs/requirements.txt +++ b/.ci/mkdocs/requirements.txt @@ -1,4 +1,4 @@ -mkdocs==1.4.1 +mkdocs==1.4.2 mkdocs-macros-plugin ==0.7.0 mkdocs-material ==8.5.7 mkdocs-minify-plugin==0.6.1 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index ec7b8c36..430fcda8 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -10,28 +10,39 @@ Thank you for contributing! I will try to test and integrate the change as soon Also don't be worried if the request is closed or not integrated. Sometimes our priorities might not match the priorities of the pull request. Don't fret, the open source community thrives on forks and GitHub makes it easy to keep your changes in a forked repo. --> -**Description of the change** +### Description of the change + - +#### Removed + -**Benefits** +#### Fixed + +#### Added + + +#### Changed + + +### Benefits -**Possible drawbacks** - +### Possible drawbacks -**Applicable issues** - +### Applicable issues - fixes # -**Additional information** - +## Additional information -**Checklist** +## Checklist + - [ ] Title of the PR conforms to the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard. - [ ] Scope of the of the PR title contains the chart name. - [ ] Chart version in `Chart.yaml` has been bumped according to [Semantic Versioning](https://semver.org/). diff --git a/.github/workflows/charts-test.yaml b/.github/workflows/charts-test.yaml index 2496852d..0f6b4c32 100644 --- a/.github/workflows/charts-test.yaml +++ b/.github/workflows/charts-test.yaml @@ -29,7 +29,7 @@ jobs: strategy: matrix: chart: ${{ fromJSON(inputs.chartsToTest) }} - k8s_version: ["v1.22.12", "v1.24.3"] + k8s_version: ["v1.22.15", "v1.23.13", "v1.24.7", "v1.25.3"] fail-fast: false steps: - name: Checkout diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index 0c11cb32..ffcd5a4c 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -1,9 +1,10 @@ +--- apiVersion: v2 name: common description: Function library for Helm charts type: library -version: 0.2.2 -kubeVersion: ">=1.16.0-0" +version: 1.0.0 +kubeVersion: ">=1.22.0-0" keywords: - common - library @@ -13,7 +14,27 @@ maintainers: email: me@bjw-s.dev annotations: artifacthub.io/changes: |- - - kind: fixed - description: Fix deprecation warning on unsupported vpn types. + - kind: removed + description: "**BREAKING**: Removed support for HorizontalPodAutoscaler" + - kind: added + description: Added support for `httpGet` probes + - kind: added + description: Added support for setting labels / annotations on volumeClaimTemplates + - kind: added + description: Support services have extraSelectorLabels - kind: changed - description: Updated code-server image to v4.7.1 + description: "**BREAKING**: Restructure of template components. All Helm template names have changed!" + - kind: changed + description: "**BREAKING**: Raised minimum supported k8s version to 1.22" + - kind: changed + description: "**BREAKING**: Renamed `configmap` key to `configMaps`" + - kind: changed + description: "**BREAKING**: Moved `serviceMonitor` from `service` to its own key" + - kind: changed + description: "**BREAKING**: Renamed `secret` key to `secrets`, which now works similar to `configMaps`" + - kind: changed + description: Updated code-server image to v4.8.2 + - kind: changed + description: Updated gluetun image to v3.32.0 + - kind: fixed + description: Fix NOTES always showing ingress protocol as http diff --git a/charts/library/common/README.md b/charts/library/common/README.md index 8721e3f4..62ae167f 100644 --- a/charts/library/common/README.md +++ b/charts/library/common/README.md @@ -1,6 +1,6 @@ # common -![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) +![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) Function library for Helm charts @@ -8,7 +8,7 @@ Since a lot of the bjw-s charts follow a similar pattern, this library was built ## Requirements -Kubernetes: `>=1.16.0-0` +Kubernetes: `>=1.22.0-0` ## Dependencies @@ -29,7 +29,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g. # Chart.yaml dependencies: - name: common - version: 0.2.0 + version: 1.0.0 repository: https://bjw-s.github.io/helm-charts/ ``` @@ -61,9 +61,9 @@ N/A | addons.codeserver.git.deployKeySecret | string | `""` | Existing secret containing SSH private key The chart expects it to be present under the `id_rsa` key. | | addons.codeserver.image.pullPolicy | string | `"IfNotPresent"` | Specify the code-server image pull policy | | addons.codeserver.image.repository | string | `"ghcr.io/coder/code-server"` | Specify the code-server image | -| addons.codeserver.image.tag | string | `"4.7.0"` | Specify the code-server image tag | +| addons.codeserver.image.tag | string | `"4.8.2"` | Specify the code-server image tag | | addons.codeserver.ingress.enabled | bool | `false` | Enable an ingress for the code-server add-on. | -| addons.codeserver.ingress.ingressClassName | string | `nil` | Set the ingressClass that is used for this ingress. Requires Kubernetes >=1.19 | +| addons.codeserver.ingress.ingressClassName | string | `nil` | Set the ingressClass that is used for this ingress. | | addons.codeserver.service.enabled | bool | `true` | Enable a service for the code-server add-on. | | addons.codeserver.volumeMounts | list | `[]` | Specify a list of volumes that get mounted in the code-server container. At least 1 volumeMount is required! | | addons.codeserver.workingDir | string | `""` | Specify the working dir that will be opened when code-server starts If not given, the app will default to the mountpah of the first specified volumeMount | @@ -92,7 +92,7 @@ N/A | addons.vpn.gluetun | object | See below | Gluetun specific configuration -- Make sure to read the [documentation](https://github.com/qdm12/gluetun/wiki) to see how to configure this addon! | | addons.vpn.gluetun.image.pullPolicy | string | `"IfNotPresent"` | Specify the Gluetun image pull policy | | addons.vpn.gluetun.image.repository | string | `"docker.io/qmcgaw/gluetun"` | Specify the Gluetun image | -| addons.vpn.gluetun.image.tag | string | `"v3.31.1"` | Specify the Gluetun image tag | +| addons.vpn.gluetun.image.tag | string | `"v3.32.0"` | Specify the Gluetun image tag | | addons.vpn.livenessProbe | object | `{}` | Optionally specify a livenessProbe, e.g. to check if the connection is still being protected by the VPN | | addons.vpn.networkPolicy.annotations | object | `{}` | Provide additional annotations which may be required. | | addons.vpn.networkPolicy.egress | string | `nil` | The egress configuration for your network policy, All outbound traffic from the pod will be blocked unless specified here. [[ref]](https://kubernetes.io/docs/concepts/services-networking/network-policies/) [[recipes]](https://github.com/ahmetb/kubernetes-network-policy-recipes) | @@ -105,13 +105,12 @@ N/A | affinity | object | `{}` | Defines affinity constraint rules. [[ref]](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity) | | args | list | `[]` | Override the args for the default container | | automountServiceAccountToken | bool | `true` | Specifies whether a service account token should be automatically mounted. | -| autoscaling | object | | Add a Horizontal Pod Autoscaler | | command | list | `[]` | Override the command(s) for the default container | -| configmap | object | See below | Configure configMaps for the chart here. Additional configMaps can be added by adding a dictionary key similar to the 'config' object. | -| configmap.config.annotations | object | `{}` | Annotations to add to the configMap | -| configmap.config.data | object | `{}` | configMap data content. Helm template enabled. | -| configmap.config.enabled | bool | `false` | Enables or disables the configMap | -| configmap.config.labels | object | `{}` | Labels to add to the configMap | +| configMaps | object | See below | Configure configMaps for the chart here. Additional configMaps can be added by adding a dictionary key similar to the 'config' object. | +| configMaps.config.annotations | object | `{}` | Annotations to add to the configMap | +| configMaps.config.data | object | `{}` | configMap data content. Helm template enabled. | +| configMaps.config.enabled | bool | `false` | Enables or disables the configMap | +| configMaps.config.labels | object | `{}` | Labels to add to the configMap | | controller.annotations | object | `{}` | Set annotations on the deployment/statefulset/daemonset | | controller.enabled | bool | `true` | enable the controller. | | controller.labels | object | `{}` | Set labels on the deployment/statefulset/daemonset | @@ -144,10 +143,9 @@ N/A | ingress.main.enabled | bool | `false` | Enables or disables the ingress | | ingress.main.hosts[0].host | string | `"chart-example.local"` | Host address. Helm template can be passed. | | ingress.main.hosts[0].paths[0].path | string | `"/"` | Path. Helm template can be passed. | -| ingress.main.hosts[0].paths[0].pathType | string | `"Prefix"` | Ignored if not kubeVersion >= 1.14-0 | | ingress.main.hosts[0].paths[0].service.name | string | `nil` | Overrides the service name reference for this path | | ingress.main.hosts[0].paths[0].service.port | string | `nil` | Overrides the service port reference for this path | -| ingress.main.ingressClassName | string | `nil` | Set the ingressClass that is used for this ingress. Requires Kubernetes >=1.19 | +| ingress.main.ingressClassName | string | `nil` | Set the ingressClass that is used for this ingress. | | ingress.main.labels | object | `{}` | Provide additional labels which may be required. | | ingress.main.nameOverride | string | `nil` | Override the name suffix that is used for this ingress. | | ingress.main.primary | bool | `true` | Make this the primary ingress (used in probes, notes, etc...). If there is more than 1 ingress, make sure that only 1 ingress is marked as primary. | @@ -180,18 +178,25 @@ N/A | probes.liveness.custom | bool | `false` | Set this to `true` if you wish to specify your own livenessProbe | | probes.liveness.enabled | bool | `true` | Enable the liveness probe | | probes.liveness.spec | object | See below | The spec field contains the values for the default livenessProbe. If you selected `custom: true`, this field holds the definition of the livenessProbe. | +| probes.liveness.type | string | "TCP" | sets the probe type when not using a custom probe | | probes.readiness | object | See below | Redainess probe configuration | | probes.readiness.custom | bool | `false` | Set this to `true` if you wish to specify your own readinessProbe | | probes.readiness.enabled | bool | `true` | Enable the readiness probe | | probes.readiness.spec | object | See below | The spec field contains the values for the default readinessProbe. If you selected `custom: true`, this field holds the definition of the readinessProbe. | +| probes.readiness.type | string | "TCP" | sets the probe type when not using a custom probe | | probes.startup | object | See below | Startup probe configuration | | probes.startup.custom | bool | `false` | Set this to `true` if you wish to specify your own startupProbe | | probes.startup.enabled | bool | `true` | Enable the startup probe | | probes.startup.spec | object | See below | The spec field contains the values for the default startupProbe. If you selected `custom: true`, this field holds the definition of the startupProbe. | +| probes.startup.type | string | "TCP" | sets the probe type when not using a custom probe | | resources | object | `{}` | Set the resource requests / limits for the main container. | | runtimeClassName | string | `nil` | Allow specifying a runtimeClassName other than the default one (ie: nvidia) | | schedulerName | string | `nil` | Allows specifying a custom scheduler name | -| secret | object | `{}` | Use this to populate a secret with the values you specify. Be aware that these values are not encrypted by default, and could therefore visible to anybody with access to the values.yaml file. | +| secrets | object | See below | Use this to populate secrets with the values you specify. Be aware that these values are not encrypted by default, and could therefore visible to anybody with access to the values.yaml file. Additional Secrets can be added by adding a dictionary key similar to the 'secret' object. | +| secrets.secret.annotations | object | `{}` | Annotations to add to the Secret | +| secrets.secret.enabled | bool | `false` | Enables or disables the Secret | +| secrets.secret.labels | object | `{}` | Labels to add to the Secret | +| secrets.secret.stringData | object | `{}` | Secret stringData content. Helm template enabled. | | securityContext | object | `{}` | Configure the Security Context for the main container | | service | object | See below | Configure the services for the chart here. Additional services can be added by adding a dictionary key similar to the 'main' service. | | service.main.annotations | object | `{}` | Provide additional annotations which may be required. | @@ -200,12 +205,10 @@ N/A | service.main.ipFamilies | list | `[]` | The ip families that should be used. Options: IPv4, IPv6 | | service.main.ipFamilyPolicy | string | `nil` | Specify the ip policy. Options: SingleStack, PreferDualStack, RequireDualStack | | service.main.labels | object | `{}` | Provide additional labels which may be required. | -| service.main.monitor | object | See below | Configure a serviceMonitor for this Service. | -| service.main.monitor.enabled | bool | `false` | Enables or disables the serviceMonitor. | -| service.main.monitor.endpoints | list | See values.yaml | Configures the endpoints for the serviceMonitor. | | service.main.nameOverride | string | `nil` | Override the name suffix that is used for this service | | service.main.ports | object | See below | Configure the Service port information here. Additional ports can be added by adding a dictionary key similar to the 'http' service. | | service.main.ports.http.enabled | bool | `true` | Enables or disables the port | +| service.main.ports.http.extraSelectorLabels | object | `{}` | Allow adding additional match labels | | service.main.ports.http.nodePort | string | `nil` | Specify the nodePort value for the LoadBalancer and NodePort service types. [[ref]](https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport) | | service.main.ports.http.port | string | `nil` | The port number | | service.main.ports.http.primary | bool | `true` | Make this the primary port (used in probes, notes, etc...) If there is more than 1 service, make sure that only 1 port is marked as primary. | @@ -216,6 +219,14 @@ N/A | serviceAccount.annotations | object | `{}` | Annotations to add to the service account | | serviceAccount.create | bool | `false` | Specifies whether a service account should be created | | serviceAccount.name | string | `""` | The name of the service account to use. If not set and create is true, a name is generated using the fullname template | +| serviceMonitor | object | See below | Configure the ServiceMonitors for the chart here. Additional ServiceMonitors can be added by adding a dictionary key similar to the 'main' ServiceMonitors. | +| serviceMonitor.main.annotations | object | `{}` | Provide additional annotations which may be required. | +| serviceMonitor.main.enabled | bool | `false` | Enables or disables the serviceMonitor. | +| serviceMonitor.main.endpoints | list | See values.yaml | Configures the endpoints for the serviceMonitor. | +| serviceMonitor.main.labels | object | `{}` | Provide additional labels which may be required. | +| serviceMonitor.main.nameOverride | string | `nil` | Override the name suffix that is used for this serviceMonitor. | +| serviceMonitor.main.selector | object | `{}` | Configures a custom selector for the serviceMonitor, this takes precedence over specifying a service name. Helm templates can be used. | +| serviceMonitor.main.serviceName | string | `"main"` | Configures the target Service for the serviceMonitor. Helm templates can be used. | | termination.gracePeriodSeconds | string | `nil` | Duration in seconds the pod needs to terminate gracefully -- [[ref](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#lifecycle)] | | termination.messagePath | string | `nil` | Configure the path at which the file to which the main container's termination message will be written. -- [[ref](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#lifecycle-1)] | | termination.messagePolicy | string | `nil` | Indicate how the main container's termination message should be populated. Valid options are `File` and `FallbackToLogsOnError`. -- [[ref](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#lifecycle-1)] | diff --git a/charts/library/common/templates/_all.tpl b/charts/library/common/templates/_all.tpl deleted file mode 100644 index e844bfb7..00000000 --- a/charts/library/common/templates/_all.tpl +++ /dev/null @@ -1,58 +0,0 @@ -{{/* -Main entrypoint for the common library chart. It will render all underlying templates based on the provided values. -*/}} -{{- define "common.all" -}} - {{- /* Merge the local chart values and the common chart defaults */ -}} - {{- include "common.values.setup" . }} - - {{- /* Enable code-server add-on if required */ -}} - {{- if .Values.addons.codeserver.enabled }} - {{- include "common.addon.codeserver" . }} - {{- end -}} - - {{- /* Enable VPN add-on if required */ -}} - {{- if .Values.addons.vpn.enabled }} - {{- include "common.addon.vpn" . }} - {{- end -}} - - {{- /* Enable promtail add-on if required */ -}} - {{- if .Values.addons.promtail.enabled }} - {{- include "common.addon.promtail" . }} - {{- end -}} - - {{- /* Enable netshoot add-on if required */ -}} - {{- if .Values.addons.netshoot.enabled }} - {{- include "common.addon.netshoot" . }} - {{- end -}} - - {{ include "common.configmap" . | nindent 0 }} - - {{- /* Build the templates */ -}} - {{- include "common.pvc" . }} - - {{- if .Values.serviceAccount.create -}} - {{- include "common.serviceAccount" . }} - {{- end -}} - - {{- if .Values.controller.enabled }} - {{- if eq .Values.controller.type "deployment" }} - {{- include "common.deployment" . | nindent 0 }} - {{ else if eq .Values.controller.type "daemonset" }} - {{- include "common.daemonset" . | nindent 0 }} - {{ else if eq .Values.controller.type "statefulset" }} - {{- include "common.statefulset" . | nindent 0 }} - {{ else }} - {{- fail (printf "Not a valid controller.type (%s)" .Values.controller.type) }} - {{- end -}} - {{- end -}} - - {{ include "common.classes.hpa" . | nindent 0 }} - - {{ include "common.service" . | nindent 0 }} - - {{ include "common.ingress" . | nindent 0 }} - - {{- if .Values.secret -}} - {{ include "common.secret" . | nindent 0 }} - {{- end -}} -{{- end -}} diff --git a/charts/library/common/templates/_daemonset.tpl b/charts/library/common/templates/_daemonset.tpl deleted file mode 100644 index ed336d97..00000000 --- a/charts/library/common/templates/_daemonset.tpl +++ /dev/null @@ -1,35 +0,0 @@ -{{/* -This template serves as the blueprint for the DaemonSet objects that are created -within the common library. -*/}} -{{- define "common.daemonset" }} ---- -apiVersion: apps/v1 -kind: DaemonSet -metadata: - name: {{ include "common.names.fullname" . }} - {{- with (merge (.Values.controller.labels | default dict) (include "common.labels" $ | fromYaml)) }} - labels: {{- toYaml . | nindent 4 }} - {{- end }} - {{- with (merge (.Values.controller.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} - annotations: {{- toYaml . | nindent 4 }} - {{- end }} -spec: - revisionHistoryLimit: {{ .Values.controller.revisionHistoryLimit }} - selector: - matchLabels: - {{- include "common.labels.selectorLabels" . | nindent 6 }} - template: - metadata: - {{- with include ("common.podAnnotations") . }} - annotations: - {{- . | nindent 8 }} - {{- end }} - labels: - {{- include "common.labels.selectorLabels" . | nindent 8 }} - {{- with .Values.podLabels }} - {{- toYaml . | nindent 8 }} - {{- end }} - spec: - {{- include "common.controller.pod" . | nindent 6 }} -{{- end }} diff --git a/charts/library/common/templates/_ingress.tpl b/charts/library/common/templates/_ingress.tpl deleted file mode 100644 index b14e1701..00000000 --- a/charts/library/common/templates/_ingress.tpl +++ /dev/null @@ -1,39 +0,0 @@ -{{/* Renders the Ingress objects required by the chart */}} -{{- define "common.ingress" -}} - {{- /* Generate named ingresses as required */ -}} - {{- range $name, $ingress := .Values.ingress }} - {{- if $ingress.enabled -}} - {{- $ingressValues := $ingress -}} - - {{/* set defaults */}} - {{- if and (not $ingressValues.nameOverride) (ne $name (include "common.ingress.primary" $)) -}} - {{- $_ := set $ingressValues "nameOverride" $name -}} - {{- end -}} - - {{- $_ := set $ "ObjectValues" (dict "ingress" $ingressValues) -}} - {{- include "common.classes.ingress" $ }} - {{- end }} - {{- end }} -{{- end }} - -{{/* Return the name of the primary ingress object */}} -{{- define "common.ingress.primary" -}} - {{- $enabledIngresses := dict -}} - {{- range $name, $ingress := .Values.ingress -}} - {{- if $ingress.enabled -}} - {{- $_ := set $enabledIngresses $name . -}} - {{- end -}} - {{- end -}} - - {{- $result := "" -}} - {{- range $name, $ingress := $enabledIngresses -}} - {{- if and (hasKey $ingress "primary") $ingress.primary -}} - {{- $result = $name -}} - {{- end -}} - {{- end -}} - - {{- if not $result -}} - {{- $result = keys $enabledIngresses | first -}} - {{- end -}} - {{- $result -}} -{{- end -}} diff --git a/charts/library/common/templates/_secret.tpl b/charts/library/common/templates/_secret.tpl deleted file mode 100644 index 616ee396..00000000 --- a/charts/library/common/templates/_secret.tpl +++ /dev/null @@ -1,17 +0,0 @@ -{{/* -The Secret object to be created. -*/}} -{{- define "common.secret" }} ---- -apiVersion: v1 -kind: Secret -metadata: - name: {{ include "common.names.fullname" . }} - labels: {{- include "common.labels" $ | nindent 4 }} - annotations: {{- include "common.annotations" $ | nindent 4 }} -type: Opaque -{{- with .Values.secret }} -stringData: - {{- toYaml . | nindent 2 }} -{{- end }} -{{- end }} diff --git a/charts/library/common/templates/_service.tpl b/charts/library/common/templates/_service.tpl deleted file mode 100644 index 2aa929c2..00000000 --- a/charts/library/common/templates/_service.tpl +++ /dev/null @@ -1,57 +0,0 @@ -{{/* -Renders the Service objects required by the chart. -*/}} -{{- define "common.service" -}} - {{- /* Generate named services as required */ -}} - {{- range $name, $service := .Values.service -}} - {{- if $service.enabled -}} - {{- $serviceValues := $service -}} - - {{/* set the default nameOverride to the service name */}} - {{- if and (not $serviceValues.nameOverride) (ne $name (include "common.service.primary" $)) -}} - {{- $_ := set $serviceValues "nameOverride" $name -}} - {{ end -}} - - {{/* Include the Service class */}} - {{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}} - {{- include "common.classes.service" $ | nindent 0 -}} - - {{/* Include a serviceMonitor if required */}} - {{- if ($service.monitor).enabled | default false -}} - {{- $_ := set $ "ObjectValues" (dict "serviceMonitor" $serviceValues.monitor) -}} - {{- $_ := set $.ObjectValues.serviceMonitor "nameOverride" $serviceValues.nameOverride -}} - - {{- $serviceName := include "common.names.fullname" $ -}} - {{- if and (hasKey $serviceValues "nameOverride") $serviceValues.nameOverride -}} - {{- $serviceName = printf "%v-%v" $serviceName $serviceValues.nameOverride -}} - {{ end -}} - {{- $_ := set $.ObjectValues.serviceMonitor "serviceName" $serviceName -}} - {{- include "common.classes.serviceMonitor" $ | nindent 0 -}} - {{- end -}} - {{- end -}} - {{- end -}} -{{- end }} - -{{/* -Return the primary service object -*/}} -{{- define "common.service.primary" -}} - {{- $enabledServices := dict -}} - {{- range $name, $service := .Values.service -}} - {{- if $service.enabled -}} - {{- $_ := set $enabledServices $name . -}} - {{- end -}} - {{- end -}} - - {{- $result := "" -}} - {{- range $name, $service := $enabledServices -}} - {{- if and (hasKey $service "primary") $service.primary -}} - {{- $result = $name -}} - {{- end -}} - {{- end -}} - - {{- if not $result -}} - {{- $result = keys $enabledServices | first -}} - {{- end -}} - {{- $result -}} -{{- end -}} diff --git a/charts/library/common/templates/_serviceaccount.tpl b/charts/library/common/templates/_serviceaccount.tpl deleted file mode 100644 index 66407509..00000000 --- a/charts/library/common/templates/_serviceaccount.tpl +++ /dev/null @@ -1,14 +0,0 @@ -{{/* -The ServiceAccount object to be created. -*/}} -{{- define "common.serviceAccount" }} ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ include "common.names.serviceAccountName" . }} - labels: {{- include "common.labels" $ | nindent 4 }} - {{- with (merge (.Values.serviceAccount.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} - annotations: {{- toYaml . | nindent 4 }} - {{- end }} -{{- end }} diff --git a/charts/library/common/templates/_statefulset.tpl b/charts/library/common/templates/_statefulset.tpl deleted file mode 100644 index 5923c2cb..00000000 --- a/charts/library/common/templates/_statefulset.tpl +++ /dev/null @@ -1,62 +0,0 @@ -{{/* -This template serves as the blueprint for the StatefulSet objects that are created -within the common library. -*/}} -{{- define "common.statefulset" }} ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: {{ include "common.names.fullname" . }} - {{- with (merge (.Values.controller.labels | default dict) (include "common.labels" $ | fromYaml)) }} - labels: {{- toYaml . | nindent 4 }} - {{- end }} - {{- with (merge (.Values.controller.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} - annotations: {{- toYaml . | nindent 4 }} - {{- end }} -spec: - revisionHistoryLimit: {{ .Values.controller.revisionHistoryLimit }} - replicas: {{ .Values.controller.replicas }} - podManagementPolicy: {{ default "OrderedReady" .Values.controller.podManagementPolicy }} - {{- $strategy := default "RollingUpdate" .Values.controller.strategy }} - {{- if and (ne $strategy "OnDelete") (ne $strategy "RollingUpdate") }} - {{- fail (printf "Not a valid strategy type for StatefulSet (%s)" $strategy) }} - {{- end }} - updateStrategy: - type: {{ $strategy }} - {{- if and (eq $strategy "RollingUpdate") .Values.controller.rollingUpdate.partition }} - rollingUpdate: - partition: {{ .Values.controller.rollingUpdate.partition }} - {{- end }} - selector: - matchLabels: - {{- include "common.labels.selectorLabels" . | nindent 6 }} - serviceName: {{ include "common.names.fullname" . }} - template: - metadata: - {{- with include ("common.podAnnotations") . }} - annotations: - {{- . | nindent 8 }} - {{- end }} - labels: - {{- include "common.labels.selectorLabels" . | nindent 8 }} - {{- with .Values.podLabels }} - {{- toYaml . | nindent 8 }} - {{- end }} - spec: - {{- include "common.controller.pod" . | nindent 6 }} - volumeClaimTemplates: - {{- range $index, $vct := .Values.volumeClaimTemplates }} - - metadata: - name: {{ $vct.name }} - spec: - accessModes: - - {{ required (printf "accessMode is required for vCT %v" $vct.name) $vct.accessMode | quote }} - resources: - requests: - storage: {{ required (printf "size is required for PVC %v" $vct.name) $vct.size | quote }} - {{- if $vct.storageClass }} - storageClassName: {{ if (eq "-" $vct.storageClass) }}""{{- else }}{{ $vct.storageClass | quote }}{{- end }} - {{- end }} - {{- end }} -{{- end }} diff --git a/charts/library/common/templates/addons/code-server/_addon.tpl b/charts/library/common/templates/addons/code-server/_addon.tpl new file mode 100644 index 00000000..6c25c243 --- /dev/null +++ b/charts/library/common/templates/addons/code-server/_addon.tpl @@ -0,0 +1,40 @@ +{{/* +Template to render code-server addon +It will include / inject the required templates based on the given values. +*/}} +{{- define "bjw-s.common.addon.codeserver" -}} + {{- if .Values.addons.codeserver.enabled -}} + {{/* Append the code-server container to the additionalContainers */}} + {{- $container := include "bjw-s.common.addon.codeserver.container" . | fromYaml -}} + {{- if $container -}} + {{- $_ := set .Values.additionalContainers "addon-codeserver" $container -}} + {{- end -}} + + {{/* Include the deployKeySecret if not empty */}} + {{- if or .Values.addons.codeserver.git.deployKey .Values.addons.codeserver.git.deployKeyBase64 -}} + {{- $deployKeySecret := include "bjw-s.common.addon.codeserver.deployKeySecret" . -}} + {{- if $deployKeySecret -}} + {{- $_ := set .Values.secrets "addon-codeserver-deploykey" (dict "enabled" "true" "stringData" ($deployKeySecret | fromYaml)) -}} + {{- end -}} + {{- end -}} + + {{/* Append the secret volume to the volumes */}} + {{- if or .Values.addons.codeserver.git.deployKey .Values.addons.codeserver.git.deployKeyBase64 .Values.addons.codeserver.git.deployKeySecret }} + {{- $volume := include "bjw-s.common.addon.codeserver.deployKeyVolumeSpec" . | fromYaml -}} + {{- if $volume -}} + {{- $_ := set .Values.persistence "deploykey" (dict "enabled" "true" "mountPath" "-" "type" "custom" "volumeSpec" $volume) -}} + {{- end -}} + {{- end -}} + + {{/* Add the code-server service */}} + {{- $_ := set .Values.service "addon-codeserver" .Values.addons.codeserver.service -}} + + {{/* Add the code-server ingress */}} + {{- $svcName := printf "%v-addon-codeserver" (include "bjw-s.common.lib.chart.names.fullname" .) -}} + {{- $svcPort := .Values.addons.codeserver.service.ports.codeserver.port -}} + {{- range $_, $host := .Values.addons.codeserver.ingress.hosts -}} + {{- $_ := set (index $host.paths 0) "service" (dict "name" $svcName "port" $svcPort) -}} + {{- end -}} + {{- $_ := set .Values.ingress "addon-codeserver" .Values.addons.codeserver.ingress -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/addons/code-server/_codeserver.tpl b/charts/library/common/templates/addons/code-server/_codeserver.tpl deleted file mode 100644 index ef1ca677..00000000 --- a/charts/library/common/templates/addons/code-server/_codeserver.tpl +++ /dev/null @@ -1,50 +0,0 @@ -{{/* -Template to render code-server addon -It will include / inject the required templates based on the given values. -*/}} -{{- define "common.addon.codeserver" -}} -{{- if .Values.addons.codeserver.enabled -}} - {{/* Append the code-server container to the additionalContainers */}} - {{- $container := include "common.addon.codeserver.container" . | fromYaml -}} - {{- if $container -}} - {{- $_ := set .Values.additionalContainers "addon-codeserver" $container -}} - {{- end -}} - - {{/* Include the deployKeySecret if not empty */}} - {{- $secret := include "common.addon.codeserver.deployKeySecret" . -}} - {{- if $secret -}} - {{- $secret | nindent 0 -}} - {{- end -}} - - {{/* Append the secret volume to the volumes */}} - {{- $volume := include "common.addon.codeserver.deployKeyVolumeSpec" . | fromYaml -}} - {{- if $volume -}} - {{- $_ := set .Values.persistence "deploykey" (dict "enabled" "true" "mountPath" "-" "type" "custom" "volumeSpec" $volume) -}} - {{- end -}} - - {{/* Add the code-server service */}} - {{- if .Values.addons.codeserver.service.enabled -}} - {{- $serviceValues := .Values.addons.codeserver.service -}} - {{- $_ := set $serviceValues "nameOverride" "codeserver" -}} - {{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}} - {{- include "common.classes.service" $ -}} - {{- $_ := unset $ "ObjectValues" -}} - {{- end -}} - - {{/* Add the code-server ingress */}} - {{- if .Values.addons.codeserver.ingress.enabled -}} - {{- $ingressValues := .Values.addons.codeserver.ingress -}} - {{- $_ := set $ingressValues "nameOverride" "codeserver" -}} - - {{/* Determine the target service name & port */}} - {{- $svcName := printf "%v-codeserver" (include "common.names.fullname" .) -}} - {{- $svcPort := .Values.addons.codeserver.service.ports.codeserver.port -}} - {{- range $_, $host := $ingressValues.hosts -}} - {{- $_ := set (index $host.paths 0) "service" (dict "name" $svcName "port" $svcPort) -}} - {{- end -}} - {{- $_ := set $ "ObjectValues" (dict "ingress" $ingressValues) -}} - {{- include "common.classes.ingress" $ -}} - {{- $_ := unset $ "ObjectValues" -}} - {{- end -}} -{{- end -}} -{{- end -}} diff --git a/charts/library/common/templates/addons/code-server/_container.tpl b/charts/library/common/templates/addons/code-server/_container.tpl index 23af35ef..e906a157 100644 --- a/charts/library/common/templates/addons/code-server/_container.tpl +++ b/charts/library/common/templates/addons/code-server/_container.tpl @@ -1,7 +1,7 @@ {{/* The code-server sidecar container to be inserted. */}} -{{- define "common.addon.codeserver.container" -}} +{{- define "bjw-s.common.addon.codeserver.container" -}} {{- if lt (len .Values.addons.codeserver.volumeMounts) 1 }} {{- fail "At least 1 volumeMount is required for codeserver container" }} {{- end -}} diff --git a/charts/library/common/templates/addons/code-server/_secret.tpl b/charts/library/common/templates/addons/code-server/_secret.tpl index d80d73ea..74333d5e 100644 --- a/charts/library/common/templates/addons/code-server/_secret.tpl +++ b/charts/library/common/templates/addons/code-server/_secret.tpl @@ -1,22 +1,10 @@ {{/* -The OpenVPN credentials secrets to be included. +The deployKey secret to be included. */}} -{{- define "common.addon.codeserver.deployKeySecret" -}} -{{- if or .Values.addons.codeserver.git.deployKey .Values.addons.codeserver.git.deployKeyBase64 }} ---- -apiVersion: v1 -kind: Secret -metadata: - name: {{ template "common.names.fullname" . }}-deploykey - labels: {{- include "common.labels" $ | nindent 4 }} - annotations: {{- include "common.annotations" $ | nindent 4 }} -type: Opaque -{{- if .Values.addons.codeserver.git.deployKey }} -stringData: - id_rsa: {{ .Values.addons.codeserver.git.deployKey | quote }} -{{- else }} -data: - id_rsa: {{ .Values.addons.codeserver.git.deployKeyBase64 | quote }} -{{- end }} -{{- end }} +{{- define "bjw-s.common.addon.codeserver.deployKeySecret" -}} + {{- $deployKeyValue := .Values.addons.codeserver.git.deployKey -}} + {{- if .Values.addons.codeserver.git.deployKeyBase64 -}} + {{- $deployKeyValue = .Values.addons.codeserver.git.deployKeyBase64 | b64dec -}} + {{- end -}} +id_rsa: {{ $deployKeyValue | quote }} {{- end -}} diff --git a/charts/library/common/templates/addons/code-server/_volume.tpl b/charts/library/common/templates/addons/code-server/_volume.tpl index 8e294e6e..240f6714 100644 --- a/charts/library/common/templates/addons/code-server/_volume.tpl +++ b/charts/library/common/templates/addons/code-server/_volume.tpl @@ -1,17 +1,15 @@ {{/* The volume (referencing git deploykey) to be inserted into additionalVolumes. */}} -{{- define "common.addon.codeserver.deployKeyVolumeSpec" -}} -{{- if or .Values.addons.codeserver.git.deployKey .Values.addons.codeserver.git.deployKeyBase64 .Values.addons.codeserver.git.deployKeySecret }} +{{- define "bjw-s.common.addon.codeserver.deployKeyVolumeSpec" -}} secret: {{- if .Values.addons.codeserver.git.deployKeySecret }} secretName: {{ .Values.addons.codeserver.git.deployKeySecret }} {{- else }} - secretName: {{ include "common.names.fullname" . }}-deploykey + secretName: {{ include "bjw-s.common.lib.chart.names.fullname" . }}-addon-codeserver-deploykey {{- end }} defaultMode: {{ "0400" | toDecimal }} items: - key: id_rsa path: id_rsa {{- end -}} -{{- end -}} diff --git a/charts/library/common/templates/addons/netshoot/_netshoot.tpl b/charts/library/common/templates/addons/netshoot/_addon.tpl similarity index 74% rename from charts/library/common/templates/addons/netshoot/_netshoot.tpl rename to charts/library/common/templates/addons/netshoot/_addon.tpl index 9a1e9fae..25a88880 100644 --- a/charts/library/common/templates/addons/netshoot/_netshoot.tpl +++ b/charts/library/common/templates/addons/netshoot/_addon.tpl @@ -2,10 +2,10 @@ Template to render netshoot addon It will include / inject the required templates based on the given values. */}} -{{- define "common.addon.netshoot" -}} +{{- define "bjw-s.common.addon.netshoot" -}} {{- if .Values.addons.netshoot.enabled -}} {{/* Append the netshoot container to the additionalContainers */}} - {{- $container := include "common.addon.netshoot.container" . | fromYaml -}} + {{- $container := include "bjw-s.common.addon.netshoot.container" . | fromYaml -}} {{- if $container -}} {{- $_ := set .Values.additionalContainers "addon-netshoot" $container -}} {{- end -}} diff --git a/charts/library/common/templates/addons/netshoot/_container.tpl b/charts/library/common/templates/addons/netshoot/_container.tpl index 3e7a429c..91f0513b 100644 --- a/charts/library/common/templates/addons/netshoot/_container.tpl +++ b/charts/library/common/templates/addons/netshoot/_container.tpl @@ -1,7 +1,7 @@ {{/* The netshoot sidecar container to be inserted. */}} -{{- define "common.addon.netshoot.container" -}} +{{- define "bjw-s.common.addon.netshoot.container" -}} name: netshoot image: "{{ .Values.addons.netshoot.image.repository }}:{{ .Values.addons.netshoot.image.tag }}" imagePullPolicy: {{ .Values.addons.netshoot.pullPolicy }} diff --git a/charts/library/common/templates/addons/promtail/_addon.tpl b/charts/library/common/templates/addons/promtail/_addon.tpl new file mode 100644 index 00000000..b0e994ef --- /dev/null +++ b/charts/library/common/templates/addons/promtail/_addon.tpl @@ -0,0 +1,25 @@ +{{/* +Template to render promtail addon +It will include / inject the required templates based on the given values. +*/}} +{{- define "bjw-s.common.addon.promtail" -}} +{{- if .Values.addons.promtail.enabled -}} + {{/* Append the promtail container to the additionalContainers */}} + {{- $container := include "bjw-s.common.addon.promtail.container" . | fromYaml -}} + {{- if $container -}} + {{- $_ := set .Values.additionalContainers "addon-promtail" $container -}} + {{- end -}} + + {{/* Append the promtail configMap to the configmaps dict */}} + {{- $configmap := include "bjw-s.common.addon.promtail.configmap" . -}} + {{- if $configmap -}} + {{- $_ := set .Values.configMaps "addon-promtail" (dict "enabled" "true" "data" ($configmap | fromYaml)) -}} + {{- end -}} + + {{/* Append the promtail config volume to the volumes */}} + {{- $volume := include "bjw-s.common.addon.promtail.volumeSpec" . | fromYaml -}} + {{- if $volume -}} + {{- $_ := set .Values.persistence "addon-promtail" (dict "enabled" "true" "mountPath" "-" "type" "custom" "volumeSpec" $volume) -}} + {{- end -}} +{{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/addons/promtail/_configmap.tpl b/charts/library/common/templates/addons/promtail/_configmap.tpl index 5057f26a..49bc09cb 100644 --- a/charts/library/common/templates/addons/promtail/_configmap.tpl +++ b/charts/library/common/templates/addons/promtail/_configmap.tpl @@ -1,35 +1,25 @@ {{/* The promtail config to be included. */}} -{{- define "common.addon.promtail.configmap" -}} -{{- if .Values.addons.promtail.enabled }} ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ include "common.names.fullname" . }}-promtail - labels: {{- include "common.labels" $ | nindent 4 }} - annotations: {{- include "common.annotations" $ | nindent 4 }} -data: - promtail.yaml: | - server: - http_listen_port: 9080 - grpc_listen_port: 0 - positions: - filename: /tmp/positions.yaml - {{- with .Values.addons.promtail.loki }} - client: - url: {{ . }} - {{- end }} - scrape_configs: - {{- range .Values.addons.promtail.logs }} - - job_name: {{ .name }} - static_configs: - - targets: - - localhost - labels: - job: {{ .name }} - __path__: "{{ .path }}" - {{- end }} -{{- end -}} +{{- define "bjw-s.common.addon.promtail.configmap" -}} +promtail.yaml: | + server: + http_listen_port: 9080 + grpc_listen_port: 0 + positions: + filename: /tmp/positions.yaml + {{- with .Values.addons.promtail.loki }} + client: + url: {{ . }} + {{- end }} + scrape_configs: + {{- range .Values.addons.promtail.logs }} + - job_name: {{ .name }} + static_configs: + - targets: + - localhost + labels: + job: {{ .name }} + __path__: "{{ .path }}" + {{- end }} {{- end -}} diff --git a/charts/library/common/templates/addons/promtail/_container.tpl b/charts/library/common/templates/addons/promtail/_container.tpl index f4936bc4..1c74a330 100644 --- a/charts/library/common/templates/addons/promtail/_container.tpl +++ b/charts/library/common/templates/addons/promtail/_container.tpl @@ -1,7 +1,7 @@ {{/* The promtail sidecar container to be inserted. */}} -{{- define "common.addon.promtail.container" -}} +{{- define "bjw-s.common.addon.promtail.container" -}} {{- if lt (len .Values.addons.promtail.volumeMounts) 1 }} {{- fail "At least 1 volumeMount is required for the promtail container" }} {{- end -}} @@ -25,7 +25,7 @@ args: {{- end }} - "-config.file=/etc/promtail/promtail.yaml" volumeMounts: - - name: promtail-config + - name: addon-promtail mountPath: /etc/promtail/promtail.yaml subPath: promtail.yaml readOnly: true diff --git a/charts/library/common/templates/addons/promtail/_promtail.tpl b/charts/library/common/templates/addons/promtail/_promtail.tpl deleted file mode 100644 index c8ef10f9..00000000 --- a/charts/library/common/templates/addons/promtail/_promtail.tpl +++ /dev/null @@ -1,25 +0,0 @@ -{{/* -Template to render promtail addon -It will include / inject the required templates based on the given values. -*/}} -{{- define "common.addon.promtail" -}} -{{- if .Values.addons.promtail.enabled -}} - {{/* Append the promtail container to the additionalContainers */}} - {{- $container := include "common.addon.promtail.container" . | fromYaml -}} - {{- if $container -}} - {{- $_ := set .Values.additionalContainers "addon-promtail" $container -}} - {{- end -}} - - {{/* Include the configmap if not empty */}} - {{- $configmap := include "common.addon.promtail.configmap" . -}} - {{- if $configmap -}} - {{- $configmap | nindent 0 -}} - {{- end -}} - - {{/* Append the promtail config volume to the volumes */}} - {{- $volume := include "common.addon.promtail.volumeSpec" . | fromYaml -}} - {{- if $volume -}} - {{- $_ := set .Values.persistence "promtail-config" (dict "enabled" "true" "mountPath" "-" "type" "custom" "volumeSpec" $volume) -}} - {{- end -}} -{{- end -}} -{{- end -}} diff --git a/charts/library/common/templates/addons/promtail/_volume.tpl b/charts/library/common/templates/addons/promtail/_volume.tpl index bce624b5..c04712bd 100644 --- a/charts/library/common/templates/addons/promtail/_volume.tpl +++ b/charts/library/common/templates/addons/promtail/_volume.tpl @@ -1,7 +1,7 @@ {{/* The volume (referencing config) to be inserted into additionalVolumes. */}} -{{- define "common.addon.promtail.volumeSpec" -}} +{{- define "bjw-s.common.addon.promtail.volumeSpec" -}} configMap: - name: {{ include "common.names.fullname" . }}-promtail + name: {{ include "bjw-s.common.lib.chart.names.fullname" . }}-addon-promtail {{- end -}} diff --git a/charts/library/common/templates/addons/vpn/_vpn.tpl b/charts/library/common/templates/addons/vpn/_addon.tpl similarity index 50% rename from charts/library/common/templates/addons/vpn/_vpn.tpl rename to charts/library/common/templates/addons/vpn/_addon.tpl index 1c662baf..9e7b0262 100644 --- a/charts/library/common/templates/addons/vpn/_vpn.tpl +++ b/charts/library/common/templates/addons/vpn/_addon.tpl @@ -2,46 +2,42 @@ Template to render VPN addon It will include / inject the required templates based on the given values. */}} -{{- define "common.addon.vpn" -}} +{{- define "bjw-s.common.addon.vpn" -}} {{- if .Values.addons.vpn.enabled -}} - {{- if eq "openvpn" .Values.addons.vpn.type -}} - {{- fail "The 'openvpn' VPN type is no longer supported. Please migrate to the 'gluetun' type." }} - {{- end -}} - - {{- if eq "wireguard" .Values.addons.vpn.type -}} - {{- fail "The 'wireguard' VPN type is no longer supported. Please migrate to the 'gluetun' type." }} - {{- end -}} - {{- if eq "gluetun" .Values.addons.vpn.type -}} - {{- include "common.addon.gluetun" . }} + {{- include "bjw-s.common.addon.gluetun" . }} {{- end -}} {{/* Include the configmap if not empty */}} - {{- $configmap := include "common.addon.vpn.configmap" . -}} - {{- if $configmap -}} - {{- $configmap | nindent 0 -}} + {{- if or .Values.addons.vpn.scripts.up .Values.addons.vpn.scripts.down }} + {{- $configmap := include "bjw-s.common.addon.vpn.configmap" . -}} + {{- if $configmap -}} + {{- $_ := set .Values.configMaps "addon-vpn" (dict "enabled" "true" "data" ($configmap | fromYaml)) -}} + {{- end -}} {{- end -}} {{/* Include the secret if not empty */}} - {{- $secret := include "common.addon.vpn.secret" . -}} - {{- if $secret -}} - {{- $secret | nindent 0 -}} + {{- if and .Values.addons.vpn.configFile (not .Values.addons.vpn.configFileSecret) }} + {{- $secret := include "bjw-s.common.addon.vpn.secret" . -}} + {{- if $secret -}} + {{- $_ := set .Values.secrets "addon-vpn-config" (dict "enabled" "true" "stringData" ($secret | fromYaml)) -}} + {{- end -}} {{- end -}} {{/* Append the vpn scripts volume to the volumes */}} - {{- $scriptVolume := include "common.addon.vpn.scriptsVolumeSpec" . | fromYaml -}} + {{- $scriptVolume := include "bjw-s.common.addon.vpn.scriptsVolumeSpec" . | fromYaml -}} {{- if $scriptVolume -}} {{- $_ := set .Values.persistence "vpnscript" (dict "enabled" "true" "mountPath" "-" "type" "custom" "volumeSpec" $scriptVolume) -}} {{- end -}} {{/* Append the vpn config volume to the volumes */}} - {{- $configVolume := include "common.addon.vpn.configVolumeSpec" . | fromYaml }} + {{- $configVolume := include "bjw-s.common.addon.vpn.configVolumeSpec" . | fromYaml }} {{ if $configVolume -}} {{- $_ := set .Values.persistence "vpnconfig" (dict "enabled" "true" "mountPath" "-" "type" "custom" "volumeSpec" $configVolume) -}} {{- end -}} {{/* Include the networkpolicy if not empty */}} - {{- $networkpolicy := include "common.addon.vpn.networkpolicy" . -}} + {{- $networkpolicy := include "bjw-s.common.addon.vpn.networkpolicy" . -}} {{- if $networkpolicy -}} {{- $networkpolicy | nindent 0 -}} {{- end -}} diff --git a/charts/library/common/templates/addons/vpn/_configmap.tpl b/charts/library/common/templates/addons/vpn/_configmap.tpl index f99942ed..697edf91 100644 --- a/charts/library/common/templates/addons/vpn/_configmap.tpl +++ b/charts/library/common/templates/addons/vpn/_configmap.tpl @@ -1,23 +1,14 @@ {{/* The VPN config and scripts to be included. */}} -{{- define "common.addon.vpn.configmap" -}} -{{- if or .Values.addons.vpn.scripts.up .Values.addons.vpn.scripts.down }} ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ include "common.names.fullname" . }}-vpn - labels: {{- include "common.labels" $ | nindent 4 }} - annotations: {{- include "common.annotations" $ | nindent 4 }} -data: +{{- define "bjw-s.common.addon.vpn.configmap" -}} {{- with .Values.addons.vpn.scripts.up }} - up.sh: |- - {{- . | nindent 4}} +up.sh: |- + {{- . | nindent 2}} {{- end }} + {{- with .Values.addons.vpn.scripts.down }} - down.sh: |- - {{- . | nindent 4}} -{{- end }} +down.sh: |- + {{- . | nindent 2}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/addons/vpn/_networkpolicy.tpl b/charts/library/common/templates/addons/vpn/_networkpolicy.tpl index 7a860b48..e2cf55c4 100644 --- a/charts/library/common/templates/addons/vpn/_networkpolicy.tpl +++ b/charts/library/common/templates/addons/vpn/_networkpolicy.tpl @@ -1,22 +1,22 @@ {{/* Blueprint for the NetworkPolicy object that can be included in the addon. */}} -{{- define "common.addon.vpn.networkpolicy" -}} +{{- define "bjw-s.common.addon.vpn.networkpolicy" -}} {{- if .Values.addons.vpn.networkPolicy.enabled }} --- kind: NetworkPolicy apiVersion: networking.k8s.io/v1 metadata: - name: {{ include "common.names.fullname" . }} - {{- with (merge (.Values.addons.vpn.networkPolicy.labels | default dict) (include "common.labels" $ | fromYaml)) }} + name: {{ include "bjw-s.common.lib.chart.names.fullname" . }} + {{- with (merge (.Values.addons.vpn.networkPolicy.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml)) }} labels: {{- toYaml . | nindent 4 }} {{- end }} - {{- with (merge (.Values.addons.vpn.networkPolicy.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} + {{- with (merge (.Values.addons.vpn.networkPolicy.annotations | default dict) (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)) }} annotations: {{- toYaml . | nindent 4 }} {{- end }} spec: podSelector: - {{- with (merge .Values.addons.vpn.networkPolicy.podSelectorLabels (include "common.labels.selectorLabels" . | fromYaml)) }} + {{- with (merge .Values.addons.vpn.networkPolicy.podSelectorLabels (include "bjw-s.common.lib.metadata.selectorLabels" . | fromYaml)) }} matchLabels: {{- toYaml . | nindent 6 }} {{- end }} policyTypes: diff --git a/charts/library/common/templates/addons/vpn/_secret.tpl b/charts/library/common/templates/addons/vpn/_secret.tpl index 7527a2fd..5735e856 100644 --- a/charts/library/common/templates/addons/vpn/_secret.tpl +++ b/charts/library/common/templates/addons/vpn/_secret.tpl @@ -1,19 +1,9 @@ {{/* The OpenVPN config secret to be included. */}} -{{- define "common.addon.vpn.secret" -}} -{{- if and .Values.addons.vpn.configFile (not .Values.addons.vpn.configFileSecret) }} ---- -apiVersion: v1 -kind: Secret -metadata: - name: {{ include "common.names.fullname" . }}-vpnconfig - labels: {{- include "common.labels" $ | nindent 4 }} - annotations: {{- include "common.annotations" $ | nindent 4 }} -stringData: - {{- with .Values.addons.vpn.configFile }} - vpnConfigfile: |- - {{- . | nindent 4}} - {{- end }} +{{- define "bjw-s.common.addon.vpn.secret" -}} +{{- if and .Values.addons.vpn.configFile (not .Values.addons.vpn.configFileSecret) -}} +vpnConfigfile: |- + {{- .Values.addons.vpn.configFile | nindent 2 }} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/addons/vpn/_volume.tpl b/charts/library/common/templates/addons/vpn/_volume.tpl index 184e2a99..a9746155 100644 --- a/charts/library/common/templates/addons/vpn/_volume.tpl +++ b/charts/library/common/templates/addons/vpn/_volume.tpl @@ -1,10 +1,10 @@ {{/* The volume (referencing VPN scripts) to be inserted into additionalVolumes. */}} -{{- define "common.addon.vpn.scriptsVolumeSpec" -}} +{{- define "bjw-s.common.addon.vpn.scriptsVolumeSpec" -}} {{- if or .Values.addons.vpn.scripts.up .Values.addons.vpn.scripts.down -}} configMap: - name: {{ include "common.names.fullname" . }}-vpn + name: {{ include "bjw-s.common.lib.chart.names.fullname" . }}-addon-vpn items: {{- if .Values.addons.vpn.scripts.up }} - key: up.sh @@ -22,13 +22,13 @@ configMap: {{/* The volume (referencing VPN config) to be inserted into additionalVolumes. */}} -{{- define "common.addon.vpn.configVolumeSpec" -}} +{{- define "bjw-s.common.addon.vpn.configVolumeSpec" -}} {{- if or .Values.addons.vpn.configFile .Values.addons.vpn.configFileSecret -}} secret: {{- if .Values.addons.vpn.configFileSecret }} secretName: {{ .Values.addons.vpn.configFileSecret }} {{- else }} - secretName: {{ include "common.names.fullname" . }}-vpnconfig + secretName: {{ include "bjw-s.common.lib.chart.names.fullname" . }}-addon-vpn-config {{- end }} items: - key: vpnConfigfile diff --git a/charts/library/common/templates/addons/vpn/gluetun/_addon.tpl b/charts/library/common/templates/addons/vpn/gluetun/_addon.tpl index 43d32781..940263ad 100644 --- a/charts/library/common/templates/addons/vpn/gluetun/_addon.tpl +++ b/charts/library/common/templates/addons/vpn/gluetun/_addon.tpl @@ -2,9 +2,9 @@ Template to render gluetun addon. It will add the container to the list of additionalContainers. */}} */}} -{{- define "common.addon.gluetun" -}} +{{- define "bjw-s.common.addon.gluetun" -}} {{/* Append the gluetun container to the additionalContainers */}} - {{- $container := fromYaml (include "common.addon.gluetun.container" .) -}} + {{- $container := fromYaml (include "bjw-s.common.addon.gluetun.container" .) -}} {{- if $container -}} {{- $_ := set .Values.additionalContainers "addon-gluetun" $container -}} {{- end -}} diff --git a/charts/library/common/templates/addons/vpn/gluetun/_container.tpl b/charts/library/common/templates/addons/vpn/gluetun/_container.tpl index 7618ee56..1369ae2c 100644 --- a/charts/library/common/templates/addons/vpn/gluetun/_container.tpl +++ b/charts/library/common/templates/addons/vpn/gluetun/_container.tpl @@ -1,7 +1,7 @@ {{/* The gluetun sidecar container to be inserted. */}} -{{- define "common.addon.gluetun.container" -}} +{{- define "bjw-s.common.addon.gluetun.container" -}} name: gluetun image: "{{ .Values.addons.vpn.gluetun.image.repository }}:{{ .Values.addons.vpn.gluetun.image.tag }}" imagePullPolicy: {{ .Values.addons.vpn.gluetun.pullPolicy }} diff --git a/charts/library/common/templates/classes/_HorizontalPodAutoscaler.tpl b/charts/library/common/templates/classes/_HorizontalPodAutoscaler.tpl deleted file mode 100644 index 7be3480b..00000000 --- a/charts/library/common/templates/classes/_HorizontalPodAutoscaler.tpl +++ /dev/null @@ -1,37 +0,0 @@ -{{/* -This template serves as a blueprint for horizontal pod autoscaler objects that are created -using the common library. -*/}} -{{- define "common.classes.hpa" -}} - {{- if .Values.autoscaling.enabled -}} - {{- $hpaName := include "common.names.fullname" . -}} - {{- $targetName := include "common.names.fullname" . }} ---- -apiVersion: autoscaling/v2beta1 -kind: HorizontalPodAutoscaler -metadata: - name: {{ $hpaName }} - labels: {{- include "common.labels" $ | nindent 4 }} - annotations: {{- include "common.annotations" $ | nindent 4 }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: {{ include "common.names.controllerType" . }} - name: {{ .Values.autoscaling.target | default $targetName }} - minReplicas: {{ .Values.autoscaling.minReplicas | default 1 }} - maxReplicas: {{ .Values.autoscaling.maxReplicas | default 3 }} - metrics: - {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} - - type: Resource - resource: - name: cpu - targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} - {{- end }} - {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} - - type: Resource - resource: - name: memory - targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} - {{- end }} - {{- end -}} -{{- end -}} diff --git a/charts/library/common/templates/classes/_configmap.tpl b/charts/library/common/templates/classes/_configmap.tpl index 721a2a64..21262808 100644 --- a/charts/library/common/templates/classes/_configmap.tpl +++ b/charts/library/common/templates/classes/_configmap.tpl @@ -2,8 +2,8 @@ This template serves as a blueprint for all configMap objects that are created within the common library. */}} -{{- define "common.classes.configmap" -}} - {{- $fullName := include "common.names.fullname" . -}} +{{- define "bjw-s.common.class.configmap" -}} + {{- $fullName := include "bjw-s.common.lib.chart.names.fullname" . -}} {{- $configMapName := $fullName -}} {{- $values := .Values.configmap -}} @@ -21,14 +21,14 @@ apiVersion: v1 kind: ConfigMap metadata: name: {{ $configMapName }} - {{- with (merge ($values.labels | default dict) (include "common.labels" $ | fromYaml)) }} + {{- with (merge ($values.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml)) }} labels: {{- toYaml . | nindent 4 }} {{- end }} - {{- with (merge ($values.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} + {{- with (merge ($values.annotations | default dict) (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)) }} annotations: {{- toYaml . | nindent 4 }} {{- end }} data: {{- with $values.data }} {{- tpl (toYaml .) $ | nindent 2 }} {{- end }} -{{- end }} +{{- end -}} diff --git a/charts/library/common/templates/classes/_daemonset.tpl b/charts/library/common/templates/classes/_daemonset.tpl new file mode 100644 index 00000000..71827f48 --- /dev/null +++ b/charts/library/common/templates/classes/_daemonset.tpl @@ -0,0 +1,35 @@ +{{/* +This template serves as the blueprint for the DaemonSet objects that are created +within the common library. +*/}} +{{- define "bjw-s.common.class.daemonset" -}} +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: {{ include "bjw-s.common.lib.chart.names.fullname" . }} + {{- with include "bjw-s.common.lib.controller.metadata.labels" . }} + labels: {{- . | nindent 4 }} + {{- end }} + {{- with include "bjw-s.common.lib.controller.metadata.annotations" . }} + annotations: {{- . | nindent 4 }} + {{- end }} +spec: + revisionHistoryLimit: {{ .Values.controller.revisionHistoryLimit }} + selector: + matchLabels: + {{- include "bjw-s.common.lib.metadata.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with include ("bjw-s.common.lib.metadata.podAnnotations") . }} + annotations: + {{- . | nindent 8 }} + {{- end }} + labels: + {{- include "bjw-s.common.lib.metadata.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- include "bjw-s.common.lib.controller.pod" . | nindent 6 }} +{{- end }} diff --git a/charts/library/common/templates/_deployment.tpl b/charts/library/common/templates/classes/_deployment.tpl similarity index 55% rename from charts/library/common/templates/_deployment.tpl rename to charts/library/common/templates/classes/_deployment.tpl index 75c1f1d5..d9c86c03 100644 --- a/charts/library/common/templates/_deployment.tpl +++ b/charts/library/common/templates/classes/_deployment.tpl @@ -1,26 +1,26 @@ {{/* -This template serves as the blueprint for the Deployment objects that are created -within the common library. +This template serves as a blueprint for Deployment objects that are created +using the common library. */}} -{{- define "common.deployment" }} +{{- define "bjw-s.common.class.deployment" -}} + {{- $strategy := default "Recreate" .Values.controller.strategy -}} + {{- if and (ne $strategy "Recreate") (ne $strategy "RollingUpdate") -}} + {{- fail (printf "Not a valid strategy type for Deployment (%s)" $strategy) -}} + {{- end -}} --- apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "common.names.fullname" . }} - {{- with (merge (.Values.controller.labels | default dict) (include "common.labels" $ | fromYaml)) }} - labels: {{- toYaml . | nindent 4 }} + name: {{ include "bjw-s.common.lib.chart.names.fullname" . }} + {{- with include "bjw-s.common.lib.controller.metadata.labels" . }} + labels: {{- . | nindent 4 }} {{- end }} - {{- with (merge (.Values.controller.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} - annotations: {{- toYaml . | nindent 4 }} + {{- with include "bjw-s.common.lib.controller.metadata.annotations" . }} + annotations: {{- . | nindent 4 }} {{- end }} spec: revisionHistoryLimit: {{ .Values.controller.revisionHistoryLimit }} replicas: {{ .Values.controller.replicas }} - {{- $strategy := default "Recreate" .Values.controller.strategy }} - {{- if and (ne $strategy "Recreate") (ne $strategy "RollingUpdate") }} - {{- fail (printf "Not a valid strategy type for Deployment (%s)" $strategy) }} - {{- end }} strategy: type: {{ $strategy }} {{- with .Values.controller.rollingUpdate }} @@ -36,18 +36,18 @@ spec: {{- end }} selector: matchLabels: - {{- include "common.labels.selectorLabels" . | nindent 6 }} + {{- include "bjw-s.common.lib.metadata.selectorLabels" . | nindent 6 }} template: metadata: - {{- with include ("common.podAnnotations") . }} + {{- with include ("bjw-s.common.lib.metadata.podAnnotations") . }} annotations: {{- . | nindent 8 }} {{- end }} labels: - {{- include "common.labels.selectorLabels" . | nindent 8 }} + {{- include "bjw-s.common.lib.metadata.selectorLabels" . | nindent 8 }} {{- with .Values.podLabels }} {{- toYaml . | nindent 8 }} {{- end }} spec: - {{- include "common.controller.pod" . | nindent 6 }} -{{- end }} + {{- include "bjw-s.common.lib.controller.pod" . | nindent 6 }} +{{- end -}} diff --git a/charts/library/common/templates/classes/_ingress.tpl b/charts/library/common/templates/classes/_ingress.tpl index 3cb3c53b..3248525b 100644 --- a/charts/library/common/templates/classes/_ingress.tpl +++ b/charts/library/common/templates/classes/_ingress.tpl @@ -2,8 +2,8 @@ This template serves as a blueprint for all Ingress objects that are created within the common library. */}} -{{- define "common.classes.ingress" -}} - {{- $fullName := include "common.names.fullname" . -}} +{{- define "bjw-s.common.class.ingress" -}} + {{- $fullName := include "bjw-s.common.lib.chart.names.fullname" . -}} {{- $ingressName := $fullName -}} {{- $values := .Values.ingress -}} @@ -17,26 +17,25 @@ within the common library. {{- $ingressName = printf "%v-%v" $ingressName $values.nameOverride -}} {{- end -}} - {{- $primaryService := get .Values.service (include "common.service.primary" .) -}} + {{- $primaryService := get .Values.service (include "bjw-s.common.lib.service.primary" .) -}} {{- $defaultServiceName := $fullName -}} {{- if and (hasKey $primaryService "nameOverride") $primaryService.nameOverride -}} {{- $defaultServiceName = printf "%v-%v" $defaultServiceName $primaryService.nameOverride -}} {{- end -}} - {{- $defaultServicePort := get $primaryService.ports (include "common.classes.service.ports.primary" (dict "values" $primaryService)) -}} - {{- $isStable := include "common.capabilities.ingress.isStable" . }} + {{- $defaultServicePort := get $primaryService.ports (include "bjw-s.common.lib.service.primaryPort" (dict "values" $primaryService)) -}} --- -apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }} +apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: {{ $ingressName }} - {{- with (merge ($values.labels | default dict) (include "common.labels" $ | fromYaml)) }} + {{- with (merge ($values.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml)) }} labels: {{- toYaml . | nindent 4 }} {{- end }} - {{- with (merge ($values.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} + {{- with (merge ($values.annotations | default dict) (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)) }} annotations: {{- toYaml . | nindent 4 }} {{- end }} spec: - {{- if and $isStable $values.ingressClassName }} + {{- if $values.ingressClassName }} ingressClassName: {{ $values.ingressClassName }} {{- end }} {{- if $values.tls }} @@ -64,19 +63,12 @@ spec: {{- $port = default $port .service.port -}} {{- end }} - path: {{ tpl .path $ | quote }} - {{- if $isStable }} pathType: {{ default "Prefix" .pathType }} - {{- end }} backend: - {{- if $isStable }} service: name: {{ $service }} port: number: {{ $port }} - {{- else }} - serviceName: {{ $service }} - servicePort: {{ $port }} - {{- end }} {{- end }} {{- end }} {{- end }} diff --git a/charts/library/common/templates/classes/_pvc.tpl b/charts/library/common/templates/classes/_pvc.tpl index e04fbd77..4e30ba09 100644 --- a/charts/library/common/templates/classes/_pvc.tpl +++ b/charts/library/common/templates/classes/_pvc.tpl @@ -2,14 +2,14 @@ This template serves as a blueprint for all PersistentVolumeClaim objects that are created within the common library. */}} -{{- define "common.classes.pvc" -}} +{{- define "bjw-s.common.class.pvc" -}} {{- $values := .Values.persistence -}} {{- if hasKey . "ObjectValues" -}} {{- with .ObjectValues.persistence -}} {{- $values = . -}} {{- end -}} {{ end -}} -{{- $pvcName := include "common.names.fullname" . -}} +{{- $pvcName := include "bjw-s.common.lib.chart.names.fullname" . -}} {{- if and (hasKey $values "nameOverride") $values.nameOverride -}} {{- if not (eq $values.nameOverride "-") -}} {{- $pvcName = printf "%v-%v" $pvcName $values.nameOverride -}} @@ -20,14 +20,14 @@ kind: PersistentVolumeClaim apiVersion: v1 metadata: name: {{ $pvcName }} - {{- with (merge ($values.labels | default dict) (include "common.labels" $ | fromYaml)) }} + {{- with (merge ($values.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml)) }} labels: {{- toYaml . | nindent 4 }} {{- end }} annotations: {{- if $values.retain }} "helm.sh/resource-policy": keep {{- end }} - {{- with (merge ($values.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} + {{- with (merge ($values.annotations | default dict) (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)) }} {{- toYaml . | nindent 4 }} {{- end }} spec: diff --git a/charts/library/common/templates/classes/_secret.tpl b/charts/library/common/templates/classes/_secret.tpl new file mode 100644 index 00000000..ec4f5fcc --- /dev/null +++ b/charts/library/common/templates/classes/_secret.tpl @@ -0,0 +1,34 @@ +{{/* +This template serves as a blueprint for all Secret objects that are created +within the common library. +*/}} +{{- define "bjw-s.common.class.secret" -}} + {{- $fullName := include "bjw-s.common.lib.chart.names.fullname" . -}} + {{- $secretName := $fullName -}} + {{- $values := .Values.configmap -}} + + {{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.secret -}} + {{- $values = . -}} + {{- end -}} + {{ end -}} + + {{- if and (hasKey $values "nameOverride") $values.nameOverride -}} + {{- $secretName = printf "%v-%v" $secretName $values.nameOverride -}} + {{- end }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ $secretName }} + {{- with (merge ($values.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml)) }} + labels: {{- toYaml . | nindent 4 }} + {{- end }} + {{- with (merge ($values.annotations | default dict) (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)) }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} +stringData: +{{- with $values.stringData }} + {{- tpl (toYaml .) $ | nindent 2 }} +{{- end }} +{{- end -}} diff --git a/charts/library/common/templates/classes/_service.tpl b/charts/library/common/templates/classes/_service.tpl index d4386d3e..b8ca08e6 100644 --- a/charts/library/common/templates/classes/_service.tpl +++ b/charts/library/common/templates/classes/_service.tpl @@ -2,7 +2,7 @@ This template serves as a blueprint for all Service objects that are created within the common library. */}} -{{- define "common.classes.service" -}} +{{- define "bjw-s.common.class.service" -}} {{- $values := .Values.service -}} {{- if hasKey . "ObjectValues" -}} {{- with .ObjectValues.service -}} @@ -10,12 +10,12 @@ within the common library. {{- end -}} {{ end -}} -{{- $serviceName := include "common.names.fullname" . -}} +{{- $serviceName := include "bjw-s.common.lib.chart.names.fullname" . -}} {{- if and (hasKey $values "nameOverride") $values.nameOverride -}} {{- $serviceName = printf "%v-%v" $serviceName $values.nameOverride -}} {{ end -}} {{- $svcType := $values.type | default "" -}} -{{- $primaryPort := get $values.ports (include "common.classes.service.ports.primary" (dict "values" $values)) }} +{{- $primaryPort := get $values.ports (include "bjw-s.common.lib.service.primaryPort" (dict "values" $values)) }} --- apiVersion: v1 kind: Service @@ -23,14 +23,14 @@ metadata: name: {{ $serviceName }} labels: app.kubernetes.io/service: {{ $serviceName }} - {{- with (merge ($values.labels | default dict) (include "common.labels" $ | fromYaml)) }} + {{- with (merge ($values.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml)) }} {{- toYaml . | nindent 4 }} {{- end }} annotations: {{- if eq ( $primaryPort.protocol | default "" ) "HTTPS" }} traefik.ingress.kubernetes.io/service.serversscheme: https {{- end }} - {{- with (merge ($values.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} + {{- with (merge ($values.annotations | default dict) (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)) }} {{ toYaml . | nindent 4 }} {{- end }} spec: @@ -95,6 +95,7 @@ spec: {{ end }} {{- end }} {{- end }} - selector: - {{- include "common.labels.selectorLabels" . | nindent 4 }} + {{- with (merge ($values.extraSelectorLabels | default dict) (include "bjw-s.common.lib.metadata.selectorLabels" . | fromYaml)) }} + selector: {{- toYaml . | nindent 4 }} + {{- end }} {{- end }} diff --git a/charts/library/common/templates/classes/_serviceAccount.tpl b/charts/library/common/templates/classes/_serviceAccount.tpl new file mode 100644 index 00000000..1505b11b --- /dev/null +++ b/charts/library/common/templates/classes/_serviceAccount.tpl @@ -0,0 +1,15 @@ +{{/* +This template serves as a blueprint for ServiceAccount objects that are created +using the common library. +*/}} +{{- define "bjw-s.common.class.serviceAccount" -}} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "bjw-s.common.lib.chart.names.serviceAccountName" . }} + labels: {{- include "bjw-s.common.lib.metadata.allLabels" $ | nindent 4 }} + {{- with (merge (.Values.serviceAccount.annotations | default dict) (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)) }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} +{{- end -}} diff --git a/charts/library/common/templates/classes/_serviceMonitor.tpl b/charts/library/common/templates/classes/_serviceMonitor.tpl index f888b18d..0611000e 100644 --- a/charts/library/common/templates/classes/_serviceMonitor.tpl +++ b/charts/library/common/templates/classes/_serviceMonitor.tpl @@ -1,4 +1,4 @@ -{{- define "common.classes.serviceMonitor" -}} +{{- define "bjw-s.common.class.serviceMonitor" -}} {{- $values := dict -}} {{- if hasKey . "ObjectValues" -}} {{- with .ObjectValues.serviceMonitor -}} @@ -6,7 +6,7 @@ {{- end -}} {{ end -}} -{{- $serviceMonitorName := include "common.names.fullname" . -}} +{{- $serviceMonitorName := include "bjw-s.common.lib.chart.names.fullname" . -}} {{- if and (hasKey $values "nameOverride") $values.nameOverride -}} {{- $serviceMonitorName = printf "%v-%v" $serviceMonitorName $values.nameOverride -}} {{ end -}} @@ -15,16 +15,20 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ $serviceMonitorName }} - {{- with (merge ($values.labels | default dict) (include "common.labels" $ | fromYaml)) }} + {{- with (merge ($values.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml)) }} labels: {{- toYaml . | nindent 4 }} {{- end }} - {{- with (merge ($values.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} + {{- with (merge ($values.annotations | default dict) (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)) }} annotations: {{- toYaml . | nindent 4 }} {{- end }} spec: selector: + {{- if $values.selector -}} + {{- tpl ($values.selector | toYaml) $ | nindent 4}} + {{- else }} matchLabels: - app.kubernetes.io/service: {{ $values.serviceName }} - {{- include "common.labels.selectorLabels" . | nindent 6 }} + app.kubernetes.io/service: {{ tpl $values.serviceName $ }} + {{- include "bjw-s.common.lib.metadata.selectorLabels" . | nindent 6 }} + {{- end }} endpoints: {{- toYaml (required (printf "endpoints are required for serviceMonitor %v" $serviceMonitorName) $values.endpoints) | nindent 4 }} {{- end }} diff --git a/charts/library/common/templates/classes/_statefulset.tpl b/charts/library/common/templates/classes/_statefulset.tpl new file mode 100644 index 00000000..a9ede417 --- /dev/null +++ b/charts/library/common/templates/classes/_statefulset.tpl @@ -0,0 +1,68 @@ +{{/* +This template serves as the blueprint for the StatefulSet objects that are created +within the common library. +*/}} +{{- define "bjw-s.common.class.statefulset" -}} + {{- $strategy := default "RollingUpdate" .Values.controller.strategy -}} + {{- if and (ne $strategy "OnDelete") (ne $strategy "RollingUpdate") -}} + {{- fail (printf "Not a valid strategy type for StatefulSet (%s)" $strategy) -}} + {{- end -}} +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "bjw-s.common.lib.chart.names.fullname" . }} + {{- with include "bjw-s.common.lib.controller.metadata.labels" . }} + labels: {{- . | nindent 4 }} + {{- end }} + {{- with include "bjw-s.common.lib.controller.metadata.annotations" . }} + annotations: {{- . | nindent 4 }} + {{- end }} +spec: + revisionHistoryLimit: {{ .Values.controller.revisionHistoryLimit }} + replicas: {{ .Values.controller.replicas }} + podManagementPolicy: {{ default "OrderedReady" .Values.controller.podManagementPolicy }} + updateStrategy: + type: {{ $strategy }} + {{- if and (eq $strategy "RollingUpdate") .Values.controller.rollingUpdate.partition }} + rollingUpdate: + partition: {{ .Values.controller.rollingUpdate.partition }} + {{- end }} + selector: + matchLabels: + {{- include "bjw-s.common.lib.metadata.selectorLabels" . | nindent 6 }} + serviceName: {{ include "bjw-s.common.lib.chart.names.fullname" . }} + template: + metadata: + {{- with include ("bjw-s.common.lib.metadata.podAnnotations") . }} + annotations: + {{- . | nindent 8 }} + {{- end }} + labels: + {{- include "bjw-s.common.lib.metadata.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- include "bjw-s.common.lib.controller.pod" . | nindent 6 }} + volumeClaimTemplates: + {{- range $index, $volumeClaimTemplate := .Values.volumeClaimTemplates }} + - metadata: + name: {{ $volumeClaimTemplate.name }} + {{- with ($volumeClaimTemplate.labels | default dict) }} + labels: {{- toYaml . | nindent 10 }} + {{- end }} + {{- with ($volumeClaimTemplate.annotations | default dict) }} + annotations: {{- toYaml . | nindent 10 }} + {{- end }} + spec: + accessModes: + - {{ required (printf "accessMode is required for volumeClaimTemplate %v" $volumeClaimTemplate.name) $volumeClaimTemplate.accessMode | quote }} + resources: + requests: + storage: {{ required (printf "size is required for PVC %v" $volumeClaimTemplate.name) $volumeClaimTemplate.size | quote }} + {{- if $volumeClaimTemplate.storageClass }} + storageClassName: {{ if (eq "-" $volumeClaimTemplate.storageClass) }}""{{- else }}{{ $volumeClaimTemplate.storageClass | quote }}{{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/library/common/templates/lib/chart/_capabilities.tpl b/charts/library/common/templates/lib/chart/_capabilities.tpl deleted file mode 100644 index 96de3c10..00000000 --- a/charts/library/common/templates/lib/chart/_capabilities.tpl +++ /dev/null @@ -1,19 +0,0 @@ -{{/* Allow KubeVersion to be overridden. */}} -{{- define "common.capabilities.ingress.kubeVersion" -}} - {{- default .Capabilities.KubeVersion.Version .Values.kubeVersionOverride -}} -{{- end -}} - -{{/* Return the appropriate apiVersion for Ingress objects */}} -{{- define "common.capabilities.ingress.apiVersion" -}} - {{- print "networking.k8s.io/v1" -}} - {{- if semverCompare "<1.19" (include "common.capabilities.ingress.kubeVersion" .) -}} - {{- print "beta1" -}} - {{- end -}} -{{- end -}} - -{{/* Check Ingress stability */}} -{{- define "common.capabilities.ingress.isStable" -}} - {{- if eq (include "common.capabilities.ingress.apiVersion" .) "networking.k8s.io/v1" -}} - {{- true -}} - {{- end -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/chart/_labels.tpl b/charts/library/common/templates/lib/chart/_labels.tpl deleted file mode 100644 index 73b5068f..00000000 --- a/charts/library/common/templates/lib/chart/_labels.tpl +++ /dev/null @@ -1,22 +0,0 @@ -{{/* Common labels shared across objects */}} -{{- define "common.labels" -}} -helm.sh/chart: {{ include "common.names.chart" . }} -{{ include "common.labels.selectorLabels" . }} - {{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} - {{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} - {{- with .Values.global.labels }} - {{- range $k, $v := . }} - {{- $name := $k }} - {{- $value := tpl $v $ }} -{{ $name }}: {{ quote $value }} - {{- end }} - {{- end }} -{{- end -}} - -{{/* Selector labels shared across objects */}} -{{- define "common.labels.selectorLabels" -}} -app.kubernetes.io/name: {{ include "common.names.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} diff --git a/charts/library/common/templates/lib/chart/_names.tpl b/charts/library/common/templates/lib/chart/_names.tpl index a32d572f..38451ce8 100644 --- a/charts/library/common/templates/lib/chart/_names.tpl +++ b/charts/library/common/templates/lib/chart/_names.tpl @@ -1,5 +1,5 @@ {{/* Expand the name of the chart */}} -{{- define "common.names.name" -}} +{{- define "bjw-s.common.lib.chart.names.name" -}} {{- $globalNameOverride := "" -}} {{- if hasKey .Values "global" -}} {{- $globalNameOverride = (default $globalNameOverride .Values.global.nameOverride) -}} @@ -12,8 +12,8 @@ Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). If release name contains chart name it will be used as a full name. */}} -{{- define "common.names.fullname" -}} - {{- $name := include "common.names.name" . -}} +{{- define "bjw-s.common.lib.chart.names.fullname" -}} + {{- $name := include "bjw-s.common.lib.chart.names.name" . -}} {{- $globalFullNameOverride := "" -}} {{- if hasKey .Values "global" -}} {{- $globalFullNameOverride = (default $globalFullNameOverride .Values.global.fullnameOverride) -}} @@ -31,28 +31,15 @@ If release name contains chart name it will be used as a full name. {{- end -}} {{/* Create chart name and version as used by the chart label */}} -{{- define "common.names.chart" -}} +{{- define "bjw-s.common.lib.chart.names.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} {{- end -}} {{/* Create the name of the ServiceAccount to use */}} -{{- define "common.names.serviceAccountName" -}} +{{- define "bjw-s.common.lib.chart.names.serviceAccountName" -}} {{- if .Values.serviceAccount.create -}} - {{- default (include "common.names.fullname" .) .Values.serviceAccount.name -}} + {{- default (include "bjw-s.common.lib.chart.names.fullname" .) .Values.serviceAccount.name -}} {{- else -}} {{- default "default" .Values.serviceAccount.name -}} {{- end -}} {{- end -}} - -{{/* Return the properly cased version of the controller type */}} -{{- define "common.names.controllerType" -}} - {{- if eq .Values.controller.type "deployment" -}} - {{- print "Deployment" -}} - {{- else if eq .Values.controller.type "daemonset" -}} - {{- print "DaemonSet" -}} - {{- else if eq .Values.controller.type "statefulset" -}} - {{- print "StatefulSet" -}} - {{- else -}} - {{- fail (printf "Not a valid controller.type (%s)" .Values.controller.type) -}} - {{- end -}} -{{- end -}} diff --git a/charts/library/common/templates/_notes.tpl b/charts/library/common/templates/lib/chart/_notes.tpl similarity index 66% rename from charts/library/common/templates/_notes.tpl rename to charts/library/common/templates/lib/chart/_notes.tpl index e5f85b09..5bfa54d6 100644 --- a/charts/library/common/templates/_notes.tpl +++ b/charts/library/common/templates/lib/chart/_notes.tpl @@ -1,13 +1,13 @@ {{/* Default NOTES.txt content. */}} -{{- define "common.notes.defaultNotes" -}} +{{- define "bjw-s.common.lib.chart.notes" -}} -{{- $primaryIngress := get .Values.ingress (include "common.ingress.primary" .) -}} -{{- $primaryService := get .Values.service (include "common.service.primary" .) -}} +{{- $primaryIngress := get .Values.ingress (include "bjw-s.common.lib.ingress.primary" .) -}} +{{- $primaryService := get .Values.service (include "bjw-s.common.lib.service.primary" .) -}} {{- $primaryPort := "" -}} {{- if $primaryService -}} - {{- $primaryPort = get $primaryService.ports (include "common.classes.service.ports.primary" (dict "serviceName" (include "common.service.primary" .) "values" $primaryService)) -}} + {{- $primaryPort = get $primaryService.ports (include "bjw-s.common.lib.service.primaryPort" (dict "serviceName" (include "bjw-s.common.lib.service.primary" .) "values" $primaryService)) -}} {{- end -}} {{- $prefix := "http" -}} @@ -22,7 +22,7 @@ Default NOTES.txt content. {{- if $primaryIngress }} 1. Access the application by visiting one of these URL's: {{ range $primaryIngress.hosts }} - {{- $protocol := "http" -}} + {{- $prefix = "http" -}} {{ if $primaryIngress.tls -}} {{- $prefix = "https" -}} {{ end -}} @@ -34,21 +34,21 @@ Default NOTES.txt content. {{ if (first .paths).pathTpl -}} {{- $path = tpl (first .paths).pathTpl $ -}} {{ end }} - - {{ $protocol }}://{{- $host }}{{- $path }} + - {{ $prefix }}://{{- $host }}{{- $path }} {{- end }} {{- else if and $primaryService $primaryPort }} 1. Get the application URL by running these commands: {{- if contains "NodePort" $primaryService.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "common.names.fullname" . }}) + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "bjw-s.common.lib.chart.names.fullname" . }}) export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") echo {{ $prefix }}://$NODE_IP:$NODE_PORT {{- else if contains "LoadBalancer" $primaryService.type }} NOTE: It may take a few minutes for the LoadBalancer IP to be available. - You can watch the status of by running 'kubectl get svc -w {{ include "common.names.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "common.names.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + You can watch the status of by running 'kubectl get svc -w {{ include "bjw-s.common.lib.chart.names.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "bjw-s.common.lib.chart.names.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') echo {{ $prefix }}://$SERVICE_IP:{{ $primaryPort.port }} {{- else if contains "ClusterIP" $primaryService.type }} - export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "common.names.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "bjw-s.common.lib.chart.names.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") echo "Visit {{ $prefix }}://127.0.0.1:8080 to use your application" kubectl port-forward $POD_NAME 8080:{{ $primaryPort.port }} {{- end }} diff --git a/charts/library/common/templates/lib/controller/_env_vars.tpl b/charts/library/common/templates/lib/container/_env_vars.tpl similarity index 94% rename from charts/library/common/templates/lib/controller/_env_vars.tpl rename to charts/library/common/templates/lib/container/_env_vars.tpl index ab4ed68e..f4b4cf2c 100644 --- a/charts/library/common/templates/lib/controller/_env_vars.tpl +++ b/charts/library/common/templates/lib/container/_env_vars.tpl @@ -1,10 +1,10 @@ {{/* Environment variables used by containers. */}} -{{- define "common.controller.env_vars" -}} +{{- define "bjw-s.common.lib.container.envVars" -}} {{- $values := .Values.env -}} {{- if hasKey . "ObjectValues" -}} - {{- with .ObjectValues.env -}} + {{- with .ObjectValues.envVars -}} {{- $values = . -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/controller/_ports.tpl b/charts/library/common/templates/lib/container/_ports.tpl similarity index 95% rename from charts/library/common/templates/lib/controller/_ports.tpl rename to charts/library/common/templates/lib/container/_ports.tpl index 5394690c..2b1404ef 100644 --- a/charts/library/common/templates/lib/controller/_ports.tpl +++ b/charts/library/common/templates/lib/container/_ports.tpl @@ -1,7 +1,7 @@ {{/* Ports included by the controller. */}} -{{- define "common.controller.ports" -}} +{{- define "bjw-s.common.lib.container.ports" -}} {{- $ports := list -}} {{- range .Values.service -}} {{- if .enabled -}} diff --git a/charts/library/common/templates/lib/container/_probes.tpl b/charts/library/common/templates/lib/container/_probes.tpl new file mode 100644 index 00000000..38fe7554 --- /dev/null +++ b/charts/library/common/templates/lib/container/_probes.tpl @@ -0,0 +1,47 @@ +{{/* +Probes selection logic. +*/}} +{{- define "bjw-s.common.lib.container.probes" -}} +{{- $primaryService := get .Values.service (include "bjw-s.common.lib.service.primary" .) -}} +{{- $primaryPort := "" -}} +{{- if $primaryService -}} + {{- $primaryPort = get $primaryService.ports (include "bjw-s.common.lib.service.primaryPort" (dict "serviceName" (include "bjw-s.common.lib.service.primary" .) "values" $primaryService)) -}} +{{- end -}} + +{{- range $probeName, $probe := .Values.probes }} + {{- if $probe.enabled -}} + {{- "" | nindent 0 }} + {{- $probeName }}Probe: + {{- if $probe.custom -}} + {{- $probe.spec | toYaml | nindent 2 }} + {{- else }} + {{- if and $primaryService $primaryPort -}} + {{- $probeType := "" -}} + {{- if eq $probe.type "AUTO" -}} + {{- $probeType = $primaryPort.protocol -}} + {{- else -}} + {{- $probeType = $probe.type | default "TCP" -}} + {{- end }} + {{- if or ( eq $probeType "HTTPS" ) ( eq $probeType "HTTP" ) -}} + httpGet: + path: {{ $probe.path }} + scheme: {{ $probeType }} + {{- else }} + tcpSocket: + {{- end }} + {{- if $probe.port }} + port: {{ ( tpl ( $probe.port | toString ) $ ) }} + {{- else if $primaryPort.targetPort }} + port: {{ $primaryPort.targetPort }} + {{- else }} + port: {{ $primaryPort.port }} + {{- end }} + initialDelaySeconds: {{ $probe.spec.initialDelaySeconds }} + failureThreshold: {{ $probe.spec.failureThreshold }} + timeoutSeconds: {{ $probe.spec.timeoutSeconds }} + periodSeconds: {{ $probe.spec.periodSeconds }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} +{{- end }} diff --git a/charts/library/common/templates/lib/controller/_volumemounts.tpl b/charts/library/common/templates/lib/container/_volumemounts.tpl similarity index 97% rename from charts/library/common/templates/lib/controller/_volumemounts.tpl rename to charts/library/common/templates/lib/container/_volumemounts.tpl index 8b05c9ec..63d45229 100644 --- a/charts/library/common/templates/lib/controller/_volumemounts.tpl +++ b/charts/library/common/templates/lib/container/_volumemounts.tpl @@ -1,5 +1,5 @@ {{/* Volumes included by the controller */}} -{{- define "common.controller.volumeMounts" -}} +{{- define "bjw-s.common.lib.container.volumeMounts" -}} {{- range $persistenceIndex, $persistenceItem := .Values.persistence }} {{- if $persistenceItem.enabled -}} {{- if kindIs "slice" $persistenceItem.subPath -}} diff --git a/charts/library/common/templates/lib/controller/_container.tpl b/charts/library/common/templates/lib/controller/_mainContainer.tpl similarity index 72% rename from charts/library/common/templates/lib/controller/_container.tpl rename to charts/library/common/templates/lib/controller/_mainContainer.tpl index 9c7ba81d..40fc8be0 100644 --- a/charts/library/common/templates/lib/controller/_container.tpl +++ b/charts/library/common/templates/lib/controller/_mainContainer.tpl @@ -1,6 +1,6 @@ {{- /* The main container included in the controller */ -}} -{{- define "common.controller.mainContainer" -}} -- name: {{ include "common.names.fullname" . }} +{{- define "bjw-s.common.lib.controller.mainContainer" -}} +- name: {{ include "bjw-s.common.lib.chart.names.fullname" . }} image: {{ printf "%s:%s" .Values.image.repository (default .Chart.AppVersion .Values.image.tag) | quote }} imagePullPolicy: {{ .Values.image.pullPolicy }} {{- with .Values.command }} @@ -36,7 +36,7 @@ {{- with .Values.env }} env: - {{- get (fromYaml (include "common.controller.env_vars" $)) "env" | toYaml | nindent 4 -}} + {{- get (fromYaml (include "bjw-s.common.lib.container.envVars" $)) "env" | toYaml | nindent 4 -}} {{- end }} {{- if or .Values.envFrom .Values.secret }} envFrom: @@ -45,16 +45,16 @@ {{- end }} {{- if .Values.secret }} - secretRef: - name: {{ include "common.names.fullname" . }} + name: {{ include "bjw-s.common.lib.chart.names.fullname" . }} {{- end }} {{- end }} ports: - {{- include "common.controller.ports" . | trim | nindent 4 }} - {{- with (include "common.controller.volumeMounts" . | trim) }} + {{- include "bjw-s.common.lib.container.ports" . | trim | nindent 4 }} + {{- with (include "bjw-s.common.lib.container.volumeMounts" . | trim) }} volumeMounts: {{- nindent 4 . }} {{- end }} - {{- include "common.controller.probes" . | trim | nindent 2 }} + {{- include "bjw-s.common.lib.container.probes" . | trim | nindent 2 }} {{- with .Values.resources }} resources: {{- toYaml . | nindent 4 }} diff --git a/charts/library/common/templates/lib/controller/_metadata.tpl b/charts/library/common/templates/lib/controller/_metadata.tpl new file mode 100644 index 00000000..0d759d6d --- /dev/null +++ b/charts/library/common/templates/lib/controller/_metadata.tpl @@ -0,0 +1,25 @@ +{{- define "bjw-s.common.lib.controller.metadata.labels" -}} + {{- + $labels := ( + merge + (.Values.controller.labels | default dict) + (include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml) + ) + -}} + {{- with $labels -}} + {{- toYaml . -}} + {{- end -}} +{{- end -}} + +{{- define "bjw-s.common.lib.controller.metadata.annotations" -}} + {{- + $annotations := ( + merge + (.Values.controller.annotations | default dict) + (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml) + ) + -}} + {{- with $annotations -}} + {{- toYaml . -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/controller/_pod.tpl b/charts/library/common/templates/lib/controller/_pod.tpl index a6e21998..f822ac6c 100644 --- a/charts/library/common/templates/lib/controller/_pod.tpl +++ b/charts/library/common/templates/lib/controller/_pod.tpl @@ -1,12 +1,12 @@ {{- /* The pod definition included in the controller. */ -}} -{{- define "common.controller.pod" -}} +{{- define "bjw-s.common.lib.controller.pod" -}} {{- with .Values.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 2 }} {{- end }} -serviceAccountName: {{ include "common.names.serviceAccountName" . }} +serviceAccountName: {{ include "bjw-s.common.lib.chart.names.serviceAccountName" . }} automountServiceAccountToken: {{ .Values.automountServiceAccountToken }} {{- with .Values.podSecurityContext }} securityContext: @@ -51,9 +51,9 @@ initContainers: {{- $_ := set $container "name" $key }} {{- end }} {{- if $container.env -}} - {{- $_ := set $ "ObjectValues" (dict "env" $container.env) -}} - {{- $newEnv := fromYaml (include "common.controller.env_vars" $) -}} - {{- $_ := unset $.ObjectValues "env" -}} + {{- $_ := set $ "ObjectValues" (dict "envVars" $container.env) -}} + {{- $newEnv := fromYaml (include "bjw-s.common.lib.container.envVars" $) -}} + {{- $_ := unset $.ObjectValues "envVars" -}} {{- $_ := set $container "env" $newEnv.env }} {{- end }} {{- $initContainers = append $initContainers $container }} @@ -61,7 +61,7 @@ initContainers: {{- tpl (toYaml $initContainers) $ | nindent 2 }} {{- end }} containers: - {{- include "common.controller.mainContainer" . | nindent 2 }} + {{- include "bjw-s.common.lib.controller.mainContainer" . | nindent 2 }} {{- with .Values.additionalContainers }} {{- $additionalContainers := list }} {{- range $name, $container := . }} @@ -69,16 +69,16 @@ containers: {{- $_ := set $container "name" $name }} {{- end }} {{- if $container.env -}} - {{- $_ := set $ "ObjectValues" (dict "env" $container.env) -}} - {{- $newEnv := fromYaml (include "common.controller.env_vars" $) -}} + {{- $_ := set $ "ObjectValues" (dict "envVars" $container.env) -}} + {{- $newEnv := fromYaml (include "bjw-s.common.lib.container.envVars" $) -}} {{- $_ := set $container "env" $newEnv.env }} - {{- $_ := unset $.ObjectValues "env" -}} + {{- $_ := unset $.ObjectValues "envVars" -}} {{- end }} {{- $additionalContainers = append $additionalContainers $container }} {{- end }} {{- tpl (toYaml $additionalContainers) $ | nindent 2 }} {{- end }} - {{- with (include "common.controller.volumes" . | trim) }} + {{- with (include "bjw-s.common.lib.controller.volumes" . | trim) }} volumes: {{- nindent 2 . }} {{- end }} diff --git a/charts/library/common/templates/lib/controller/_probes.tpl b/charts/library/common/templates/lib/controller/_probes.tpl deleted file mode 100644 index 3b64a5e3..00000000 --- a/charts/library/common/templates/lib/controller/_probes.tpl +++ /dev/null @@ -1,33 +0,0 @@ -{{/* -Probes selection logic. -*/}} -{{- define "common.controller.probes" -}} -{{- $primaryService := get .Values.service (include "common.service.primary" .) -}} -{{- $primaryPort := "" -}} -{{- if $primaryService -}} - {{- $primaryPort = get $primaryService.ports (include "common.classes.service.ports.primary" (dict "serviceName" (include "common.service.primary" .) "values" $primaryService)) -}} -{{- end -}} - -{{- range $probeName, $probe := .Values.probes }} - {{- if $probe.enabled -}} - {{- "" | nindent 0 }} - {{- $probeName }}Probe: - {{- if $probe.custom -}} - {{- $probe.spec | toYaml | nindent 2 }} - {{- else }} - {{- if and $primaryService $primaryPort -}} - {{- "tcpSocket:" | nindent 2 }} - {{- if $primaryPort.targetPort }} - {{- printf "port: %v" $primaryPort.targetPort | nindent 4 }} - {{- else}} - {{- printf "port: %v" $primaryPort.port | nindent 4 }} - {{- end }} - {{- printf "initialDelaySeconds: %v" $probe.spec.initialDelaySeconds | nindent 2 }} - {{- printf "failureThreshold: %v" $probe.spec.failureThreshold | nindent 2 }} - {{- printf "timeoutSeconds: %v" $probe.spec.timeoutSeconds | nindent 2 }} - {{- printf "periodSeconds: %v" $probe.spec.periodSeconds | nindent 2 }} - {{- end }} - {{- end }} - {{- end }} -{{- end }} -{{- end }} diff --git a/charts/library/common/templates/lib/controller/_volumes.tpl b/charts/library/common/templates/lib/controller/_volumes.tpl index 1a077ae3..d9bb858b 100644 --- a/charts/library/common/templates/lib/controller/_volumes.tpl +++ b/charts/library/common/templates/lib/controller/_volumes.tpl @@ -1,12 +1,12 @@ {{/* Volumes included by the controller. */}} -{{- define "common.controller.volumes" -}} +{{- define "bjw-s.common.lib.controller.volumes" -}} {{- range $index, $persistence := .Values.persistence }} {{- if $persistence.enabled }} - name: {{ $index }} {{- if eq (default "pvc" $persistence.type) "pvc" }} - {{- $pvcName := (include "common.names.fullname" $) -}} + {{- $pvcName := (include "bjw-s.common.lib.chart.names.fullname" $) -}} {{- if $persistence.existingClaim }} {{- /* Always prefer an existingClaim if that is set */}} {{- $pvcName = $persistence.existingClaim -}} @@ -14,10 +14,10 @@ Volumes included by the controller. {{- /* Otherwise refer to the PVC name */}} {{- if $persistence.nameOverride -}} {{- if not (eq $persistence.nameOverride "-") -}} - {{- $pvcName = (printf "%s-%s" (include "common.names.fullname" $) $persistence.nameOverride) -}} + {{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $) $persistence.nameOverride) -}} {{- end -}} {{- else -}} - {{- $pvcName = (printf "%s-%s" (include "common.names.fullname" $) $index) -}} + {{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $) $index) -}} {{- end -}} {{- end }} persistentVolumeClaim: diff --git a/charts/library/common/templates/lib/ingress/_primary.tpl b/charts/library/common/templates/lib/ingress/_primary.tpl new file mode 100644 index 00000000..9f58d38b --- /dev/null +++ b/charts/library/common/templates/lib/ingress/_primary.tpl @@ -0,0 +1,21 @@ +{{/* Return the name of the primary ingress object */}} +{{- define "bjw-s.common.lib.ingress.primary" -}} + {{- $enabledIngresses := dict -}} + {{- range $name, $ingress := .Values.ingress -}} + {{- if $ingress.enabled -}} + {{- $_ := set $enabledIngresses $name . -}} + {{- end -}} + {{- end -}} + + {{- $result := "" -}} + {{- range $name, $ingress := $enabledIngresses -}} + {{- if and (hasKey $ingress "primary") $ingress.primary -}} + {{- $result = $name -}} + {{- end -}} + {{- end -}} + + {{- if not $result -}} + {{- $result = keys $enabledIngresses | first -}} + {{- end -}} + {{- $result -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/metadata/_allLabels.tpl b/charts/library/common/templates/lib/metadata/_allLabels.tpl new file mode 100644 index 00000000..330857b0 --- /dev/null +++ b/charts/library/common/templates/lib/metadata/_allLabels.tpl @@ -0,0 +1,10 @@ +{{/* Common labels shared across objects */}} +{{- define "bjw-s.common.lib.metadata.allLabels" -}} +helm.sh/chart: {{ include "bjw-s.common.lib.chart.names.chart" . }} +{{ include "bjw-s.common.lib.metadata.selectorLabels" . }} + {{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} + {{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{ include "bjw-s.common.lib.metadata.globalLabels" . }} +{{- end -}} diff --git a/charts/library/common/templates/lib/metadata/_globalAnnotations.tpl b/charts/library/common/templates/lib/metadata/_globalAnnotations.tpl new file mode 100644 index 00000000..c7850c59 --- /dev/null +++ b/charts/library/common/templates/lib/metadata/_globalAnnotations.tpl @@ -0,0 +1,10 @@ +{{/* Common annotations shared across objects */}} +{{- define "bjw-s.common.lib.metadata.globalAnnotations" -}} + {{- with .Values.global.annotations }} + {{- range $k, $v := . }} + {{- $name := $k }} + {{- $value := tpl $v $ }} +{{ $name }}: {{ quote $value }} + {{- end }} + {{- end }} +{{- end -}} diff --git a/charts/library/common/templates/lib/metadata/_globalLabels.tpl b/charts/library/common/templates/lib/metadata/_globalLabels.tpl new file mode 100644 index 00000000..6b4c3770 --- /dev/null +++ b/charts/library/common/templates/lib/metadata/_globalLabels.tpl @@ -0,0 +1,9 @@ +{{- define "bjw-s.common.lib.metadata.globalLabels" -}} + {{- with .Values.global.labels }} + {{- range $k, $v := . }} + {{- $name := $k }} + {{- $value := tpl $v $ }} +{{ $name }}: {{ quote $value }} + {{- end }} + {{- end }} +{{- end -}} diff --git a/charts/library/common/templates/lib/chart/_annotations.tpl b/charts/library/common/templates/lib/metadata/_podAnnotations.tpl similarity index 57% rename from charts/library/common/templates/lib/chart/_annotations.tpl rename to charts/library/common/templates/lib/metadata/_podAnnotations.tpl index d3b661d8..0a26d7f6 100644 --- a/charts/library/common/templates/lib/chart/_annotations.tpl +++ b/charts/library/common/templates/lib/metadata/_podAnnotations.tpl @@ -1,22 +1,11 @@ -{{/* Common annotations shared across objects */}} -{{- define "common.annotations" -}} - {{- with .Values.global.annotations }} - {{- range $k, $v := . }} - {{- $name := $k }} - {{- $value := tpl $v $ }} -{{ $name }}: {{ quote $value }} - {{- end }} - {{- end }} -{{- end -}} - {{/* Determine the Pod annotations used in the controller */}} -{{- define "common.podAnnotations" -}} +{{- define "bjw-s.common.lib.metadata.podAnnotations" -}} {{- if .Values.podAnnotations -}} {{- tpl (toYaml .Values.podAnnotations) . | nindent 0 -}} {{- end -}} {{- $configMapsFound := dict -}} - {{- range $name, $configmap := .Values.configmap -}} + {{- range $name, $configmap := .Values.configMaps -}} {{- if $configmap.enabled -}} {{- $_ := set $configMapsFound $name (toYaml $configmap.data | sha256sum) -}} {{- end -}} diff --git a/charts/library/common/templates/lib/metadata/_selectorLabels.tpl b/charts/library/common/templates/lib/metadata/_selectorLabels.tpl new file mode 100644 index 00000000..5174d999 --- /dev/null +++ b/charts/library/common/templates/lib/metadata/_selectorLabels.tpl @@ -0,0 +1,5 @@ +{{/* Selector labels shared across objects */}} +{{- define "bjw-s.common.lib.metadata.selectorLabels" -}} +app.kubernetes.io/name: {{ include "bjw-s.common.lib.chart.names.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} diff --git a/charts/library/common/templates/lib/service/_primary.tpl b/charts/library/common/templates/lib/service/_primary.tpl new file mode 100644 index 00000000..e6bdd4d9 --- /dev/null +++ b/charts/library/common/templates/lib/service/_primary.tpl @@ -0,0 +1,23 @@ +{{/* +Return the primary service object +*/}} +{{- define "bjw-s.common.lib.service.primary" -}} + {{- $enabledServices := dict -}} + {{- range $name, $service := .Values.service -}} + {{- if $service.enabled -}} + {{- $_ := set $enabledServices $name . -}} + {{- end -}} + {{- end -}} + + {{- $result := "" -}} + {{- range $name, $service := $enabledServices -}} + {{- if and (hasKey $service "primary") $service.primary -}} + {{- $result = $name -}} + {{- end -}} + {{- end -}} + + {{- if not $result -}} + {{- $result = keys $enabledServices | first -}} + {{- end -}} + {{- $result -}} +{{- end -}} diff --git a/charts/library/common/templates/classes/_service_ports.tpl b/charts/library/common/templates/lib/service/_primary_port.tpl similarity index 92% rename from charts/library/common/templates/classes/_service_ports.tpl rename to charts/library/common/templates/lib/service/_primary_port.tpl index 32cae4c8..04660581 100644 --- a/charts/library/common/templates/classes/_service_ports.tpl +++ b/charts/library/common/templates/lib/service/_primary_port.tpl @@ -1,7 +1,7 @@ {{/* Return the primary port for a given Service object. */}} -{{- define "common.classes.service.ports.primary" -}} +{{- define "bjw-s.common.lib.service.primaryPort" -}} {{- $enabledPorts := dict -}} {{- range $name, $port := .values.ports -}} {{- if $port.enabled -}} diff --git a/charts/library/common/templates/loader/_all.tpl b/charts/library/common/templates/loader/_all.tpl new file mode 100644 index 00000000..f0b70078 --- /dev/null +++ b/charts/library/common/templates/loader/_all.tpl @@ -0,0 +1,10 @@ +{{/* +Main entrypoint for the common library chart. It will render all underlying templates based on the provided values. +*/}} +{{- define "bjw-s.common.loader.all" -}} + {{- /* Generate chart and dependency values */ -}} + {{- include "bjw-s.common.loader.init" . -}} + + {{- /* Generate remaining objects */ -}} + {{- include "bjw-s.common.loader.generate" . -}} +{{- end -}} diff --git a/charts/library/common/templates/loader/_generate.tpl b/charts/library/common/templates/loader/_generate.tpl new file mode 100644 index 00000000..2afbee4d --- /dev/null +++ b/charts/library/common/templates/loader/_generate.tpl @@ -0,0 +1,34 @@ +{{/* +Secondary entrypoint and primary loader for the common chart +*/}} +{{- define "bjw-s.common.loader.generate" -}} + {{- /* Enable code-server add-on if required */ -}} + {{- if .Values.addons.codeserver.enabled -}} + {{- include "bjw-s.common.addon.codeserver" . | nindent 0 -}} + {{- end -}} + + {{- /* Enable VPN add-on if required */ -}} + {{- if .Values.addons.vpn.enabled -}} + {{- include "bjw-s.common.addon.vpn" . | nindent 0 -}} + {{- end -}} + + {{- /* Enable promtail add-on if required */ -}} + {{- if .Values.addons.promtail.enabled -}} + {{- include "bjw-s.common.addon.promtail" . | nindent 0 -}} + {{- end -}} + + {{- /* Enable netshoot add-on if required */ -}} + {{- if .Values.addons.netshoot.enabled -}} + {{- include "bjw-s.common.addon.netshoot" . | nindent 0 -}} + {{- end -}} + + {{- /* Build the templates */ -}} + {{- include "bjw-s.common.render.configmaps" . | nindent 0 -}} + {{- include "bjw-s.common.render.secrets" . | nindent 0 -}} + {{- include "bjw-s.common.render.pvcs" . | nindent 0 -}} + {{- include "bjw-s.common.render.serviceAccount" . | nindent 0 -}} + {{- include "bjw-s.common.render.controller" . | nindent 0 -}} + {{- include "bjw-s.common.render.services" . | nindent 0 -}} + {{- include "bjw-s.common.render.ingresses" . | nindent 0 -}} + {{- include "bjw-s.common.render.serviceMonitors" . | nindent 0 -}} +{{- end -}} diff --git a/charts/library/common/templates/loader/_init.tpl b/charts/library/common/templates/loader/_init.tpl new file mode 100644 index 00000000..95f63f62 --- /dev/null +++ b/charts/library/common/templates/loader/_init.tpl @@ -0,0 +1,4 @@ +{{- define "bjw-s.common.loader.init" -}} + {{- /* Merge the local chart values and the common chart defaults */ -}} + {{- include "bjw-s.common.values.init" . }} +{{- end -}} diff --git a/charts/library/common/templates/_configmap.tpl b/charts/library/common/templates/render/_configmaps.tpl similarity index 59% rename from charts/library/common/templates/_configmap.tpl rename to charts/library/common/templates/render/_configmaps.tpl index 73ad958e..f6965dc7 100644 --- a/charts/library/common/templates/_configmap.tpl +++ b/charts/library/common/templates/render/_configmaps.tpl @@ -1,19 +1,19 @@ {{/* Renders the configMap objects required by the chart. */}} -{{- define "common.configmap" -}} +{{- define "bjw-s.common.render.configmaps" -}} {{- /* Generate named configMaps as required */ -}} - {{- range $name, $configmap := .Values.configmap }} + {{- range $name, $configmap := .Values.configMaps -}} {{- if $configmap.enabled -}} {{- $configmapValues := $configmap -}} - {{/* set the default nameOverride to the configMap name */}} + {{- /* set the default nameOverride to the configMap name */ -}} {{- if not $configmapValues.nameOverride -}} {{- $_ := set $configmapValues "nameOverride" $name -}} {{ end -}} {{- $_ := set $ "ObjectValues" (dict "configmap" $configmapValues) -}} - {{- include "common.classes.configmap" $ }} - {{- end }} - {{- end }} -{{- end }} + {{- include "bjw-s.common.class.configmap" $ | nindent 0 -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/render/_controller.tpl b/charts/library/common/templates/render/_controller.tpl new file mode 100644 index 00000000..1d6bf137 --- /dev/null +++ b/charts/library/common/templates/render/_controller.tpl @@ -0,0 +1,16 @@ +{{/* +Renders the controller object required by the chart. +*/}} +{{- define "bjw-s.common.render.controller" -}} + {{- if .Values.controller.enabled -}} + {{- if eq .Values.controller.type "deployment" -}} + {{- include "bjw-s.common.class.deployment" . | nindent 0 -}} + {{ else if eq .Values.controller.type "daemonset" -}} + {{- include "bjw-s.common.class.daemonset" . | nindent 0 -}} + {{ else if eq .Values.controller.type "statefulset" -}} + {{- include "bjw-s.common.class.statefulset" . | nindent 0 -}} + {{ else -}} + {{- fail (printf "Not a valid controller.type (%s)" .Values.controller.type) -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/render/_ingresses.tpl b/charts/library/common/templates/render/_ingresses.tpl new file mode 100644 index 00000000..6a7551b1 --- /dev/null +++ b/charts/library/common/templates/render/_ingresses.tpl @@ -0,0 +1,19 @@ +{{/* +Renders the Ingress objects required by the chart. +*/}} +{{- define "bjw-s.common.render.ingresses" -}} + {{- /* Generate named ingresses as required */ -}} + {{- range $name, $ingress := .Values.ingress }} + {{- if $ingress.enabled -}} + {{- $ingressValues := $ingress -}} + + {{/* set defaults */}} + {{- if and (not $ingressValues.nameOverride) (ne $name (include "bjw-s.common.lib.ingress.primary" $)) -}} + {{- $_ := set $ingressValues "nameOverride" $name -}} + {{- end -}} + + {{- $_ := set $ "ObjectValues" (dict "ingress" $ingressValues) -}} + {{- include "bjw-s.common.class.ingress" $ | nindent 0 -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/_pvc.tpl b/charts/library/common/templates/render/_pvcs.tpl similarity index 70% rename from charts/library/common/templates/_pvc.tpl rename to charts/library/common/templates/render/_pvcs.tpl index 608b4de6..29ec5c83 100644 --- a/charts/library/common/templates/_pvc.tpl +++ b/charts/library/common/templates/render/_pvcs.tpl @@ -1,16 +1,16 @@ {{/* Renders the Persistent Volume Claim objects required by the chart. */}} -{{- define "common.pvc" -}} +{{- define "bjw-s.common.render.pvcs" -}} {{- /* Generate pvc as required */ -}} - {{- range $index, $PVC := .Values.persistence }} + {{- range $index, $PVC := .Values.persistence -}} {{- if and $PVC.enabled (eq (default "pvc" $PVC.type) "pvc") (not $PVC.existingClaim) -}} {{- $persistenceValues := $PVC -}} {{- if not $persistenceValues.nameOverride -}} {{- $_ := set $persistenceValues "nameOverride" $index -}} {{- end -}} {{- $_ := set $ "ObjectValues" (dict "persistence" $persistenceValues) -}} - {{- include "common.classes.pvc" $ | nindent 0 -}} - {{- end }} - {{- end }} -{{- end }} + {{- include "bjw-s.common.class.pvc" $ | nindent 0 -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/render/_secrets.tpl b/charts/library/common/templates/render/_secrets.tpl new file mode 100644 index 00000000..16d5121b --- /dev/null +++ b/charts/library/common/templates/render/_secrets.tpl @@ -0,0 +1,19 @@ +{{/* +Renders the Secret objects required by the chart. +*/}} +{{- define "bjw-s.common.render.secrets" -}} + {{- /* Generate named Secrets as required */ -}} + {{- range $name, $secret := .Values.secrets -}} + {{- if $secret.enabled -}} + {{- $secretValues := $secret -}} + + {{- /* set the default nameOverride to the Secret name */ -}} + {{- if not $secretValues.nameOverride -}} + {{- $_ := set $secretValues "nameOverride" $name -}} + {{ end -}} + + {{- $_ := set $ "ObjectValues" (dict "secret" $secretValues) -}} + {{- include "bjw-s.common.class.secret" $ | nindent 0 -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/render/_serviceMonitors.tpl b/charts/library/common/templates/render/_serviceMonitors.tpl new file mode 100644 index 00000000..eec3c5d9 --- /dev/null +++ b/charts/library/common/templates/render/_serviceMonitors.tpl @@ -0,0 +1,20 @@ +{{/* +Renders the serviceMonitor objects required by the chart. +*/}} +{{- define "bjw-s.common.render.serviceMonitors" -}} + {{- /* Generate named services as required */ -}} + {{- range $name, $serviceMonitor := .Values.serviceMonitor -}} + {{- if $serviceMonitor.enabled -}} + {{- $serviceMonitorValues := $serviceMonitor -}} + + {{- if and (not $serviceMonitorValues.nameOverride) (ne $name "main") -}} + {{- $_ := set $serviceMonitorValues "nameOverride" $name -}} + {{- end -}} + + {{/* Include the serviceMonitor class */}} + {{- $_ := set $ "ObjectValues" (dict "serviceMonitor" $serviceMonitorValues) -}} + {{- include "bjw-s.common.class.serviceMonitor" $ | nindent 0 -}} + {{- $_ := unset $.ObjectValues "serviceMonitor" -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/render/_serviceaccount.tpl b/charts/library/common/templates/render/_serviceaccount.tpl new file mode 100644 index 00000000..8212c040 --- /dev/null +++ b/charts/library/common/templates/render/_serviceaccount.tpl @@ -0,0 +1,8 @@ +{{/* +Renders the serviceAccount object required by the chart. +*/}} +{{- define "bjw-s.common.render.serviceAccount" -}} + {{- if .Values.serviceAccount.create -}} + {{- include "bjw-s.common.class.serviceAccount" $ | nindent 0 -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/render/_services.tpl b/charts/library/common/templates/render/_services.tpl new file mode 100644 index 00000000..c270fa1c --- /dev/null +++ b/charts/library/common/templates/render/_services.tpl @@ -0,0 +1,21 @@ +{{/* +Renders the Service objects required by the chart. +*/}} +{{- define "bjw-s.common.render.services" -}} + {{- /* Generate named services as required */ -}} + {{- range $name, $service := .Values.service -}} + {{- if $service.enabled -}} + {{- $serviceValues := $service -}} + + {{/* set the default nameOverride to the service name */}} + {{- if and (not $serviceValues.nameOverride) (ne $name (include "bjw-s.common.lib.service.primary" $)) -}} + {{- $_ := set $serviceValues "nameOverride" $name -}} + {{ end -}} + + {{/* Include the Service class */}} + {{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}} + {{- include "bjw-s.common.class.service" $ | nindent 0 -}} + {{- $_ := unset $.ObjectValues "service" -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/chart/_values.tpl b/charts/library/common/templates/values/_init.tpl similarity index 74% rename from charts/library/common/templates/lib/chart/_values.tpl rename to charts/library/common/templates/values/_init.tpl index d3c8413c..e9a7af8f 100644 --- a/charts/library/common/templates/lib/chart/_values.tpl +++ b/charts/library/common/templates/values/_init.tpl @@ -1,5 +1,7 @@ -{{/* Merge the local chart values and the common chart defaults */}} -{{- define "common.values.setup" -}} +{{/* +Merge the local chart values and the common chart defaults +*/}} +{{- define "bjw-s.common.values.init" -}} {{- if .Values.common -}} {{- $defaultValues := deepCopy .Values.common -}} {{- $userValues := deepCopy (omit .Values "common") -}} diff --git a/charts/library/common/values.yaml b/charts/library/common/values.yaml index 115a4d42..b108f8db 100644 --- a/charts/library/common/values.yaml +++ b/charts/library/common/values.yaml @@ -59,16 +59,6 @@ podAnnotations: {} # -- Set labels on the pod podLabels: {} -# -- Add a Horizontal Pod Autoscaler -# @default -- -autoscaling: - enabled: false - target: # deploymentname - minReplicas: # 1 - maxReplicas: # 100 - targetCPUUtilizationPercentage: # 80 - targetMemoryUtilizationPercentage: # 80 - serviceAccount: # -- Specifies whether a service account should be created create: false @@ -83,16 +73,27 @@ serviceAccount: # -- Specifies whether a service account token should be automatically mounted. automountServiceAccountToken: true -# -- Use this to populate a secret with the values you specify. +# -- Use this to populate secrets with the values you specify. # Be aware that these values are not encrypted by default, and could therefore visible # to anybody with access to the values.yaml file. -secret: {} - # PASSWORD: my-password +# Additional Secrets can be added by adding a dictionary key similar to the 'secret' object. +# @default -- See below +secrets: + secret: + # -- Enables or disables the Secret + enabled: false + # -- Labels to add to the Secret + labels: {} + # -- Annotations to add to the Secret + annotations: {} + # -- Secret stringData content. Helm template enabled. + stringData: {} + # foo: bar # -- Configure configMaps for the chart here. # Additional configMaps can be added by adding a dictionary key similar to the 'config' object. # @default -- See below -configmap: +configMaps: config: # -- Enables or disables the configMap enabled: false @@ -188,6 +189,9 @@ probes: enabled: true # -- Set this to `true` if you wish to specify your own livenessProbe custom: false + # -- sets the probe type when not using a custom probe + # @default -- "TCP" + type: TCP # -- The spec field contains the values for the default livenessProbe. # If you selected `custom: true`, this field holds the definition of the livenessProbe. # @default -- See below @@ -204,6 +208,9 @@ probes: enabled: true # -- Set this to `true` if you wish to specify your own readinessProbe custom: false + # -- sets the probe type when not using a custom probe + # @default -- "TCP" + type: TCP # -- The spec field contains the values for the default readinessProbe. # If you selected `custom: true`, this field holds the definition of the readinessProbe. # @default -- See below @@ -220,6 +227,9 @@ probes: enabled: true # -- Set this to `true` if you wish to specify your own startupProbe custom: false + # -- sets the probe type when not using a custom probe + # @default -- "TCP" + type: TCP # -- The spec field contains the values for the default startupProbe. # If you selected `custom: true`, this field holds the definition of the startupProbe. # @default -- See below @@ -277,20 +287,6 @@ service: # -- Provide additional labels which may be required. labels: {} - # -- Configure a serviceMonitor for this Service. - # @default -- See below - monitor: - # -- Enables or disables the serviceMonitor. - enabled: false - # -- Configures the endpoints for the serviceMonitor. - # @default -- See values.yaml - endpoints: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s - # -- Configure the Service port information here. # Additional ports can be added by adding a dictionary key similar to the 'http' service. # @default -- See below @@ -320,6 +316,43 @@ service: # [[ref]](https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport) nodePort: + # -- Allow adding additional match labels + extraSelectorLabels: {} + +# -- Configure the ServiceMonitors for the chart here. +# Additional ServiceMonitors can be added by adding a dictionary key similar to the 'main' ServiceMonitors. +# @default -- See below +serviceMonitor: + main: + # -- Enables or disables the serviceMonitor. + enabled: false + + # -- Override the name suffix that is used for this serviceMonitor. + nameOverride: + + # -- Provide additional annotations which may be required. + annotations: {} + + # -- Provide additional labels which may be required. + labels: {} + + # -- Configures a custom selector for the serviceMonitor, this takes precedence over + # specifying a service name. + # Helm templates can be used. + selector: {} + + # -- Configures the target Service for the serviceMonitor. Helm templates can be used. + serviceName: main + + # -- Configures the endpoints for the serviceMonitor. + # @default -- See values.yaml + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + # -- Configure the ingresses for the chart here. # Additional ingresses can be added by adding a dictionary key similar to the 'main' ingress. # @default -- See below @@ -344,7 +377,6 @@ ingress: labels: {} # -- Set the ingressClass that is used for this ingress. - # Requires Kubernetes >=1.19 ingressClassName: # "nginx" ## Configure the hosts for the ingress @@ -355,7 +387,6 @@ ingress: paths: - # -- Path. Helm template can be passed. path: / - # -- Ignored if not kubeVersion >= 1.14-0 pathType: Prefix service: # -- Overrides the service name reference for this path @@ -435,10 +466,14 @@ persistence: # -- Used in conjunction with `controller.type: statefulset` to create individual disks for each instance. volumeClaimTemplates: [] # - name: data +# labels: {} +# annotations: {} # mountPath: /data # accessMode: "ReadWriteOnce" # size: 1Gi # - name: backup +# labels: {} +# annotations: {} # mountPath: /backup # subPath: theSubPath # accessMode: "ReadWriteOnce" @@ -507,7 +542,7 @@ addons: # -- Specify the Gluetun image repository: docker.io/qmcgaw/gluetun # -- Specify the Gluetun image tag - tag: v3.31.1 + tag: v3.32.0 # -- Specify the Gluetun image pull policy pullPolicy: IfNotPresent @@ -604,7 +639,7 @@ addons: # -- Specify the code-server image repository: ghcr.io/coder/code-server # -- Specify the code-server image tag - tag: 4.7.1 + tag: 4.8.2 # -- Specify the code-server image pull policy pullPolicy: IfNotPresent @@ -651,7 +686,7 @@ addons: port: 12321 enabled: true protocol: TCP - targetPort: codeserver + targetPort: 12321 ## Specify the nodePort value for the LoadBalancer and NodePort service types. ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport ## @@ -670,14 +705,12 @@ addons: labels: {} # -- Set the ingressClass that is used for this ingress. - # Requires Kubernetes >=1.19 ingressClassName: # "nginx" hosts: - host: code.chart-example.local paths: - path: / - # Ignored if not kubeVersion >= 1.14-0 pathType: Prefix tls: [] # - secretName: chart-example-tls diff --git a/charts/other/app-template/Chart.yaml b/charts/other/app-template/Chart.yaml index 601ad44b..d775abbb 100644 --- a/charts/other/app-template/Chart.yaml +++ b/charts/other/app-template/Chart.yaml @@ -2,19 +2,20 @@ 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: 0.2.2 +version: 1.0.0 +kubeVersion: ">=1.22.0-0" maintainers: - name: bjw-s email: me@bjw-s.dev dependencies: - name: common repository: https://bjw-s.github.io/helm-charts - version: 0.2.2 + version: 1.0.0 annotations: artifacthub.io/changes: |- - kind: changed description: | - Updated library version to 0.2.2. + **BREAKING**: Updated library version to 1.0.0. links: - name: Common library chart definition url: https://github.com/bjw-s/helm-charts/blob/main/charts/library/common/Chart.yaml diff --git a/charts/other/app-template/ci/codeserver-values.yaml b/charts/other/app-template/ci/codeserver-values.yaml index 61af9eeb..8284a461 100644 --- a/charts/other/app-template/ci/codeserver-values.yaml +++ b/charts/other/app-template/ci/codeserver-values.yaml @@ -23,10 +23,11 @@ persistence: addons: codeserver: enabled: true + git: + deployKey: test workingDir: "/www/assets" ingress: - main: - enabled: true + enabled: true volumeMounts: - name: config mountPath: /www/assets diff --git a/charts/other/app-template/templates/common.yaml b/charts/other/app-template/templates/common.yaml index 9e25cf24..6da812bd 100644 --- a/charts/other/app-template/templates/common.yaml +++ b/charts/other/app-template/templates/common.yaml @@ -1,15 +1,14 @@ --- -{{- include "common.values.setup" . }} +{{- include "bjw-s.common.loader.init" . }} {{- define "app-template.hardcodedValues" -}} - # Set the nameOverride based on the release name if no override has been set {{ if not .Values.global.nameOverride }} global: nameOverride: "{{ .Release.Name }}" {{ end }} - {{- end -}} {{- $_ := mergeOverwrite .Values (include "app-template.hardcodedValues" . | fromYaml) -}} -{{ include "common.all" . }} +{{/* Render the templates */}} +{{ include "bjw-s.common.loader.generate" . }} diff --git a/charts/other/app-template/tests/addons/codeserver_test.yaml b/charts/other/app-template/tests/addons/codeserver_test.yaml index 2e780ffa..e76a849b 100644 --- a/charts/other/app-template/tests/addons/codeserver_test.yaml +++ b/charts/other/app-template/tests/addons/codeserver_test.yaml @@ -29,15 +29,15 @@ tests: asserts: - hasDocuments: count: 3 - - documentIndex: 0 - isKind: - of: Service - - documentIndex: &DeploymentDocument 1 + - documentIndex: &DeploymentDocument 0 isKind: of: Deployment - documentIndex: &AddonServiceDocument 2 isKind: of: Service + - documentIndex: 1 + isKind: + of: Service - documentIndex: *DeploymentDocument equal: path: spec.template.spec.containers[1].name @@ -63,87 +63,6 @@ tests: - documentIndex: &AddonDeployKeySecretDocument 0 isKind: of: Secret - - documentIndex: &DeploymentDocument 2 - isKind: - of: Deployment - - documentIndex: *DeploymentDocument - contains: - path: spec.template.spec.containers[1].volumeMounts - content: - mountPath: /root/.ssh/id_rsa - name: deploykey - subPath: id_rsa - - documentIndex: *DeploymentDocument - contains: - path: spec.template.spec.volumes - content: - name: deploykey - secret: - defaultMode: 256 - items: - - key: id_rsa - path: id_rsa - secretName: RELEASE-NAME-deploykey - - documentIndex: *AddonDeployKeySecretDocument - equal: - path: metadata.name - value: RELEASE-NAME-deploykey - - - it: addon enabled with InlineBase64 deployKey should pass - set: - addons: - codeserver: - enabled: true - git: - deployKeyBase64: dGVzdEtleQ== - volumeMounts: - - name: "config" - mountPath: "/data/config" - asserts: - - hasDocuments: - count: 4 - - documentIndex: &AddonDeployKeySecretDocument 0 - isKind: - of: Secret - - documentIndex: &DeploymentDocument 2 - isKind: - of: Deployment - - documentIndex: *DeploymentDocument - contains: - path: spec.template.spec.containers[1].volumeMounts - content: - mountPath: /root/.ssh/id_rsa - name: deploykey - subPath: id_rsa - - documentIndex: *DeploymentDocument - contains: - path: spec.template.spec.volumes - content: - name: deploykey - secret: - defaultMode: 256 - items: - - key: id_rsa - path: id_rsa - secretName: RELEASE-NAME-deploykey - - documentIndex: *AddonDeployKeySecretDocument - equal: - path: metadata.name - value: RELEASE-NAME-deploykey - - - it: addon enabled with existingSecret deployKey should pass - set: - addons: - codeserver: - enabled: true - git: - deployKeySecret: test-secret - volumeMounts: - - name: "config" - mountPath: "/data/config" - asserts: - - hasDocuments: - count: 3 - documentIndex: &DeploymentDocument 1 isKind: of: Deployment @@ -154,6 +73,87 @@ tests: mountPath: /root/.ssh/id_rsa name: deploykey subPath: id_rsa + - documentIndex: *DeploymentDocument + contains: + path: spec.template.spec.volumes + content: + name: deploykey + secret: + defaultMode: 256 + items: + - key: id_rsa + path: id_rsa + secretName: RELEASE-NAME-addon-codeserver-deploykey + - documentIndex: *AddonDeployKeySecretDocument + equal: + path: metadata.name + value: RELEASE-NAME-addon-codeserver-deploykey + + - it: addon enabled with InlineBase64 deployKey should pass + set: + addons: + codeserver: + enabled: true + git: + deployKeyBase64: dGVzdEtleQ== + volumeMounts: + - name: "config" + mountPath: "/data/config" + asserts: + - hasDocuments: + count: 4 + - documentIndex: &AddonDeployKeySecretDocument 0 + isKind: + of: Secret + - documentIndex: &DeploymentDocument 1 + isKind: + of: Deployment + - documentIndex: *DeploymentDocument + contains: + path: spec.template.spec.containers[1].volumeMounts + content: + mountPath: /root/.ssh/id_rsa + name: deploykey + subPath: id_rsa + - documentIndex: *DeploymentDocument + contains: + path: spec.template.spec.volumes + content: + name: deploykey + secret: + defaultMode: 256 + items: + - key: id_rsa + path: id_rsa + secretName: RELEASE-NAME-addon-codeserver-deploykey + - documentIndex: *AddonDeployKeySecretDocument + equal: + path: metadata.name + value: RELEASE-NAME-addon-codeserver-deploykey + + - it: addon enabled with existingSecret deployKey should pass + set: + addons: + codeserver: + enabled: true + git: + deployKeySecret: test-secret + volumeMounts: + - name: "config" + mountPath: "/data/config" + asserts: + - hasDocuments: + count: 3 + - documentIndex: &DeploymentDocument 0 + isKind: + of: Deployment + - documentIndex: *DeploymentDocument + contains: + path: spec.template.spec.containers[1].volumeMounts + content: + mountPath: /root/.ssh/id_rsa + name: deploykey + subPath: id_rsa - documentIndex: *DeploymentDocument contains: path: spec.template.spec.volumes diff --git a/charts/other/app-template/tests/addons/vpn_test.yaml b/charts/other/app-template/tests/addons/vpn_test.yaml index 20083d78..7f37d61c 100644 --- a/charts/other/app-template/tests/addons/vpn_test.yaml +++ b/charts/other/app-template/tests/addons/vpn_test.yaml @@ -68,11 +68,63 @@ tests: items: - key: vpnConfigfile path: vpnConfigfile - secretName: RELEASE-NAME-vpnconfig + secretName: RELEASE-NAME-addon-vpn-config - documentIndex: *AddonVPNConfigSecretDocument equal: path: metadata.name - value: RELEASE-NAME-vpnconfig + value: RELEASE-NAME-addon-vpn-config + + - it: addon enabled with up/down scripts should pass + set: + addons: + vpn: + enabled: true + scripts: + up: | + test_up + down: | + test_down + asserts: + - hasDocuments: + count: 3 + - documentIndex: &AddonVPNConfigConfigMapDocument 0 + isKind: + of: ConfigMap + - documentIndex: &DeploymentDocument 1 + isKind: + of: Deployment + - documentIndex: *DeploymentDocument + contains: + path: spec.template.spec.containers[1].volumeMounts + content: + mountPath: /gluetun/scripts/up.sh + name: vpnscript + subPath: up.sh + - documentIndex: *DeploymentDocument + contains: + path: spec.template.spec.containers[1].volumeMounts + content: + mountPath: /gluetun/scripts/down.sh + name: vpnscript + subPath: down.sh + - documentIndex: *DeploymentDocument + contains: + path: spec.template.spec.volumes + content: + configMap: + items: + - key: up.sh + mode: 511 + path: up.sh + - key: down.sh + mode: 511 + path: down.sh + name: RELEASE-NAME-addon-vpn + name: vpnscript + - documentIndex: *AddonVPNConfigConfigMapDocument + equal: + path: metadata.name + value: RELEASE-NAME-addon-vpn - it: addon enabled with existing configFile secret should pass set: diff --git a/charts/other/app-template/tests/configmap/metadata_test.yaml b/charts/other/app-template/tests/configmap/metadata_test.yaml index 7f7cebb2..d5d3372f 100644 --- a/charts/other/app-template/tests/configmap/metadata_test.yaml +++ b/charts/other/app-template/tests/configmap/metadata_test.yaml @@ -4,7 +4,7 @@ templates: tests: - it: default metadata should pass set: - configmap: + configMaps: config: enabled: true asserts: @@ -21,11 +21,11 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 - it: custom metadata should pass set: - configmap: + configMaps: config: enabled: true annotations: @@ -48,7 +48,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test - it: custom metadata with global metadata should pass @@ -58,7 +58,7 @@ tests: global_label: test annotations: global_annotation: test - configmap: + configMaps: config: enabled: true annotations: @@ -83,5 +83,5 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test diff --git a/charts/other/app-template/tests/configmap/names_test.yaml b/charts/other/app-template/tests/configmap/names_test.yaml index 0f9a36da..b00ae5ea 100644 --- a/charts/other/app-template/tests/configmap/names_test.yaml +++ b/charts/other/app-template/tests/configmap/names_test.yaml @@ -17,7 +17,7 @@ tests: - it: with disabled configMap should pass set: - configmap: + configMaps: config: enabled: false asserts: @@ -34,7 +34,7 @@ tests: - it: with multiple configMap should pass set: - configmap: + configMaps: config: enabled: true data: @@ -59,7 +59,7 @@ tests: - it: default name should pass set: - configmap: + configMaps: config: enabled: true asserts: @@ -75,7 +75,7 @@ tests: - it: with nameOverride should pass set: - configmap: + configMaps: config: enabled: true nameOverride: http diff --git a/charts/other/app-template/tests/configmap/pod_metadata_test.yaml b/charts/other/app-template/tests/configmap/pod_metadata_test.yaml index 593baa89..bc181e45 100644 --- a/charts/other/app-template/tests/configmap/pod_metadata_test.yaml +++ b/charts/other/app-template/tests/configmap/pod_metadata_test.yaml @@ -4,7 +4,7 @@ templates: tests: - it: default metadata should pass set: - configmap: + configMaps: config: enabled: true data: diff --git a/charts/other/app-template/tests/controller/metadata_daemonset_test.yaml b/charts/other/app-template/tests/controller/metadata_daemonset_test.yaml index a3d20ace..5f10460b 100644 --- a/charts/other/app-template/tests/controller/metadata_daemonset_test.yaml +++ b/charts/other/app-template/tests/controller/metadata_daemonset_test.yaml @@ -19,7 +19,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 - it: custom metadata should pass set: @@ -45,7 +45,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test - it: custom metadata with global metadata should pass @@ -79,5 +79,5 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test diff --git a/charts/other/app-template/tests/controller/metadata_deployment_test.yaml b/charts/other/app-template/tests/controller/metadata_deployment_test.yaml index ab1dc261..22e04587 100644 --- a/charts/other/app-template/tests/controller/metadata_deployment_test.yaml +++ b/charts/other/app-template/tests/controller/metadata_deployment_test.yaml @@ -19,7 +19,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 - it: custom metadata should pass set: @@ -45,7 +45,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test - it: custom metadata with global metadata should pass @@ -79,5 +79,5 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test diff --git a/charts/other/app-template/tests/controller/metadata_statefulset_test.yaml b/charts/other/app-template/tests/controller/metadata_statefulset_test.yaml index 7e2eb66e..cedf7713 100644 --- a/charts/other/app-template/tests/controller/metadata_statefulset_test.yaml +++ b/charts/other/app-template/tests/controller/metadata_statefulset_test.yaml @@ -19,7 +19,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 - it: custom metadata should pass set: @@ -45,7 +45,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test - it: custom metadata with global metadata should pass @@ -79,5 +79,5 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test diff --git a/charts/other/app-template/tests/ingress/metadata_test.yaml b/charts/other/app-template/tests/ingress/metadata_test.yaml index 4b84b872..df6f026f 100644 --- a/charts/other/app-template/tests/ingress/metadata_test.yaml +++ b/charts/other/app-template/tests/ingress/metadata_test.yaml @@ -19,7 +19,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 - it: custom metadata should pass set: @@ -45,7 +45,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test - it: custom metadata with global metadata should pass @@ -79,5 +79,5 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test diff --git a/charts/other/app-template/tests/ingress/service_reference_test.yaml b/charts/other/app-template/tests/ingress/service_reference_test.yaml index 3f105dd4..6992ce5a 100644 --- a/charts/other/app-template/tests/ingress/service_reference_test.yaml +++ b/charts/other/app-template/tests/ingress/service_reference_test.yaml @@ -13,8 +13,10 @@ tests: equal: path: spec.rules[0].http.paths[0].backend value: - serviceName: RELEASE-NAME - servicePort: null + service: + name: RELEASE-NAME + port: + number: null - it: custom service reference should pass set: @@ -35,5 +37,7 @@ tests: equal: path: spec.rules[0].http.paths[0].backend value: - serviceName: pathService - servicePort: 1234 + service: + name: pathService + port: + number: 1234 diff --git a/charts/other/app-template/tests/persistence/types_test.yaml b/charts/other/app-template/tests/persistence/types_test.yaml index 3bced08f..0a330c0b 100644 --- a/charts/other/app-template/tests/persistence/types_test.yaml +++ b/charts/other/app-template/tests/persistence/types_test.yaml @@ -54,7 +54,7 @@ tests: configmap: enabled: true type: configMap - name: "{{ include \"common.names.fullname\" $ }}-config" + name: "{{ include \"bjw-s.common.lib.chart.names.fullname\" $ }}-config" asserts: - documentIndex: 0 isKind: diff --git a/charts/other/app-template/tests/persistence/volumeclaimtemplates_test.yaml b/charts/other/app-template/tests/persistence/volumeclaimtemplates_test.yaml index 7efc48a4..fd26bc72 100644 --- a/charts/other/app-template/tests/persistence/volumeclaimtemplates_test.yaml +++ b/charts/other/app-template/tests/persistence/volumeclaimtemplates_test.yaml @@ -11,6 +11,10 @@ tests: accessMode: "ReadWriteOnce" size: "10Gi" storageClass: "storage" + labels: + test: "label" + annotations: + test: "annotation" asserts: - documentIndex: 0 isKind: @@ -21,6 +25,10 @@ tests: value: metadata: name: storage + labels: + test: "label" + annotations: + test: "annotation" spec: accessModes: - ReadWriteOnce diff --git a/charts/other/app-template/tests/pvc/metadata_test.yaml b/charts/other/app-template/tests/pvc/metadata_test.yaml index 6d386895..2e3b8e44 100644 --- a/charts/other/app-template/tests/pvc/metadata_test.yaml +++ b/charts/other/app-template/tests/pvc/metadata_test.yaml @@ -19,7 +19,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 - it: retain enabled should pass set: @@ -42,7 +42,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 - it: custom metadata should pass set: @@ -68,7 +68,7 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test - it: custom metadata with global metadata should pass @@ -102,5 +102,5 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test diff --git a/charts/other/app-template/tests/service/metadata_test.yaml b/charts/other/app-template/tests/service/metadata_test.yaml index b5ca163a..c47125d6 100644 --- a/charts/other/app-template/tests/service/metadata_test.yaml +++ b/charts/other/app-template/tests/service/metadata_test.yaml @@ -18,7 +18,7 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/service: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 - it: custom metadata should pass set: @@ -45,7 +45,7 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/service: RELEASE-NAME - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test - it: custom metadata with global metadata should pass @@ -80,5 +80,5 @@ tests: app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/service: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.2.2 + helm.sh/chart: app-template-1.0.0 test_label: test diff --git a/charts/other/app-template/tests/service/servicemonitor_test.yaml b/charts/other/app-template/tests/serviceMonitor/servicemonitor_test.yaml similarity index 60% rename from charts/other/app-template/tests/service/servicemonitor_test.yaml rename to charts/other/app-template/tests/serviceMonitor/servicemonitor_test.yaml index fcbcdcf2..0e62738b 100644 --- a/charts/other/app-template/tests/service/servicemonitor_test.yaml +++ b/charts/other/app-template/tests/serviceMonitor/servicemonitor_test.yaml @@ -1,4 +1,4 @@ -suite: service values +suite: serviceMonitor values templates: - common.yaml tests: @@ -15,10 +15,9 @@ tests: - it: a serviceMonitor is not created when disabled set: - service: + serviceMonitor: main: - monitor: - enabled: false + enabled: false asserts: - hasDocuments: count: 2 @@ -31,16 +30,72 @@ tests: - it: a serviceMonitor is created set: - service: + serviceMonitor: main: - monitor: - enabled: true - endpoints: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s + enabled: true + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + asserts: + - hasDocuments: + count: 3 + - documentIndex: &ServiceMonitorDocument 2 + isKind: + of: ServiceMonitor + - documentIndex: *ServiceMonitorDocument + equal: + path: metadata.name + value: RELEASE-NAME + - documentIndex: *ServiceMonitorDocument + equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/name: RELEASE-NAME + app.kubernetes.io/service: main + - documentIndex: *ServiceMonitorDocument + equal: + path: spec.endpoints + value: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + + - it: a serviceMonitor is created with nameOverride + set: + serviceMonitor: + main: + enabled: true + nameOverride: test + asserts: + - hasDocuments: + count: 3 + - documentIndex: &ServiceMonitorDocument 2 + isKind: + of: ServiceMonitor + - documentIndex: *ServiceMonitorDocument + equal: + path: metadata.name + value: RELEASE-NAME-test + - documentIndex: *ServiceMonitorDocument + equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/name: RELEASE-NAME + app.kubernetes.io/service: main + + - it: a serviceMonitor is created with a templated service + set: + serviceMonitor: + main: + enabled: true + serviceName: "{{ .Release.Name }}" asserts: - hasDocuments: count: 3 @@ -58,29 +113,15 @@ tests: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/service: RELEASE-NAME - - documentIndex: *ServiceMonitorDocument - equal: - path: spec.endpoints - value: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s - - it: a serviceMonitor is created with nameOverride + - it: a serviceMonitor is created with a custom selector set: - service: + serviceMonitor: main: - nameOverride: test - monitor: - enabled: true - endpoints: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s + enabled: true + selector: + mySelector: + test: "true" asserts: - hasDocuments: count: 3 @@ -90,20 +131,10 @@ tests: - documentIndex: *ServiceMonitorDocument equal: path: metadata.name - value: RELEASE-NAME-test + value: RELEASE-NAME - documentIndex: *ServiceMonitorDocument equal: - path: spec.selector.matchLabels + path: spec.selector value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/name: RELEASE-NAME - app.kubernetes.io/service: RELEASE-NAME-test - - documentIndex: *ServiceMonitorDocument - equal: - path: spec.endpoints - value: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s + mySelector: + test: "true"