Skip to content

templates: Support Nested YAML for GCFG Configuration #769

@mconflitti-pbc

Description

@mconflitti-pbc

Enhancement: Support Nested YAML for GCFG Configuration

1. Problem Statement

Currently, our rstudio-library.config.gcfg template only supports a "flat" map structure. To generate configuration headers with subsections—such as [OTLPEndpoint "default"]—users are forced to use escaped string keys in their values.yaml:

    'OTLPEndpoint "default"':
      Endpoint: http://localhost:4318

or how we show here in our docs

This is error-prone, difficult to read, and breaks standard Helm nesting conventions, which makes deep-merging or using --set flags difficult.

2. Proposed Solution

Update the gcfg helper template to detect the data type of the section values.

  • If the value is a Map, it should automatically render a nested header: [Section "Subsection"].
  • If the value is a Simple Type (string/bool), it should continue to render the legacy flat header: [Section].

3. Implementation Plan

Introduce a "Hybrid" template logic using kindIs "map" to differentiate between the two input styles.

Proposed Template Logic:

    {{- define "rstudio-library.config.gcfg" -}}
    {{- range $section, $content := . -}}
      {{/* Determine if this section contains subsections or just key-values */}}
      {{- $isNested := false -}}
      {{- range $k, $v := $content -}}
        {{- if kindIs "map" $v -}}
          {{- $isNested = true -}}
        {{- end -}}
      {{- end -}}

      {{- if $isNested -}}
        {{/* New Way: Supports nested YAML maps */}}
        {{- range $sub, $vals := $content }}
    [{{ $section }} "{{ $sub }}"]
          {{- range $k, $v := $vals }}
    {{ $k }} = {{ $v }}
          {{- end }}
        {{- end }}
      {{- else -}}
        {{/* Legacy Way: Supports flat keys with manual quotes */}}
    [{{ $section }}]
        {{- range $k, $v := $content }}
    {{ $k }} = {{ $v }}
        {{- end }}
      {{- end }}
    {{- end -}}
    {{- end -}}

4. Backwards Compatibility

This change is non-breaking:

  1. Existing configurations using 'Section "Sub"': will still enter the else block and render exactly as they do today.
  2. New configurations can use the cleaner nested syntax, which is more "Helm-native."

5. Example Comparison

Input Style values.yaml Syntax Rendered .gcfg Output
Legacy 'OTLPEndpoint "default"': { Logs: true } [OTLPEndpoint "default"]
New OTLPEndpoint: { default: { Logs: true } } [OTLPEndpoint "default"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    team: connectPosit Connect related issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions