Skip to content

Allow template rendering in Cluster managed services value #699

@willj-ti

Description

@willj-ti

I want to be able to dynamically name additional services. I am working towards deploying a Cluster that is externally visible through a LoadBalancer Service, and I want this additional service to have a dynamic name.

In this section from (cluster.yaml)[https://github.com/cloudnative-pg/charts/blob/main/charts/cluster/templates/cluster.yaml#L105], the config is populated as literals, without template rendering.

  {{- if not (and (empty .Values.cluster.roles) (empty .Values.cluster.services)) }}
  managed:
    {{- with .Values.cluster.services }}
    services:
      {{- toYaml . | nindent 6 }}
    {{ end }}
    {{- with .Values.cluster.roles }}
    roles:
      {{- toYaml . | nindent 6 }}
    {{ end }}
  {{- end }}

I'm fairly new to Helm, but my first idea is to add a tpl function to wrap the value somewhere in this block, e.g. {{- toYaml (tpl .) | nindent 6 }}

This is what I'm expecting my own values.yaml to look like:

cluster:
  services:
    additional:
      - selectorType: rw
        serviceTemplate:
          metadata:
            name: '{{ $.Release.Name }}-pg'
          spec:
            type: LoadBalancer
        updateStrategy: patch

Note the templated value is a string, to be evaluated later by tpl.

I am definitely open for feedback on this, including any other way to accomplish this, any pitfalls with tpl, or even a telling off that I'm doing Helm or CNPG all wrong. In the meantime, I'll fork and try it out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions