Skip to content

Commit

Permalink
Merge pull request #10 from chatwork/passing-token-using-secret
Browse files Browse the repository at this point in the history
Pass api-token and username using Secret
  • Loading branch information
ada-u authored Jan 13, 2021
2 parents fe8afac + a9c62e5 commit 69f7e58
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion charts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 3 additions & 11 deletions charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./
```

```
Expand Down Expand Up @@ -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` |
Expand Down
11 changes: 11 additions & 0 deletions charts/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
11 changes: 11 additions & 0 deletions charts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions charts/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 6 additions & 0 deletions charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ securityContext: {}

envFrom: []

deployment:
secret:
existingSecretName:
username: ""
apiKey: ""

service:
type: ClusterIP
port: 9154
Expand Down

0 comments on commit 69f7e58

Please sign in to comment.