-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move api key from configmap to secret
- Loading branch information
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
charts/gpu-metrics-exporter/templates/move-api-key-to-secret.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters