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

Incorrect behaviour when working with helm templates #407

Closed
1 of 4 tasks
Jasstkn opened this issue Dec 11, 2020 · 10 comments
Closed
1 of 4 tasks

Incorrect behaviour when working with helm templates #407

Jasstkn opened this issue Dec 11, 2020 · 10 comments

Comments

@Jasstkn
Copy link

Jasstkn commented Dec 11, 2020

Describe the bug

When work with helm templates, there are a lot of wrong errors.

Expected Behavior

Should work correctly as it was before

Current Behavior

Mark a lot of lines as containing error

Steps to Reproduce

  1. Open any helm template file
  2. See a lot of errors which are wrong

Environment

  • Windows
  • Mac
  • Linux
  • other (please specify)

Screenshot 2020-12-11 at 19 53 02

@JPinkney
Copy link
Contributor

Do you have any other kubernetes related extensions installed? Also, what file type is your file associated with? (You can see that this file is associated with the YAML filetype in the bottom right.

2020-12-11-122052_960x1010_scrot

@Jasstkn
Copy link
Author

Jasstkn commented Dec 11, 2020

@JPinkney, yeah, I have several extensions but when I disable only this one, no red lines appeared
Screenshot 2020-12-12 at 00 45 37

@JPinkney
Copy link
Contributor

Are you able to post more of your yaml file? Do you have another apiVersion at the root of the document?

@sagor999
Copy link

I have same problem.
Here is an example yaml file:

{{- if .Values.hooks.enabled -}}
apiVersion: batch/v1
 kind: Job
metadata:
  name: {{ template "sentry.fullname" . }}-db-init
  labels:
    app: sentry
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
  annotations:
    # This is what defines this resource as a hook. Without this line, the
    # job is considered part of the release.
    "helm.sh/hook": "post-install,post-upgrade"
    "helm.sh/hook-delete-policy": "{{ if .Values.hooks.removeOnSuccess }}hook-succeeded,{{ end }}before-hook-creation"
    "helm.sh/hook-weight": "6"
spec:
  template:
    metadata:
      name: {{ template "sentry.fullname" . }}-db-init
      annotations:
        checksum/configmap.yaml: {{ include (print $.Template.BasePath "/configmap-sentry.yaml") . | sha256sum }}
        {{- if .Values.sentry.worker.annotations }}
{{ toYaml .Values.sentry.worker.annotations | indent 8 }}
        {{- end }}
      labels:
        app: sentry
        release: "{{ .Release.Name }}"
        {{- if .Values.sentry.worker.podLabels }}
{{ toYaml .Values.sentry.worker.podLabels | indent 8 }}
        {{- end }}
    spec:
      restartPolicy: Never
      {{- if .Values.images.sentry.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.images.sentry.imagePullSecrets | indent 8 }}
      {{- end }}
      containers:
      - name: db-init-job
        image: "{{ template "sentry.image" . }}"
        imagePullPolicy: {{ default "IfNotPresent" .Values.images.sentry.pullPolicy }}
        command: ["sentry","upgrade","--noinput"]
        env:
        {{- if .Values.postgresql.enabled }}
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ default (include "sentry.postgresql.fullname" .) .Values.postgresql.existingSecret }}
              key: {{ default "postgresql-password" .Values.postgresql.existingSecretKey }}
        {{- end }}
        {{- if .Values.hooks.dbInit.env }}
{{ toYaml .Values.hooks.dbInit.env | indent 8 }}
        {{- end }}
        volumeMounts:
        - mountPath: /etc/sentry
          name: config
          readOnly: true
        resources:
{{ toYaml .Values.hooks.dbInit.resources | indent 10 }}
      volumes:
      - name: config
        configMap:
          name: {{ template "sentry.fullname" . }}-sentry
{{- end -}}

And this is how it looks with YAML extension currently:
Screenshot from 2020-12-18 07-12-57

It gets tripped on the first {{ and after that the rest of the file is messed up.

@sagor999
Copy link

Found workaround to this issue.
I installed Kubernetes extension to vscode, and it automatically marked helm files as helm-template type, and it is no longer being attempted to be validated by YAML extension. So problem went away. :)

@JPinkney
Copy link
Contributor

If you are using helm you should definitely install vscode-kubernetes! It interfaces with this extension in order to provide its support. The reason why your helm yaml doesn't validate correctly is because something like:

{{- if .Values.hooks.enabled -}}
apiVersion: batch/v1
 kind: Job
metadata:
  name: {{ template "sentry.fullname" . }}-db-init
{{- end -}}

isn't valid in yaml 1.2. It's only valid in helms custom yaml

@jkryanchou
Copy link

+1 same issues with the kubernets vscode extension installed, Is there any solutions we could refer to?

@jmuleiro
Copy link

I've installed VS Code's Kubernetes extension and I'm having this issue, the workaround @sagor999 mentioned works. However, this prevents autocompletion, snippets, etc. from working. Would be nice for both extensions to work together.

@tobimax
Copy link

tobimax commented May 10, 2022

I have to put the YAML files under a subdirectory called templates and they detect as helm charts properly. It's that by design?

image

vs.

image

Chart.yaml always detects as helm regardless of where it is put.

@Jasstkn
Copy link
Author

Jasstkn commented Aug 11, 2022

Works for me now.

@Jasstkn Jasstkn closed this as completed Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants