Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helm sometimes renders unnecessary additional yaml document containing only a comment when templating #12996

Closed
wimnat opened this issue May 1, 2024 · 2 comments

Comments

@wimnat
Copy link

wimnat commented May 1, 2024

Output of helm version: version.BuildInfo{Version:"v3.14.3", GitCommit:"v3.14.3", GitTreeState:"", GoVersion:"go1.21.7"}

Output of kubectl version: N/A

Cloud Provider/Platform (AKS, GKE, Minikube etc.): N/A

Context

Recently when trying to install Envoy Gateway via Jsonnet I hit an obscure problem using std.prune. The reason I had been trying to use std.prune was to remove empty objects from the Envoy Gateway install.yaml file. This file is created via helm template here.

When the install.yaml file is rendered, it ends up with yaml documents that contain only the "Source: " comment before being followed by another document containing the actual manifest. Example:

Actual output:

---
# Source: gateway-helm/crds/generated/gateway.envoyproxy.io_securitypolicies.yaml
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
    controller-gen.kubebuilder.io/version: v0.14.0
  name: securitypolicies.gateway.envoyproxy.io

Expected output:

---
# Source: gateway-helm/crds/generated/gateway.envoyproxy.io_securitypolicies.yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
    controller-gen.kubebuilder.io/version: v0.14.0
  name: securitypolicies.gateway.envoyproxy.io

The original issue I raised with Envoy Gateway is here.

This happens because helm template doesn't take in to account how a manifest begins. If it doesn't start with the --- then it adds it in along with the comment and all is well. However, if it does start with --- then helm template will insert a document that has a comment only and then the manifest will be added after that and because the manifest starts with ---, it is added as a separate document.

The offending line appears to be https://github.com/helm/helm/blob/main/cmd/helm/template.go#L116

My suggestion is that helm template should check for the yaml start document line ---\n prior to the comment addition and remove it if it exists so that the comment will always appear in the same document as the manifest it is rendering.

I'm happy to work on the issue but just want some feedback on my proposed solution.

@banjoh
Copy link

banjoh commented May 1, 2024

@wimnat looking at https://github.com/envoyproxy/gateway/releases/download/v1.0.1/install.yaml, it seems to contain multiple documents inside one YAML file i.e parts split with ---\n. Some of the documents contain comments starting with # Source: ...

Here is an output after running helm template

#
# Gateway API Experimental channel install
#
---
# Source: foo/templates/install.yaml
# Source: gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml
---
# Source: foo/templates/install.yaml
# Source: gateway-helm/crds/generated/gateway.envoyproxy.io_clienttrafficpolicies.yaml
---
# Source: foo/templates/install.yaml
# Source: gateway-helm/crds/generated/gateway.envoyproxy.io_envoypatchpolicies.yaml
---
# Source: foo/templates/install.yaml
# Source: gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml
---
# Source: foo/templates/install.yaml
# Source: gateway-helm/crds/generated/gateway.envoyproxy.io_securitypolicies.yaml
---
# Source: foo/templates/install.yaml
# Source: gateway-helm/templates/certgen-rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: eg-gateway-helm-certgen
  namespace: 'envoy-gateway-system'
  labels:
    helm.sh/chart: gateway-helm-v0.0.0-latest

My suggestion is that helm template should check for the yaml start document line ---\n prior to the comment addition and remove it if it exists so that the comment will always appear in the same document as the manifest it is rendering.

I'm not sure I follow your suggestion here. Specifically, what do you mean by will always appear in the same document as the manifest? The YAML file in question contains multiple documents which helm renders as expected.

@gjenkins8
Copy link
Contributor

closing as dup: #12953

(please comment if I'm mistaken)

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

No branches or pull requests

3 participants