Skip to content

Conversation

@vichaos
Copy link

@vichaos vichaos commented Dec 3, 2025

Fix ConfigMap rendering to use YAML block format instead of JSON encoding

Problem

When running kustomize build --enable-helm, the APISIX ConfigMap was being rendered with JSON-encoded strings (containing \n escape sequences) instead of clean YAML block format with the pipe (|) operator. This made the rendered output extremely difficult to read and debug.

Before:

data:
  config.yaml: "#\n# Licensed to the Apache Software Foundation...\n  enable_admin: true\n  enable_admin_cors: true\n..."

After:

data:
  config.yaml: |
    #
    # Licensed to the Apache Software Foundation...
    enable_admin: true
    enable_admin_cors: true
    ...

Root Cause

The issue was caused by inconsistent Helm template whitespace control in the trustedAddresses conditional block. The template used {{ if and {{ end }} without the dash (-) modifier, which preserved extra whitespace and newlines in the output.

When these extra characters were present, the YAML serializer switched to JSON encoding mode to preserve the literal whitespace, resulting in the unreadable escaped format.

Solution

Changed the conditional block from:

{{ if .Values.apisix.trustedAddresses }}
trusted_addresses:
{{- toYaml .Values.apisix.trustedAddresses | nindent 8 }}
{{ end }}

To:

{{- if .Values.apisix.trustedAddresses }}
trusted_addresses:
{{- toYaml .Values.apisix.trustedAddresses | nindent 8 }}
{{- end }}

The {{- syntax tells Helm to trim leading whitespace, preventing extra newlines from being added to the rendered output. This keeps the YAML formatting consistent with the rest of the template.

Impact

  • ✅ ConfigMap output is now human-readable when using kustomize build
  • ✅ Easier to debug and review configuration changes in CI/CD pipelines
  • ✅ No functional changes - the deployed ConfigMap works identically
  • ✅ Consistent with Helm best practices for whitespace control

Testing

# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
helmCharts:
- name: apisix
  repo: https://apache.github.io/apisix-helm-chart
  version: 2.12.4

Verified that kustomize build --enable-helm . now produces properly formatted YAML output with clean line breaks instead of JSON-encoded strings.

@vichaos
Copy link
Author

vichaos commented Dec 3, 2025

Screenshot 2568-12-03 at 15 46 28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant