error converting YAML to JSON: mapping values are not allowed in this context

4/30/2021

I'm using helm3. My kubernetes deployment get crashed on 43 line of code below.

Error in console: error converting YAML to JSON: mapping values are not allowed in this context

yaml lint says this: (<unknown>): found unexpected ':' while scanning a plain scalar at line 43 column 19

Whats wrong with that line?

wrong one:

- image: {{ printf "%s/%s:%s" .Values.dockerRegistry .Values.dockerImage .Values.version }}



  apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "deploy_name" . }}
  namespace: {{ .Release.Namespace }}
spec:
  replicas: {{ .Values.replicas.min }}
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}
        team: {{ .Values.meta.team }}
        env: {{ .Values.env }}
        version: {{ .Values.version }}
        revision: {{ .Release.Revision | quote }}
        json_logs: "true"
        commit_hash: {{ .Values.commitHash }}
      annotations:
        prometheus.io/port: {{ .Values.ports.application | quote }}
        prometheus.io/path: {{ .Values.prometheus.path | quote }}
        prometheus.io/scrape: {{ .Values.prometheus.scrape | quote }}
        prometheus.io/scheme: {{ .Values.prometheus.scheme | quote }}
        host/url: {{ .Values.url | quote }}
        host.net/owner: {{ .Values.meta.owner | quote }}
        host.net/system: {{ .Values.meta.team | quote }}
        sidecar.istio.io/rewriteAppHTTPProbers: "true"
    spec:
      imagePullSecrets:
      - name: gitlab
      hostAliases:
      - ip: 0.0.0.0
        hostnames:
        - host
        - host
      - ip: 0.0.0.0
        hostnames:
        - host
      containers:
      - image: {{ printf "%s/%s:%s" .Values.dockerRegistry .Values.dockerImage .Values.version }}
        imagePullPolicy: Always
        name: website
        ports:
        - containerPort: {{  .Values.ports.application }}
        envFrom:
        - configMapRef:
            name: {{ template "config_map_name" . }}
        - secretRef:
            name: {{ template "secret_name" . }}
        resources:
          limits:
            cpu: 2
            memory: 4Gi
          requests:
            cpu: 350m
            memory: 2Gi
        livenessProbe:
          httpGet:
            path: /healthz
            port: {{ .Values.ports.application }}
          initialDelaySeconds: 20
          periodSeconds: 3
          failureThreshold: 10
        readinessProbe:
          httpGet:
            path: /readyz
            port: {{ .Values.ports.application }}
          initialDelaySeconds: 20
          periodSeconds: 3
-- jediinspace
kubernetes
kubernetes-helm

1 Answer

4/30/2021

so my solution is:

- image: '{{.Values.dockerRegistry}}/{{.Values.dockerImage}}:{{.Values.version}}'

The problem was about printf function and colon symbol within

"%s/%s:%s"
-- jediinspace
Source: StackOverflow