doksha
doksha

Reputation: 97

k8s: error converting YAML to JSON: yaml: line 33: found character that cannot start any token

hope you are doing fine,

i got that error :error:

error converting YAML to JSON: yaml: line 33: found character that cannot start any token

while trying to deploy this cronjob on my k8s cluster, can you please check and let me know if you have any clues about the reason of having this error ?

the file is as follows:

---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: resourcecleanup
spec:
  # 10:00 UTC == 1200 CET
  schedule: '0 10 * * 1-5'
  jobTemplate:
    spec:
      template:
        metadata:
          annotations:
            iam.amazonaws.com/role: arn:aws:iam::%%AWS_ACCOUNT_NUMBER%%:role/k8s/pod/id_ResourceCleanup
        spec:
          containers:
          - name: resourcecleanup
            image: cloudcustodian/c7n
            args:
                - run
                - -v
                - -s
                - /tmp
                - -f
                - /tmp/.cache/cloud-custodian.cache
                - /home/custodian/delete-unused-ebs-volumes-policies.yaml
            volumeMounts:
                - name: cleanup-policies
                  mountPath: /home/custodian/delete-unused-ebs-volumes-policies.yaml
                  subPath: delete-unused-ebs-volumes-policies.yaml
            env:
                - name: AWS_DEFAULT_REGION
                  value: %%AWS_REGION%%
          volumes:
                - name: cleanup-policies
                  configMap:
                   name: cleanup-policies
          restartPolicy: Never

---

Upvotes: 6

Views: 26465

Answers (4)

Sysanin
Sysanin

Reputation: 1803

Try to do a helm lint against the charts:

For example, error:

Error: YAML parse error on server-infra/templates/service-prod.yaml: 
error converting YAML to JSON: yaml: line 11: 
found character that cannot start any token

Output of lint helm lint myrepo/charts/server-infra/ command:

[WARNING] templates/service-prod.yaml: 
object name does not conform to Kubernetes naming requirements: 
"server-infra-service-prod-%!s(<nil>)": metadata.name:
Invalid value: "server-infra-service-prod-%!s(<nil>)": 
a DNS-1035 label must consist of lower case alphanumeric characters or '-',
start with an alphabetic character, and end with an alphanumeric character 
(e.g. 'my-name',  or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')

Which shows that actual value is missing (<nil>) and must be passed during execution of helm command or chart should be adjusted accordingly.

Upd: Another helpful command for such cases might be helm template It is simply compile your charts and values locally without sending to kubernetes API server and prints charts with values to the output so you can clearly see all charts and lines with unsupported characters, like a variable was missing or has wrong value. The command operates as install/update in most cases and support same options so you just need to replace helm update to helm template --debug to see what is going on with your charts and values.

Upvotes: 0

IceWreck
IceWreck

Reputation: 127

If somebody else came here googling this error, then quoting both the value and the template helped me.

In values.yaml

schedule: "@daily"

And in your helm template:

schedule: "{{ .Values.cronjob.schedule }}"

It's easier to forget the last one but since the variable's value can include @, *, etc we have to quote the variable as well.

Upvotes: 0

Sanim16
Sanim16

Reputation: 329

The problem could be from your indentation method, Try using spaces and not tabs for your indentation. Use 2 spaces for each indentation. Hope this helps.

Upvotes: 12

P....
P....

Reputation: 18411

change:

              value: %%AWS_REGION%%

to:

              value: "%%AWS_REGION%%"

Strings containing any of the following characters must be quoted.

:, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, `

Could not find in kubernetes docs, but from ansible yaml syntax:

In addition to ' and " there are a number of characters that are special (or reserved) and cannot be used as the first character of an unquoted scalar: [] {} > | * & ! % # ` @ ,.

Upvotes: 8

Related Questions