Pass date command as parameter to kubernetes cronjob

你说的曾经没有我的故事 提交于 2021-02-08 10:40:32

问题


I want to execute data migration through Kubernetes cronjob using Luigi pipeline. My luigi task receives --start parameter which I want to pass through cronjob command.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: migration
spec:
  schedule: "0 0 */1 * *"
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: spark
          containers:
          - name: migratecronjob
            image: latest-image
            imagePullPolicy: Always
            env:
              - name: TAG
                value: latest-image
              - name: MIGRATION_TAG
                value: migration-v05
            command:
              -  "luigi"
              - "--module" 
              - "module.task" 
              - "Migrate10Days"
              - "--start"
              - $(date +%Y-%m-%dT%H)
              - "--workers"
              - "10"
          restartPolicy: OnFailure

The cronjob cannot recognize the $(date +%Y-%m-%dT%H) as a bash script and pass this command as string to the luigi task.


回答1:


I am not sure what are you going to archive, but this should work:

      - command:
        - sh
        - -c
        - 'exec luigi --module module.task Migrate10Days --start $(date +%Y-%m-%dT%H) --workers --workers'


来源:https://stackoverflow.com/questions/57364453/pass-date-command-as-parameter-to-kubernetes-cronjob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!