Olgun Kaya
Olgun Kaya

Reputation: 2589

Unable to send single line command via Helm

I am trying to set up a CronJob using helm. My job template part is as below

jobTemplate:
    metadata:
      creationTimestamp: null
    spec:
      backoffLimit: 3
      template:
        metadata:
          creationTimestamp: null
        spec:
          containers:
            - args:
                - >
                  POD_LIST=($(kubectl get pod
                  --field-selector=status.phase=Succeeded -n ex-namespace -l
                  tekton.dev/pipeline |  awk '$5 ~
                  /(^[6-9][0-9]*|^[1-5][0-9]+)d.*/ {print $1}')); for podname in
                  $POD_LIST; do;
                    echo "deleting pod $podname";
                    kubectl delete pod -n ex-namespace $podname;
                  done;
              command:
                - /bin/sh
                - '-c'
              image: > kubctlImage
              imagePullPolicy: IfNotPresent
              name: cleanup-completed-pods
              resources: {}
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Never
          schedulerName: default-scheduler
          securityContext: {}
          serviceAccount: ral-tekton
          serviceAccountName: ral-tekton
          terminationGracePeriodSeconds: 30
  schedule: 0 0 * * *
  startingDeadlineSeconds: 200
  successfulJobsHistoryLimit: 3

When this job triggers, I am getting below error in the pod logs.

"/bin/sh: 1: Syntax error: "(" unexpected"

Obviously this is a shell script error but not sure what I am missing here ?

Can someone help me to find the shell error here ?

p.s : I copied the command, converted it to single line and tried on my mac's /bin/sh shell and seems to be working.

Upvotes: 0

Views: 86

Answers (1)

SYN
SYN

Reputation: 5041

might work, assuming your kubectl image has gawk

       - args:
            - >
              for podname in $(kubectl get pod
                --field-selector=status.phase=Succeeded -n ex-namespace -l
                tekton.dev/pipeline | awk '$5 ~
                /(^[6-9][0-9]*|^[1-5][0-9]+)d.*/ {print $1}'); do
                echo "deleting pod $podname";
                kubectl delete pod -n ex-namespace $podname;
              done;

Upvotes: 1

Related Questions