arttor / helmify

Creates Helm chart from Kubernetes yaml
MIT License
1.48k stars 137 forks source link

Names that are too long generate invalid multi-line strings #12

Closed danielxvu closed 1 year ago

danielxvu commented 3 years ago

The following snippet of YAML results in an invalid credentials.yaml file:

apiVersion: v1
kind: Secret
metadata:
  name: spellbook-credentials
type: Opaque
data:
  MQTT_HOST: "Zm9vYmFy"
  MQTT_PORT: "Zm9vYmFy"
  ELASTIC_HOST: "Zm9vYmFy"
  ELASTIC_PORT: "Zm9vYmFy"
  ELASTIC_PROTOCOL: "Zm9vYmFy"
  ELASTIC_PASSWORD: "Zm9vYmFy"
  ELASTIC_FOOBAR_HUNTER123_MEOWTOWN_VERIFY: "Zm9vYmFy"

The resulting output:

apiVersion: v1
kind: Secret
metadata:
  name: {{ include "spellbook.fullname" . }}-credentials
  labels:
  {{- include "spellbook.labels" . | nindent 4 }}
data:
  ELASTIC_FOOBAR_HUNTER123_MEOWTOWN_VERIFY: {{ required "credentials.elasticFoobarHunter123MeowtownVerify
    is required" .Values.credentials.elasticFoobarHunter123MeowtownVerify | b64enc
    | quote }}
  ELASTIC_HOST: {{ required "credentials.elasticHost is required" .Values.credentials.elasticHost
    | b64enc | quote }}
  ELASTIC_PASSWORD: {{ required "credentials.elasticPassword is required" .Values.credentials.elasticPassword
    | b64enc | quote }}
  ELASTIC_PORT: {{ required "credentials.elasticPort is required" .Values.credentials.elasticPort
    | b64enc | quote }}
  ELASTIC_PROTOCOL: {{ required "credentials.elasticProtocol is required" .Values.credentials.elasticProtocol
    | b64enc | quote }}
  MQTT_HOST: {{ required "credentials.mqttHost is required" .Values.credentials.mqttHost
    | b64enc | quote }}
  MQTT_PORT: {{ required "credentials.mqttPort is required" .Values.credentials.mqttPort
    | b64enc | quote }}

Running helm install will error out because of the invalid YAML generated for key names past a certain length:

$ helm install -f ./contrib/k8s/examples/spellbook/values.yaml webrtc-dev-telemetry ./contrib/k8s/charts/spellbook
Error: INSTALLATION FAILED: parse error at (spellbook/templates/credentials.yaml:8): unterminated quoted string

Thanks for your work on this, by the way.

arttor commented 3 years ago

This one is quite tricky to fix. Used YAML encoder sigs.k8s.io/yaml v1.2.0 creates line breaks for all lines longer than 80 symbols. Which is fine, because such quotes in the middle of the string are not expected for YAML value (but ok for a helm template). I will try to find another encoder allowing to disable such line breaks but not sure that it is possible. For instance, go-yaml also not allowing to disable line breaks

yxd-ym commented 2 years ago

I wrote a tool to sanitize templates generated by helmify. It just works for now without handling complicated cases.

https://github.com/yxd-ym/go-template-sanitizer

Just

cat your-template.yaml | go-template-sanitizer
vicentefb commented 2 years ago

@danielxvu is your required error {{ required "credentials.elasticHost is required" .Values.credentials.elasticHost | b64enc | quote }} due to the same error? Or does this error has a different source issue?

danielxvu commented 2 years ago

@vicentefb No. This issue is caused by an overly long key like ELASTIC_FOOBAR_HUNTER123_MEOWTOWN_VERIFY.

gprossliner commented 1 year ago

I'm having the same issue on a secret object. @arttor are you still working on this?

arttor commented 1 year ago

Fixed in 0.3.22 release.

gprossliner commented 1 year ago

Thank you!