KohlsTechnology/git2consul-go

Running git2consul updates kv to one before most recent commit

Closed this issue · 0 comments

What version of git2consul-go are you using?

$ git2consul -version
 v0.1.2-dev

Does this issue reproduce with the latest release?
Yes

What operating system and processor architecture are you using (uname -a)?

uname -a Output
$ uname -a
Linux mdl-sres0001a.surescripts-dev.qa 3.10.0-1160.24.1.el7.x86_64 #1 SMP Thu Mar 25 21:21:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

What did you do?

We run git2consul on commit from jenkins

git2consul --config config.json -debug -once

Using a configuration like:

{
    "repos": [{
        "name": "dev",
        "url": "https://bitbucket/scm/ops/consul_kv.git",
        "credentials": {
            "username": "user",
            "password": "password"
        },
        "source_root": "/dev/dc1/",
        "skip_branch_name": true,
        "skip_repo_name": true,
        "expand_keys": true
    }],
    "consul": {
        "address": "http://localhost:8500",
        "token":"123"
    }
}

What did you expect to see?
We would expect the consul kv to mirror the most recent source control values. Instead on first run, it matches 1 commit older than the most recent. If we look at the os.tempdir() contents the values match the most recent commit. And if we immediately run the command again, the consul kv values are updated to match the most recent commit. Lastly, if we delete the os.tempdir() before every run the consul kv values match the most recent commit. It feels like there's a race condition in the git checkout and the push to the consul kv where the checkout hasn't finished before the push to the kv is started

What did you see instead?
The first run of git2-consul doesn't push out the most recent commit. The second run pushes out the most recent commit. Below are the debug logs from one such "first" run.

        "\u001b[34m  INFO\u001b[0m[0000] Starting git2consul version: v0.1.2-dev \u001b[34mcaller\u001b[0m=main",
        "\u001b[34m  INFO\u001b[0m[0000] Setting configuration with sane defaults \u001b[34mcaller\u001b[0m=config",
        "\u001b[37m DEBUG\u001b[0m[0000] Using configuration: {\"local_store\":\"/tmp\",\"webhook\":
        "\u001b[34m  INFO\u001b[0m[0000] Loaded repository devint  \u001b[34mcaller\u001b[0m=repository",
        "\u001b[34m  INFO\u001b[0m[0000] KV GET ref: devint/master \u001b[34mcaller\u001b[0m=consul",
        "\u001b[34m  INFO\u001b[0m[0000] Changed: devint/master    \u001b[34mcaller\u001b[0m=watcher",
        "\u001b[34m  INFO\u001b[0m[0000] Stopping watcher...       \u001b[34mcaller\u001b[0m=watcher",
        "\u001b[34m  INFO\u001b[0m[0000] Received finish           \u001b[34mcaller\u001b[0m=watcher",
        "\u001b[34m  INFO\u001b[0m[0001] Watcher received finish   \u001b[34mcaller\u001b[0m=runner",
        "\u001b[34m  INFO\u001b[0m[0001] Terminating git2consul   "

The fact its says "Changed: devint/master" is interesting to me. That implies that git2consul knows there's a newer commit but then it didn't update any values?

Second run

        "\u001b[34m  INFO\u001b[0m[0000] Starting git2consul version: v0.1.2-dev \u001b[34mcaller\u001b[0m=main",
        "\u001b[34m  INFO\u001b[0m[0000] Setting configuration with sane defaults \u001b[34mcaller\u001b[0m=config",
        "\u001b[34m  INFO\u001b[0m[0000] Loaded repository devint  \u001b[34mcaller\u001b[0m=repository",
        "\u001b[34m  INFO\u001b[0m[0000] KV GET ref: devint/master \u001b[34mcaller\u001b[0m=consul",
        "\u001b[37m DEBUG\u001b[0m[0000] Detected modified file: /tmp/devint/dc1/test.yml
\u001b[37mcaller\u001b[0m=consul",
        "\u001b[34m  INFO\u001b[0m[0000] KV DEL devint/refs/heads/master/test
\u001b[34mcaller\u001b[0m=consul",
        "\u001b[37m DEBUG\u001b[0m[0000] KV PUT: devint/master: test/resilience/config \u001b[37mcaller\u001b[0m=consul",
        "\u001b[37m DEBUG\u001b[0m[0000] Transaction with 4 items was sent to the KV store \u001b[37mcaller\u001b[0m=consul",
        "\u001b[34m  INFO\u001b[0m[0000] KV PUT ref: devint/master \u001b[34mcaller\u001b[0m=consul",
        "\u001b[37m DEBUG\u001b[0m[0000] Up to date: devint/master \u001b[37mcaller\u001b[0m=watcher",
        "\u001b[34m  INFO\u001b[0m[0000] Stopping watcher...       \u001b[34mcaller\u001b[0m=watcher",
        "\u001b[34m  INFO\u001b[0m[0000] Received finish           \u001b[34mcaller\u001b[0m=watcher",
        "\u001b[34m  INFO\u001b[0m[0001] Watcher received finish   \u001b[34mcaller\u001b[0m=runner",
        "\u001b[34m  INFO\u001b[0m[0001] Terminating git2consul   "

Identical config.json and command line parameters were used for both runs and there was no change to source control.