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

6/16/2021

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

---
-- doksha
google-kubernetes-engine
kubernetes

2 Answers

6/16/2021

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: [] {} > | * & ! % # ` @ ,.

-- P....
Source: StackOverflow

4/12/2022

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.

-- Sanim16
Source: StackOverflow