pulumi / pulumi-kubernetes

A Pulumi resource provider for Kubernetes to manage API resources and workloads in running clusters
https://www.pulumi.com/docs/reference/clouds/kubernetes/
Apache License 2.0
415 stars 115 forks source link

HelmRelease causes a line break on long values #3062

Open ChristianRaoulis opened 5 months ago

ChristianRaoulis commented 5 months ago

What happened?

I'm trying to add some prometheus rules to my rabbitmq bitnami helm chart and pulumi seems to add a \n on a point where it causes an unterminated quoted string error on pulumi up

Example

const rabbitMQ = new HelmRelease("rabbitmq", {
   chart:          "rabbitmq",
   version:        "14.1.2",
   repositoryOpts: {
      repo: "https://charts.bitnami.com/bitnami",
   },
   values:         {
      metrics: {
         enabled:        true,
         prometheusRule: {
            enabled:   true,
            rules:     [
               {
                  alert:       "RabbitmqInstancesDifferentVersions",
                  expr:        'count(count(rabbitmq_build_info) by (rabbitmq_version)) > 1',
                  for:         '60m',
                  labels:      {
                     severity: "warning",
                  },
                  annotations: {
                     summary:     'RabbitMQ instances running different versions (instance {{ "{{ $labels.instance }}" }})', // <-- this get's converted to "RabbitMQ instances running different versions (instance {{ \"{{ $labels.instance\n      }}\" }})"
                     description: 'Running different version of RabbitMQ in the same cluster, can lead to failure.\n   VALUE = {{ "{{ $value }}" }}\n LABELS = {{ "{{ $labels }}" }}',
                  },
               },
            ],
         },
      },
   },
});

Output of pulumi about

CLI          
Version      3.107.0
Go Version   go1.22.0
Go Compiler  gc

Plugins
NAME          VERSION
command       0.11.1
keycloak      5.3.2
kubernetes    4.13.1
mongodbatlas  3.16.0
nodejs        unknown
postgresql    3.11.1
random        4.16.2

Host     
OS       Microsoft Windows 11 Enterprise
Version  10.0.22631 Build 22631
Arch     x86_64

This project is written in nodejs: executable='C:\Users\A92615470\AppData\Local\pnpm\node.exe' version='v20.14.0'

Additional context

// In my arg 
RabbitMQ instances running different versions (instance {{ "{{ $labels.instance }}" }})
// In values.yaml
RabbitMQ instances running different versions (instance {{ "{{ $labels.instance\n      }}" }})

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

rquitales commented 5 months ago

Hi @ChristianRaoulis it appears that this is related to an upstream bug regarding line splitting. Please see https://github.com/helm/helm/issues/7704 for additional information.

Note that I am also able to reproduce this issue using Helm CLI (v3.15.2 - latest) and the following values.yaml file:

# helm install bitnami/rabbitmq --values ./values.yml --generate-name
metrics:
  enabled: true
  prometheusRule:
    enabled: true
    rules:
      - alert: RabbitmqInstancesDifferentVersions
        expr: count(count(rabbitmq_build_info) by (rabbitmq_version)) > 1
        for: 60m
        labels:
          severity: warning
        annotations:
          summary: RabbitMQ instances running different versions (instance {{ "{{ $labels.instance }}" }})
          description: |-
            Running different version of RabbitMQ in the same cluster, can lead to failure.
            VALUE = {{ "{{ $value }}" }}
            LABELS = {{ "{{ $labels }}" }}

As a workaround for now, you could employ the suggestion in https://github.com/helm/helm/issues/7704#issuecomment-747561507 by declaring your custom values in a yaml file and referencing it using the valueYamlFiles field.

Example:

# index.ts
const chart = new k8s.helm.v3.Release(
  "rabbitmq",
  {
    chart: "rabbitmq",
    version: "14.1.2",
    repositoryOpts: {
      repo: "https://charts.bitnami.com/bitnami",
    },
    valueYamlFiles: [new pulumi.asset.FileAsset("./values.yml")],
  },
  { provider }
);
#values.yml
metrics:
  enabled: true
  prometheusRule:
    enabled: true
    rules:
      - alert: RabbitmqInstancesDifferentVersions
        expr: |
          count(count(rabbitmq_build_info) by (rabbitmq_version)) > 1
        for: 60m
        labels:
          severity: warning
        annotations:
          summary: |
            RabbitMQ instances running different versions (instance {{ "{{ $labels.instance }}" }})
          description: |
            Running different version of RabbitMQ in the same cluster, can lead to failure.
            VALUE = {{ "{{ $value }}" }}
            LABELS = {{ "{{ $labels }}" }}

Alternatively, you could force a string literal by adding a \n to the end of strings >80 characters.

const rabbitMQ = new HelmRelease("rabbitmq", {
   chart:          "rabbitmq",
   version:        "14.1.2",
   repositoryOpts: {
      repo: "https://charts.bitnami.com/bitnami",
   },
   values:         {
      metrics: {
         enabled:        true,
         prometheusRule: {
            enabled:   true,
            rules:     [
               {
                  alert:       "RabbitmqInstancesDifferentVersions",
                  expr:        'count(count(rabbitmq_build_info) by (rabbitmq_version)) > 1',
                  for:         '60m',
                  labels:      {
                     severity: "warning",
                  },
                  annotations: {
                     summary:     'RabbitMQ instances running different versions (instance {{ "{{ $labels.instance }}" }})\n',
                     description: 'Running different version of RabbitMQ in the same cluster, can lead to failure.\n   VALUE = {{ "{{ $value }}" }}\n LABELS = {{ "{{ $labels }}" }}',
                  },
               },
            ],
         },
      },
   },
});

In the meantime, I'll see what strategies we could implement within our provider to avoid this issue.