Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move api key from configmap to secret #32

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions charts/gpu-metrics-exporter/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ spec:
env:
- name: "DCGM_HOST"
value: "localhost"
- name: "API_KEY"
valueFrom:
secretKeyRef:
name: {{ include "gpu-metrics-exporter.fullname" . }}
key: API_KEY
{{- end }}
resources:
{{- toYaml .Values.gpuMetricsExporter.resources | nindent 12 }}
Expand Down
43 changes: 43 additions & 0 deletions charts/gpu-metrics-exporter/templates/move-api-key-to-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: batch/v1
kind: Job
metadata:
name: migrate-configmap-to-secret
Ivaka marked this conversation as resolved.
Show resolved Hide resolved
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
backoffLimit: 0
template:
spec:
serviceAccountName: {{ include "gpu-metrics-exporter.serviceAccountName" . }}
containers:
- name: migrate
image: alpine/k8s:1.31.0
command:
- /bin/sh
- -c
- |
configmap_data=$(kubectl get configmap ${CONFIGMAP_NAME} -o json)

if echo $configmap_data | jq -e '.data["API_KEY"]' > /dev/null; then
secret_value=$(echo $configmap_data | jq -r '.data["API_KEY"]')

kubectl create secret generic {{ include "gpu-metrics-exporter.fullname" . }} -n {{ .Release.Namespace }} \
--from-literal=API_KEY=$secret_value \
--dry-run=client -o yaml | kubectl apply -f -

kubectl patch configmap {{ include "gpu-metrics-exporter.config-map" . }} -n {{ .Release.Namespace }} \
--type=json -p='[{"op": "remove", "path": "/data/API_KEY"}]'

kubectl rollout restart daemonset/{{ include "gpu-metrics-exporter.fullname" . }} -n {{ .Release.Namespace }}
else
echo "API_KEY not found in the ConfigMap. Skipping migration."
fi
securityContext:
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop:
- ALL
restartPolicy: Never
23 changes: 23 additions & 0 deletions charts/gpu-metrics-exporter/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ rules:
verbs:
- get
- list
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
- patch
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- update
- patch
- apiGroups:
- apps
resources:
- daemonsets
verbs:
- get
- patch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
14 changes: 14 additions & 0 deletions charts/gpu-metrics-exporter/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: v1
kind: Secret
metadata:
name: {{ include "gpu-metrics-exporter.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "gpu-metrics-exporter.labels" . | nindent 4 }}
data:
{{- if and .Values.castai (not (empty .Values.castai.apiKey)) }}
API_KEY: {{ .Values.castai.apiKey | b64enc | quote }}
{{- else }}
API_KEY: ""
{{- end }}
3 changes: 3 additions & 0 deletions charts/gpu-metrics-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ serviceAccount:
automount: true
annotations: {}

castai:
apiKey: ""

gpuMetricsExporter:
image:
repository: ghcr.io/castai/gpu-metrics-exporter/gpu-metrics-exporter
Expand Down
Loading