1

I am using git-sync as a sidecar in Kubernetes to do git-pull and mount the pulled data to shared volume periodically.

Everything works well except GIT_SYNC_PERIOD. I want git sync every 10min, somehow it always use the default value which is 10ms.

Here is my configuration.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx-helloworld
          image: nginx
          ports:
            - containerPort: 80
          volumeMounts:
            - mountPath: "/usr/share/nginx/html"
              name: www-data
        - name: git-sync
          image: k8s.gcr.io/git-sync:v3.1.3
          volumeMounts:
            - name: www-data
              mountPath: /data
          env:
            - name: GIT_SYNC_REPO
              value: "https://github.com/musaalp/gighub.git" ##repo-path-you-want-to-clone
            - name: GIT_SYNC_BRANCH
              value: "master" ##repo-branch
            - name: GIT_SYNC_ROOT
              value: /data
            - name: GIT_SYNC_DEST
              value: "languages" ##path-where-you-want-to-clone
            - name: GIT_SYNC_PERIOD
              value: "600"
          securityContext:
            runAsUser: 0
      volumes:
        - name: www-data
          emptyDir: {}

I am assuming the value for GIT_SYNC_PERIOD is second.

Musa
  • 15
  • 1
  • 5
  • Just a guess, but your `GIT_SYNC_PERIOD` doesn't have a unit suffix (e.g. `s`), unlike what's shown in the documentation. Try adding one? (or setting it to `10m`, instead) – Hasturkun Aug 22 '22 at 15:30
  • I tried with 10s and 10m neither of them worked:( – Musa Aug 22 '22 at 20:19

1 Answers1

0

You can pass -wait=time to override the default behaviour

      containers:
        - name: git-sync
          image: k8s.gcr.io/git-sync:v3.1.3
          args: ["-wait=20","-v=7"]

and with -v=7 you will be able to see how much time it will wait.

debug logs

I0822 16:22:17.088533      13 main.go:641]  "level"=5 "msg"="running command"  "cmd"="git rev-parse HEAD" "cwd"="/data/hello"
I0822 16:22:17.122642      13 main.go:641]  "level"=5 "msg"="running command"  "cmd"="git ls-remote -q origin refs/heads/master" "cwd"="/data/hello"
I0822 16:22:19.060599      13 main.go:582]  "level"=2 "msg"="git state"  "local"="61be34f64d471d65c26f2d28f1a35b165249a537" "remote"="61be34f64d471d65c26f2d28f1a35b165249a537"
I0822 16:22:19.060811      13 main.go:584]  "level"=1 "msg"="no update required"
I0822 16:22:19.060931      13 main.go:354]  "level"=1 "msg"="next sync"  "wait_time"=20000000000
I0822 16:22:39.079914      13 main.go:641]  "level"=5 "msg"="running command"  "cmd"="git rev-parse HEAD" "cwd"="/data/hello"
I0822 16:22:39.159808      13 main.go:641]  "level"=5 "msg"="running command"  "cmd"="git ls-remote -q origin refs/heads/master" "cwd"="/data/hello"
I0822 16:22:40.839761      13 main.go:582]  "level"=2 "msg"="git state"  "local"="61be34f64d471d65c26f2d28f1a35b165249a537" "remote"="61be34f64d471d65c26f2d28f1a35b165249a537"
I0822 16:22:40.839788      13 main.go:584]  "level"=1 "msg"="no update required"
I0822 16:22:40.839815      13 main.go:354]  "level"=1 "msg"="next sync"  "wait_time"=20000000000

now if you set something like --wait=1000 then

I0822 16:22:53.240181      15 main.go:354]  "level"=1 "msg"="next sync"  "wait_time"=1000000000000

--period <duration>, $GIT_SYNC_PERIOD How long to wait between sync attempts. This must be at least 10ms. This flag obsoletes --wait, but if --wait is specified, it will take precedence. (default: 10s)

Adiii
  • 54,482
  • 7
  • 145
  • 148
  • Thank you @Adiii, your suggestion made it work. Now I am a bit confused. As you mentioned the doc says --wait flag is obsoletes and it encourages us to use GIT_SYNC_PERIOD, in the other hand it didn't work for me. Do you have any idea why GIT_SYNC_PERIOD is not working? – Musa Aug 22 '22 at 20:30
  • You are using o older version, upgrade the version – Adiii Aug 22 '22 at 23:43
  • I have tried with latest version which https://github.com/kubernetes/git-sync/releases/tag/v3.6.0, I also tried other version neither of them worked for me. – Musa Aug 23 '22 at 09:15
  • so then no worry, seems like docker image is not up to date with github. you can use `--wait` flag or create custom build image – Adiii Aug 23 '22 at 09:23
  • i did not find the link to latest image, did you find the latest image? – Adiii Aug 23 '22 at 09:24
  • but anyway it still working under same version and same tag, then it should not be an issue – Adiii Aug 23 '22 at 09:25
  • here is the latest image link k8s.gcr.io/git-sync/git-sync:v3.6.0. – Musa Aug 23 '22 at 09:30