From 413fd292d579c48f3fb6bac15a49a916a3dec626 Mon Sep 17 00:00:00 2001 From: tde Date: Tue, 22 Feb 2022 14:40:45 +0100 Subject: [PATCH] feature expansion --- Chart.yaml | 4 ++-- config.conf | 1 + templates/_configmap.yaml | 14 +++++++++++-- templates/_deployment.yaml | 3 +++ templates/_helpers.tpl | 14 +++++++++++-- templates/rbac.yaml | 7 +++---- templates/secret-docker.yaml | 4 +++- values.yaml | 39 +++++++++++++++++++++++++++--------- 8 files changed, 66 insertions(+), 20 deletions(-) diff --git a/Chart.yaml b/Chart.yaml index 82370cb..8a3a2b3 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,8 +1,8 @@ --- apiVersion: v2 name: microservice -version: 0.3.1 -appVersion: 0.3.1 +version: 0.4.0 +appVersion: 0.4.0 description: A Helm chart which provide a DRY microservice deployment mechanism keywords: - microservice diff --git a/config.conf b/config.conf index e69de29..62aa822 100644 --- a/config.conf +++ b/config.conf @@ -0,0 +1 @@ +test configuration file \ No newline at end of file diff --git a/templates/_configmap.yaml b/templates/_configmap.yaml index 3d36b86..c2012d5 100644 --- a/templates/_configmap.yaml +++ b/templates/_configmap.yaml @@ -1,17 +1,27 @@ {{- define "configmap" -}} {{- if .Values.volumes.configMaps }} +{{ $header := .Values.configFileCommonHeader | default "" }} + {{ $root := . }} {{ range $cm := .Values.volumes.configMaps}} -{{- if $cm.data }} +--- apiVersion: v1 kind: ConfigMap metadata: name: {{ $cm.name }} data: + {{- if $cm.data }} {{- range $filename, $content := $cm.data }} # property-like keys; each key maps to a simple value {{ $filename }}: {{ $content }} {{- end }} -{{- end }} + {{- end }} + {{- if $cm.files }} + {{- range $file := $cm.files }} + {{ $file.destination }}: | + {{ $header }} + {{ $root.Files.Get $file.source }} + {{- end}} + {{- end }} {{- end }} {{- end }} {{- end -}} \ No newline at end of file diff --git a/templates/_deployment.yaml b/templates/_deployment.yaml index aa6cce8..a556b81 100644 --- a/templates/_deployment.yaml +++ b/templates/_deployment.yaml @@ -30,6 +30,9 @@ spec: imagePullSecrets: - name: {{ .Values.imagePullSecrets }} {{- end }} + {{- if .Values.imageCredentials }} + - name: {{ include "microservice.name" . }}-docker-credentials + {{- end }} {{- if .Values.serviceAccount }} serviceAccountName: {{ .Values.serviceAccount }} {{- end }} diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 162c8b5..b3238aa 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -7,14 +7,13 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end -}} - {{/* vim: set filetype=mustache: */}} {{/* Expand the name of the chart. */}} {{- define "microservice.name" -}} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} +{{- end }} {{/* Create a default fully qualified app name. @@ -40,3 +39,14 @@ Create chart name and version as used by the chart label. {{- define "microservice.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} {{- end -}} + + + +{{/* +Create docker credentials. +*/}} +{{- define "docker_credentials_tpl" }} +{{- with .Values.imageCredentials }} +{{- printf "{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}}}" .registry .username .password .email (printf "%s:%s" .username .password | b64enc) | b64enc }} +{{- end }} +{{- end }} diff --git a/templates/rbac.yaml b/templates/rbac.yaml index a8e0c4d..4b7138e 100644 --- a/templates/rbac.yaml +++ b/templates/rbac.yaml @@ -1,10 +1,9 @@ +{{- $sa := .Values.serviceAccount | default "default" }} apiVersion: v1 kind: ServiceAccount metadata: - name: {{ include "serviceaccount" .}} + name: {{ $sa }} namespace: {{ .Release.Namespace }} -imagePullSecrets: -- docker-credentials --- apiVersion: v1 kind: List @@ -30,7 +29,7 @@ items: name: {{ .Release.Name }}-crb-{{ .Release.Namespace }} subjects: - kind: ServiceAccount - name: {{ include "serviceaccount" .}} + name: {{ $sa }} namespace: {{ .Release.Namespace }} roleRef: kind: ClusterRole diff --git a/templates/secret-docker.yaml b/templates/secret-docker.yaml index cdb73fa..481e977 100644 --- a/templates/secret-docker.yaml +++ b/templates/secret-docker.yaml @@ -1,8 +1,10 @@ +{{- if .Values.imageCredentials }} apiVersion: v1 kind: Secret metadata: - name: docker-credentials + name: {{ include "microservice.name" . }}-docker-credentials namespace: {{ .Release.Namespace }} type: kubernetes.io/dockerconfigjson data: .dockerconfigjson: {{ template "docker_credentials_tpl" . }} +{{- end }} \ No newline at end of file diff --git a/values.yaml b/values.yaml index 0f482e9..88c5579 100644 --- a/values.yaml +++ b/values.yaml @@ -28,10 +28,16 @@ fullnameOverride: "" ## Secret must be manually created in the namespace. ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ ## -# imagePullSecrets: myRegistrKeySecretName +imagePullSecrets: myRegistrKeySecretName +imageCredentials: + registry: https://index.docker.io/v1/ + username: username + password: password + email: tsorage@cetic.be - -# serviceAccount: +serviceAccount: microservice-sa +createServiceAccount: true +rbac: true # Annotation for the Deployment annotations: {} @@ -68,7 +74,7 @@ readiness: failureThreshold: 3 volumes: - enabled: false + enabled: true pvc: enabled: false existing_claim: @@ -79,12 +85,27 @@ volumes: accessModes: - ReadWriteOnce + configFileCommonHeader: commonValue configMaps: -# - name: test -# mountPath: /test -# data: -# test.conf: | -# hello + - name: test + mountPath: /test + data: + test.conf: | + hello + - name: test-from-file + mountPath: /test2 + files: + - source: config.conf + destination: application.conf + - name: test-mixed + mountPath: /test3 + data: + test2.conf: | + another hello + files: + - source: config.conf + destination: application2.conf + ingress: enabled: false