From f7fb76d23089f2b0a2eedb1e860bd53ca1be50d5 Mon Sep 17 00:00:00 2001 From: Martyn Ranyard Date: Thu, 26 Oct 2023 21:30:12 +0200 Subject: [PATCH] Let's try something that needs a secret Signed-off-by: Martyn Ranyard --- apps-helm/sshtunnel/templates/_helpers.tpl | 62 +++++++++++++++++ apps-helm/sshtunnel/templates/deployment.yaml | 67 +++++++++++++++++++ .../templates/secretsProviderClass.yaml | 10 +++ 3 files changed, 139 insertions(+) create mode 100644 apps-helm/sshtunnel/templates/_helpers.tpl create mode 100644 apps-helm/sshtunnel/templates/deployment.yaml create mode 100644 apps-helm/sshtunnel/templates/secretsProviderClass.yaml diff --git a/apps-helm/sshtunnel/templates/_helpers.tpl b/apps-helm/sshtunnel/templates/_helpers.tpl new file mode 100644 index 0000000..21ab270 --- /dev/null +++ b/apps-helm/sshtunnel/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "sshtunnel.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +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 "sshtunnel.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "sshtunnel.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "sshtunnel.labels" -}} +helm.sh/chart: {{ include "sshtunnel.chart" . }} +{{ include "sshtunnel.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "sshtunnel.selectorLabels" -}} +app.kubernetes.io/name: {{ include "sshtunnel.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "sshtunnel.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "sshtunnel.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/apps-helm/sshtunnel/templates/deployment.yaml b/apps-helm/sshtunnel/templates/deployment.yaml new file mode 100644 index 0000000..5e210f0 --- /dev/null +++ b/apps-helm/sshtunnel/templates/deployment.yaml @@ -0,0 +1,67 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "sshtunnel.fullname" . }} + labels: + {{- include "sshtunnel.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "sshtunnel.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} + labels: + {{- include "sshtunnel.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + command: + - /bin/sh + - -c + - cp /keyfile/autossh /tmp/; chmod 600 /tmp/autossh; autossh -M0 {{.Values.tunnel.user}}@{{.Values.tunnel.sshHost}} -i /tmp/autossh + {{- range .Values.tunnel.sshOptions}} {{.}} {{end}} + {{- range .Values.tunnel.ports}} -R{{.bindIP}}:{{.source}}:{{.destsvc}}.{{.destns}}.svc.cluster.local.:{{.dest}} {{end}} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - mountPath: /keyfile + name: keyfile + volumes: + - name: keyfile + secret: + defaultMode: 256 + secretName: {{ .Chart.Name }}-keyfile + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/apps-helm/sshtunnel/templates/secretsProviderClass.yaml b/apps-helm/sshtunnel/templates/secretsProviderClass.yaml new file mode 100644 index 0000000..43bac56 --- /dev/null +++ b/apps-helm/sshtunnel/templates/secretsProviderClass.yaml @@ -0,0 +1,10 @@ +apiVersion: secrets-store.csi.x-k8s.io/v1 +kind: SecretProviderClass +metadata: + name: app-secrets +spec: + provider: 1password + parameters: + secrets: | + - resourceName: "vaults/3oh5jxmxvqvpuimu2lbuajtizi/allitems/gd24dzcpub5vmuscsvavnyu6cm/private key" + path: "keyfile"