Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

2.4 KB
Raw Blame
{{- $secretName := "openremote-secret" -}}
{{- $existingSecret := lookup "v1" "Secret" .Release.Namespace $secretName -}}
{{- $adminPassword := default "" .Values.credentials.adminPassword -}}
{{- $postgresqlUsername := default "" .Values.credentials.postgresqlUsername -}}
{{- $postgresqlPassword := default "" .Values.credentials.postgresqlPassword -}}
{{- if $existingSecret -}}
  {{- $existingData := required "existing openremote-secret has no data" $existingSecret.data -}}
  {{- $existingAdminPassword := required "existing openremote-secret is missing admin-password" (index $existingData "admin-password") -}}
  {{- $existingPostgresqlUsername := required "existing openremote-secret is missing postgresql-username" (index $existingData "postgresql-username") -}}
  {{- $existingPostgresqlPassword := required "existing openremote-secret is missing postgresql-password" (index $existingData "postgresql-password") -}}
  {{- if and $adminPassword (ne $adminPassword ($existingAdminPassword | b64dec)) -}}
    {{- fail "credentials.adminPassword differs from the existing Secret; credential rotation is not supported by apply" -}}
  {{- end -}}
  {{- if and $postgresqlUsername (ne $postgresqlUsername ($existingPostgresqlUsername | b64dec)) -}}
    {{- fail "credentials.postgresqlUsername differs from the existing Secret; database credential rotation is not supported by apply" -}}
  {{- end -}}
  {{- if and $postgresqlPassword (ne $postgresqlPassword ($existingPostgresqlPassword | b64dec)) -}}
    {{- fail "credentials.postgresqlPassword differs from the existing Secret; database credential rotation is not supported by apply" -}}
  {{- end -}}
  {{- $adminPassword = $existingAdminPassword | b64dec -}}
  {{- $postgresqlUsername = $existingPostgresqlUsername | b64dec -}}
  {{- $postgresqlPassword = $existingPostgresqlPassword | b64dec -}}
{{- else -}}
  {{- if not $adminPassword -}}
    {{- $adminPassword = randAlphaNum 32 -}}
  {{- end -}}
  {{- if not $postgresqlUsername -}}
    {{- $postgresqlUsername = "postgres" -}}
  {{- end -}}
  {{- if not $postgresqlPassword -}}
    {{- $postgresqlPassword = randAlphaNum 32 -}}
  {{- end -}}
{{- end -}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ $secretName }}
  annotations:
    helm.sh/resource-policy: keep
type: Opaque
data:
  admin-password: {{ $adminPassword | b64enc | quote }}
  postgresql-username: {{ $postgresqlUsername | b64enc | quote }}
  postgresql-password: {{ $postgresqlPassword | b64enc | quote }}