Skip to content

Commit

Permalink
feat: Enable Secret creation using tokengen
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
  • Loading branch information
jdbaldry committed Sep 15, 2021
1 parent 4efa932 commit d90f155
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 4 deletions.
28 changes: 25 additions & 3 deletions charts/enterprise-logs/templates/tokengen/job-tokengen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ template "loki.serviceAccountName" . }}
{{- if .Values.tokengen.priorityClassName }}
priorityClassName: {{ .Values.tokengen.priorityClassName }}
{{- end }}
Expand All @@ -47,7 +46,7 @@ spec:
- name: {{ . }}
{{- end }}
{{- end }}
containers:
initContainers:
- name: enterprise-logs
image: {{ template "enterprise-logs.image" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
Expand All @@ -62,13 +61,16 @@ spec:
- -admin.client.s3.secret-access-key=supersecret
- -admin.client.s3.insecure=true
{{- end }}
- -tokengen.token-file=/shared/admin-token
{{- range $key, $value := .Values.tokengen.extraArgs }}
- "-{{ $key }}={{ $value }}"
{{- end }}
volumeMounts:
{{- if .Values.tokengen.extraVolumeMounts }}
{{ toYaml .Values.tokengen.extraVolumeMounts | nindent 12 }}
{{- end }}
- name: shared
mountPath: /shared
- name: config
mountPath: /etc/loki/config
- name: license
Expand All @@ -77,7 +79,27 @@ spec:
{{- if .Values.tokengen.env }}
{{ toYaml .Values.tokengen.env | nindent 12 }}
{{- end }}
containers:
- name: create-secret
image: bitnami/kubectl
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/bash
- -euc
- kubectl create secret generic gel-admin-token --from-file=token=/shared/admin-token --from-literal=grafana-token="$(base64 <(echo :$(cat /shared/admin-token)))"
volumeMounts:
{{- if .Values.tokengen.extraVolumeMounts }}
{{ toYaml .Values.tokengen.extraVolumeMounts | nindent 12 }}
{{- end }}
- name: shared
mountPath: /shared
- name: config
mountPath: /etc/loki/config
- name: license
mountPath: /etc/enterprise-logs/license
restartPolicy: OnFailure
serviceAccount: {{ template "enterprise-logs.tokengenFullname" . }}
serviceAccountName: {{ template "enterprise-logs.tokengenFullname" . }}
volumes:
- name: config
secret:
Expand All @@ -93,7 +115,7 @@ spec:
{{- else }}
secretName: enterprise-logs-license
{{- end }}
- name: storage
- name: shared
emptyDir: {}
{{- if .Values.tokengen.extraVolumes }}
{{ toYaml .Values.tokengen.extraVolumes | nindent 8 }}
Expand Down
20 changes: 20 additions & 0 deletions charts/enterprise-logs/templates/tokengen/role-tokengen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{ if .Values.tokengen.enable }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ template "enterprise-logs.tokengenFullname" . }}
labels:
{{- include "enterprise-logs.tokengenLabels" . | nindent 4 }}
{{- with .Values.tokengen.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
{{- with .Values.tokengen.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
"helm.sh/hook": post-install
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["create"]
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{ if .Values.tokengen.enable }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ template "enterprise-logs.tokengenFullname" . }}
labels:
{{- include "enterprise-logs.tokengenLabels" . | nindent 4 }}
{{- with .Values.tokengen.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
{{- with .Values.tokengen.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
"helm.sh/hook": post-install
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ template "enterprise-logs.tokengenFullname" . }}
subjects:
- kind: ServiceAccount
name: {{ template "enterprise-logs.tokengenFullname" . }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{ if .Values.tokengen.enable }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "enterprise-logs.tokengenFullname" . }}
labels:
{{- include "enterprise-logs.tokengenLabels" . | nindent 4 }}
{{- with .Values.tokengen.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
{{- with .Values.tokengen.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
"helm.sh/hook": post-install
{{- end }}
6 changes: 5 additions & 1 deletion charts/enterprise-logs/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ config:

# -- Configuration for `tokengen` target
tokengen:
# -- Weather the job should be part of the deployment
# -- Whether the job should be part of the deployment
enable: true
# -- Additional CLI arguments for the `tokengen` target
extraArgs: {}
Expand All @@ -193,6 +193,10 @@ tokengen:
extraVolumes: []
# -- Additional volume mounts for Pods
extraVolumeMounts: []
securityContext:
runAsNonRoot: true
runAsUser: 10001
fsGroup: 10001

# -- Configuration for the `admin-api` target
adminApi:
Expand Down

0 comments on commit d90f155

Please sign in to comment.