2

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

---
Jonas
  • 121,568
  • 97
  • 310
  • 388
doksha
  • 47
  • 1
  • 2
  • 8

3 Answers3

8

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
  • 151
  • 3
  • 6
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 12 '22 at 05:08
  • 3
    Thanks buddy. This issue has been bugging me for a while. – CodeSlave May 25 '22 at 01:10
  • 1
    this was the issue for me , thanks – devcodes Jan 16 '23 at 07:57
7

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....
  • 17,421
  • 2
  • 32
  • 52
  • i tried that already but it deals with the value as a string contains the string: "AWS_REGION" it doesn't deal with it a variable.. – doksha Jun 17 '21 at 07:57
  • do you want to use environment variables in your `yaml` file ? "you said "it doesn't deal with it a variable" can you explain a bit more? – P.... Jun 17 '21 at 13:51
  • Yes, i want to use it as an env variable.. when i wrapper it with "" it was invoked as a string contains "AWS_REGION" while i wanted the AWS_REGION which is eu-central-1..(a..b..c..) and so . – doksha Jun 17 '21 at 21:04
  • in that case you may either use `helm` or you can check out any of the work around mentioned in https://stackoverflow.com/questions/48296082/how-to-set-dynamic-values-with-kubernetes-yaml-file but note that, as per `yaml` grammar using `%` as a starting character is forbidden. which is the point of this answer. – P.... Jun 17 '21 at 21:39
0

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.

IceWreck
  • 117
  • 1
  • 2
  • 10