Jx: Empty Helm template should not append JX metadata

Created on 11 Apr 2019  路  5Comments  路  Source: jenkins-x/jx

Summary

When installing helm chart with values that make a template empty, JX still add his metadata and make the install fail.

Related to: #2504

Steps to reproduce the behavior

Using kafka helm chart with default values, and run jx step helm apply it fails with something like:

error: unable to decode "/tmp/helm-template-workdir-873726160/jx/output/env/charts/jenkinsx-quickstart-nuxeo-poc/charts/kafka/templates/servicemonitors.yaml": Object 'Kind' is missing in '{"metadata":{"annotations":{"jenkins.io/chart":"env"},"labels":{"jenkins.io/chart-release":"jx","jenkins.io/version":"25"}}}'': exit status 1

File content:

cat /var/XXXX/jx/output/kafka/templates/part0-servicemonitors.yaml
metadata:
  labels:
    jenkins.io/chart-release: jx
    jenkins.io/version: 0.14.2
  annotations:
    jenkins.io/chart-app-version: 5.0.1
    jenkins.io/chart: kafka

Expected behavior

JX should not append anything to an empty template, otherwise install fails.

Jx version

The output of jx version is:

jx version
NAME               VERSION
jx                 1.3.1101
jenkins x platform 0.0.3690
Kubernetes cluster v1.12.6-gke.7
kubectl            v1.13.4
helm client        Client: v2.13.0+g79d0794
git                git version 2.21.0
Operating System   Mac OS X 10.14.3 build 18D109
arehelm kinbug prioritimportant-longterm

Most helpful comment

the platform release with this fix is now released as 2.0.106

All 5 comments

yea just got hit by this too - the incubator/kafka chart does this if you require it as a dependency and operator.enabled is false

here's a non-generic workaround

    stage('Update Environment') {
      when {
        branch 'master'
      }
      steps {
        container('maven') {
          dir('env') {
            dir('./charts') {
              sh 'for file in *.tgz; do tar -zxf "$file" && rm "$file"; done'
              sh 'rm kafka/templates/servicemonitors.yaml'
            }
            sh 'jx step helm apply'
          }
        }
      }
    }

We are having the same issue with the following error:

error: unable to decode "/tmp/helm-template-workdir-813127549/jx/output/env/charts/activiti-cloud-platform/charts/infrastructure/charts/activiti-keycloak/templates/part0-realm-secret.yaml": Object 'Kind' is missing in '{"metadata":{"annotations":{"jenkins.io/chart":"env","jenkins.io/chart-app-version":"7.0.0.GA"},"labels":{"jenkins.io/chart-release":"jx","jenkins.io/version":"12"}}}''

This is the resource template that causes the error: https://github.com/Activiti/activiti-cloud-charts/blob/master/activiti-keycloak/templates/realm-secret.yaml

{{- if .Values.keycloak.enabled }}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{ .Release.Name }}-realm-secret
  labels:
    app: {{ .Chart.Name }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
type: Opaque
data:
  "activiti-realm.json": {{ tpl (.Files.Get "files/activiti-realm.json") . | b64enc | quote }}
{{- end }}

This is the output of helm template . command:

apiVersion: v1
kind: Secret
metadata:
  name: release-name-realm-secret
  labels:
    app: activiti-keycloak
    chart: activiti-keycloak-1.1.6
    release: release-name
    heritage: Tiller
type: Opaque
data:
  "activiti-realm.json": "xxxxx"

This is the output produced by jx step helm apply command:

metadata:
  labels:
    jenkins.io/chart-release: jx
    jenkins.io/version: 0.0.1
  annotations:
    jenkins.io/chart-app-version: 7.0.0.GA
    jenkins.io/chart: env

Basically, having any empty template resource generated with --- or # makes jx step helm apply fail. Here is another example of configmap.yaml that causes the error:

# This comment breaks jx step helm apply if .Values.configMap is false
{{- if .Values.configMap }}
apiVersion: v1
kind: ConfigMap
metadata:
{{- if .Values.service.name }}
  name: {{ .Values.service.name }}
{{- else }}
  name: {{ template "fullname" . }}
{{- end }}
data:
  application.properties: |-
{{- range $key, $value := .Values.configMap }}
    {{ $key }}={{ $value }}
{{- end }}
{{- end }}

the platform release with this fix is now released as 2.0.106

Was this page helpful?
0 / 5 - 0 ratings