{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if (not .Values.config.existingSSHKeySecret) }}
{{- $privateKey := coalesce .Values.config.sshPrivateKey (genPrivateKey "rsa") }}
{{- $secretName := printf "%s-ssh-key" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ $secretName }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: deepspeed
    app.kubernetes.io/component: client
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" (dict "value" .Values.commonAnnotations "context" $) | nindent 4 }}
  {{- end }}
data:
  id_rsa: {{ include "common.secrets.lookup" (dict "secret" $secretName "key" "id_rsa" "defaultValue" $privateKey "context" $) }}
{{- end }}
