From a9c62e5e633a52e10e96294b36c4e9b1201bdc59 Mon Sep 17 00:00:00 2001 From: ada-u Date: Wed, 13 Jan 2021 18:48:45 +0900 Subject: [PATCH] Pass api-token and username using Secret --- charts/Chart.yaml | 2 +- charts/README.md | 14 +++----------- charts/templates/_helpers.tpl | 11 +++++++++++ charts/templates/deployment.yaml | 11 +++++++++++ charts/templates/secret.yaml | 10 ++++++++++ charts/values.yaml | 6 ++++++ 6 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 charts/templates/secret.yaml diff --git a/charts/Chart.yaml b/charts/Chart.yaml index 2ed4c52..bc71638 100644 --- a/charts/Chart.yaml +++ b/charts/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: sendgrid-stats-exporter -description: A Helm chart for chatwork/sendgrid-stats-exporter (It's till private for now, but will make it public soon) +description: A Helm chart for chatwork/sendgrid-stats-exporter type: application version: 0.0.1 appVersion: 0.0.3 diff --git a/charts/README.md b/charts/README.md index 74c1e1f..9f5db06 100644 --- a/charts/README.md +++ b/charts/README.md @@ -6,17 +6,7 @@ A Helm chart for [chatwork/sendgrid-stats-exporter](https://github.com/chatwork/ ## Installing the Chart ``` -$ cat configmap.yaml -apiVersion: v1 -kind: ConfigMap -metadata: - name: sendgrid-config - data: - SENDGRID_API_KEY: 'secret' -$ kubectl apply -f configmap.yaml -configmap/sendgrid-config created - -$ helm install --set 'envFrom[0].configMapRef.name=sendgrid-config' sendgrid-stats-exporter ./ +$ helm install --set 'deployment.secret.apiKey=secret' --set 'deployment.secret.username=username' sendgrid-stats-exporter ./ ``` ``` @@ -49,6 +39,8 @@ The following table lists the configurable parameters of the Sendgrid-stats-expo | `podSecurityContext` | Security context for the pod | `{}` | | `securityContext` | Security context for container | `{}` | | `envFrom` | Extra custom environment variables from ConfigMaps | `[]` | +| `deployment.secret.apiKey` | SendGrid api token | `{}` | +| `deployment.secret.username` | SendGrid username | `[]` | | `service.type` | Service Type | `"ClusterIP"` | | `service.port` | Service port | `9154` | | `ingress.enabled` | If true, enable Ingress | `false` | diff --git a/charts/templates/_helpers.tpl b/charts/templates/_helpers.tpl index d020648..138feff 100644 --- a/charts/templates/_helpers.tpl +++ b/charts/templates/_helpers.tpl @@ -60,3 +60,14 @@ Create the name of the service account to use {{- default "default" .Values.serviceAccount.name }} {{- end }} {{- end }} + +{{/* +Return secret name to be used based on provided values. +*/}} +{{- define "sendgrid-stats-exporter.secretName" -}} +{{- if not .Values.deployment.secret.existingSecretName -}} +{{ default (printf "%s-secret" (include "sendgrid-stats-exporter.fullname" . )) }} +{{- else -}} + {{ .Values.deployment.secret.existingSecretName }} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/templates/deployment.yaml b/charts/templates/deployment.yaml index a40e54b..efef298 100644 --- a/charts/templates/deployment.yaml +++ b/charts/templates/deployment.yaml @@ -35,6 +35,17 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} envFrom: {{- toYaml .Values.envFrom | nindent 12 }} + env: + - name: SENDGRID_USER_NAME + valueFrom: + secretKeyRef: + name: {{ include "sendgrid-stats-exporter.secretName" . }} + key: username + - name: SENDGRID_API_KEY + valueFrom: + secretKeyRef: + name: {{ include "sendgrid-stats-exporter.secretName" . }} + key: apiKey ports: - name: http containerPort: 9154 diff --git a/charts/templates/secret.yaml b/charts/templates/secret.yaml new file mode 100644 index 0000000..b9157e1 --- /dev/null +++ b/charts/templates/secret.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "sendgrid-stats-exporter.secretName" . }} + labels: + {{- include "sendgrid-stats-exporter.labels" . | nindent 4 }} +type: Opaque +data: + username: {{ .Values.deployment.secret.username | b64enc | quote }} + apiKey: {{ .Values.deployment.secret.apiKey | b64enc | quote }} \ No newline at end of file diff --git a/charts/values.yaml b/charts/values.yaml index cf0f5c5..541c0e2 100644 --- a/charts/values.yaml +++ b/charts/values.yaml @@ -29,6 +29,12 @@ securityContext: {} envFrom: [] +deployment: + secret: + existingSecretName: + username: "" + apiKey: "" + service: type: ClusterIP port: 9154