首页 > 解决方案 > Kubernetes cronjob - git pull else git clone

问题描述

Kubernetes cronjob 可用于使用 git 存储库中的最新数据更新某些卷。

containers:
      - name: hello
        image: alpine/git
        volumeMounts:
        - name: requirements
          mountPath: /workdir
        imagePullPolicy: IfNotPresent
        command:
        - /bin/sh
        - -c
        - cd /workdir/dashboard; git pull http://url..

但它还没有准备好从盒子里开始工作。如果卷为空,我需要先执行 git clone ,然后每次执行 git pull 。

但是由于某种原因,将 bash if 语句作为 cronjob 命令不起作用 - cronjob 只会失败。

if cd /workdir/dashboard; then git pull http://url..; else git clone http://url..; fi

日志是fatal: not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)

有谁知道如何使它工作?

标签: gitkubernetescronyaml

解决方案


如果你想做一个 git pull 并且如果 repo 在本地不存在,你可以使用以下代码片段仅在第一个命令失败时执行第二个命令,即 repo 尚未克隆

git pull || git clone $git-repo-url

推荐阅读