shell 无法通过Helm发送单行命令

eivgtgni  于 2022-11-16  发布在  Shell
关注(0)|答案(1)|浏览(144)

我正在尝试使用helm设置一个CronJob。我的作业模板部分如下

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

触发此作业时,我在Pod日志中看到以下错误。
“/bin/sh:1:语法错误:“(《意料之外》
显然这是一个shell脚本错误,但不确定我在这里错过了什么?
有人能帮我找到这里的shell错误吗?
p.s:我复制了命令,将其转换为单行,并尝试在我的mac的/bin/sh shell ,似乎是工作.

yh2wf1be

yh2wf1be1#

假设你的kubectl图像有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;

相关问题