{{- range .Values.secrets }}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{ .name }}
  namespace: {{ $.namespace }}
type: Opaque
data:
  {{- range $key, $value := .data }}
  {{ $key }}: {{ $value | b64enc }}
  {{- end }}
{{- end }}

{{- if .Values.createAgentSecret }}
{{- $secret := lookup "v1" "Secret" .Release.Namespace "woodpecker-default-agent-secret" }}
---
apiVersion: v1
kind: Secret
metadata:
  name: woodpecker-default-agent-secret
  namespace: {{ .Release.Namespace }}
type: Opaque
data:
  WOODPECKER_AGENT_SECRET: {{ dig "data" "WOODPECKER_AGENT_SECRET" (randAlphaNum 64 | b64enc) $secret }}
{{- end }}
