Is it possible to reference generated helm template name from values file

Viewed 129

While composing helm chart with few sub-charts I've encountered collision. Long story short, I'm creating config with some value, and config name is generated. But subchart expects that generated names to be referenced directly in Values.yaml file.

That's actually service with PG database & I'm trying to install prometheus-postgres-exporter to enable Prometheus monitoring for the DB. But that's not the point.

So, I have some config for building DB connection string:

apiVersion: v1
kind: Secret
metadata:
  name: {{ include "myapp.fullname" . }}-secret
type: Opaque
data:
  PG_CONN_STRING: {{ printf "postgresql://%s:%s@%s:%s/%s" .Values.postgresql.postgresqlUsername .Values.postgresql.postgresqlPassword (include "postgresql.fullname" .) .Values.postgresql.service.port .Values.postgresql.postgresqlDatabase  | b64enc | quote }}

Okay, that works file. However, when I'm trying to install prometheus-postgres-exporter, that requires naming specific secret name where DB connection string can be obtained. I have a problem with that name should be generated, so I can't provide exact value. Not sure, how can I reference that? Obviously, passing same template code doesn't work, since replacement is single-pass, not recursive.

prometheus-postgres-exporter:
  serviceMonitor:
    enabled: true
  config:
    datasourceSecret:
      name: "{{ include "myapp.fullname" . }}-secret" # Doesn't work, unfortunatelly
      key: "PG_CONN_STRING"

Is there known way to overcome this other than hardcoding values?

0 Answers
Related