From 0b59dfc14cafb54844413dde70e1239b0ca07c43 Mon Sep 17 00:00:00 2001 From: Bernd Schorgers Date: Tue, 30 Jan 2024 20:11:46 +0100 Subject: [PATCH] feat(k8s-ycl): Restructure Helm helpers/includes --- charts/apps/k8s-ycl/Chart.yaml | 4 +- .../k8s-ycl/templates/_hardcodedValues.tpl | 64 ++++++++++++++++ charts/apps/k8s-ycl/templates/_helpers.tpl | 7 ++ .../templates/admissionregistration.yaml | 3 +- charts/apps/k8s-ycl/templates/common.yaml | 73 +------------------ charts/apps/k8s-ycl/templates/pki.yaml | 9 +-- 6 files changed, 79 insertions(+), 81 deletions(-) create mode 100644 charts/apps/k8s-ycl/templates/_hardcodedValues.tpl diff --git a/charts/apps/k8s-ycl/Chart.yaml b/charts/apps/k8s-ycl/Chart.yaml index b89c3948..b12083c9 100644 --- a/charts/apps/k8s-ycl/Chart.yaml +++ b/charts/apps/k8s-ycl/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 description: Kubernetes admission controller to remove CPU limits from Pods. name: k8s-ycl -version: 1.2.1 +version: 1.2.2 appVersion: v0.2.0 kubeVersion: ">=1.22.0-0" sources: @@ -24,7 +24,7 @@ annotations: artifacthub.io/changes: |- - kind: changed description: | - Update to most recent library dependency + Restructure Helm helpers / includes artifacthub.io/links: | - name: "source" url: "https://github.com/bjw-s/k8s-ycl" diff --git a/charts/apps/k8s-ycl/templates/_hardcodedValues.tpl b/charts/apps/k8s-ycl/templates/_hardcodedValues.tpl new file mode 100644 index 00000000..7ac53d06 --- /dev/null +++ b/charts/apps/k8s-ycl/templates/_hardcodedValues.tpl @@ -0,0 +1,64 @@ +{{- define "k8s-ycl.hardcodedValues" -}} +controllers: + main: + containers: + main: + probes: + liveness: + enabled: true + custom: true + spec: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + readiness: + enabled: true + custom: true + spec: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + startup: + enabled: true + custom: true + spec: + httpGet: + path: /healthz + port: 8081 + failureThreshold: 30 + periodSeconds: 10 + +service: + main: + enabled: true + nameOverride: webhook + ports: + http: + enabled: true + port: 9443 + metrics: + enabled: true + port: 8080 + probe: + enabled: true + port: 8081 + +serviceAccount: + create: true + +persistence: + certs: + enabled: true + type: secret + name: {{ include "k8s-ycl.servingCertificate" . }} + globalMounts: + - path: /tls +{{- end -}} diff --git a/charts/apps/k8s-ycl/templates/_helpers.tpl b/charts/apps/k8s-ycl/templates/_helpers.tpl index 9e1af1a5..abbc812a 100644 --- a/charts/apps/k8s-ycl/templates/_helpers.tpl +++ b/charts/apps/k8s-ycl/templates/_helpers.tpl @@ -1,3 +1,10 @@ +{{- define "k8s-ycl.init" -}} + {{/* Make sure all variables are set properly */}} + {{- include "bjw-s.common.loader.init" . }} + + {{- $_ := include "k8s-ycl.hardcodedValues" . | fromYaml | merge .Values -}} +{{- end -}} + {{- define "k8s-ycl.webhookPort" -}} 9443 {{- end -}} diff --git a/charts/apps/k8s-ycl/templates/admissionregistration.yaml b/charts/apps/k8s-ycl/templates/admissionregistration.yaml index 6b18b355..273f3c30 100644 --- a/charts/apps/k8s-ycl/templates/admissionregistration.yaml +++ b/charts/apps/k8s-ycl/templates/admissionregistration.yaml @@ -1,4 +1,5 @@ -{{- include "bjw-s.common.loader.init" . -}} +{{/* Make sure all variables are set properly */}} +{{- include "k8s-ycl.init" . -}} --- apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration diff --git a/charts/apps/k8s-ycl/templates/common.yaml b/charts/apps/k8s-ycl/templates/common.yaml index 167d7d87..b748b552 100644 --- a/charts/apps/k8s-ycl/templates/common.yaml +++ b/charts/apps/k8s-ycl/templates/common.yaml @@ -1,75 +1,6 @@ --- {{/* Make sure all variables are set properly */}} -{{- include "bjw-s.common.loader.init" . }} - -{{/* Append the hardcoded settings */}} -{{- define "k8s-ycl.hardcodedValues" -}} -controllers: - main: - containers: - main: - probes: - liveness: - enabled: true - custom: true - spec: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 0 - periodSeconds: 10 - timeoutSeconds: 1 - failureThreshold: 3 - readiness: - enabled: true - custom: true - spec: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 0 - periodSeconds: 10 - timeoutSeconds: 1 - failureThreshold: 3 - startup: - enabled: true - custom: true - spec: - httpGet: - path: /healthz - port: 8081 - failureThreshold: 30 - periodSeconds: 10 - -service: - main: - enabled: true - nameOverride: webhook - ports: - http: - enabled: true - port: 9443 - metrics: - enabled: true - port: 8080 - probe: - enabled: true - port: 8081 - -serviceAccount: - create: true - -persistence: - certs: - enabled: true - type: secret - name: {{ include "k8s-ycl.servingCertificate" . }} - globalMounts: - - path: /tls -{{- end -}} +{{- include "k8s-ycl.init" . }} {{/* Render the templates */}} -{{- $ctx := deepCopy . -}} -{{- $_ := include "k8s-ycl.hardcodedValues" . | fromYaml | merge $ctx.Values -}} - -{{- include "bjw-s.common.loader.all" $ctx }} +{{- include "bjw-s.common.loader.all" . }} diff --git a/charts/apps/k8s-ycl/templates/pki.yaml b/charts/apps/k8s-ycl/templates/pki.yaml index 3d497fb6..b90e7f11 100644 --- a/charts/apps/k8s-ycl/templates/pki.yaml +++ b/charts/apps/k8s-ycl/templates/pki.yaml @@ -1,4 +1,5 @@ -{{- include "bjw-s.common.loader.init" . -}} +{{/* Make sure all variables are set properly */}} +{{- include "k8s-ycl.init" . -}} --- # Create a selfsigned Issuer, in order to create a root CA certificate for # signing webhook serving certificates @@ -11,9 +12,7 @@ metadata: {{- include "bjw-s.common.lib.metadata.allLabels" . | nindent 4 }} spec: selfSigned: {} - --- - # Generate a CA Certificate used to sign certificates for the webhook apiVersion: cert-manager.io/v1 kind: Certificate @@ -30,9 +29,7 @@ spec: kind: Issuer commonName: "ca.k8s-ycl.cert-manager" isCA: true - --- - # Create an Issuer that uses the above generated CA certificate to issue certs apiVersion: cert-manager.io/v1 kind: Issuer @@ -44,9 +41,7 @@ metadata: spec: ca: secretName: {{ include "k8s-ycl.rootCACertificate" . }} - --- - # Finally, generate a serving certificate for the webhook to use apiVersion: cert-manager.io/v1 kind: Certificate