canonical / cos-configuration-k8s-operator

This charmed operator for Kubernetes enables you to provide configurations to various components of the Canonical Observability Stack (COS) bundle.
https://charmhub.io/cos-configuration-k8s
Apache License 2.0
4 stars 5 forks source link

Sync fails behind a proxy #71

Closed przemeklal closed 8 months ago

przemeklal commented 11 months ago

Bug Description

Git sync fails behind a proxy regardless of the protocol used, SSH and HTTP both fail.

To Reproduce

juju run-action cos-config/0 sync-now --wait
unit-cos-config-0:
  UnitId: cos-config/0
  id: "6"
  log:
  - 2023-08-18 12:06:54 +0000 UTC Calling git-sync with --one-time...
  - 2023-08-18 12:10:29 +0000 UTC I0818 12:06:54.309038     306 main.go:473] "level"=0
    "msg"="starting up" "pid"=306 "args"=["/git-sync","--repo","https://<username>:<token>@git.launchpad.net/~<redacted>/+git/cos-config","--branch","<branch>","--r
ev","HEAD","--depth","1","--root","/git","--dest","repo","--one-time"]
  - 2023-08-18 12:10:29 +0000 UTC I0818 12:06:54.309175     306 main.go:923] "level"=0
    "msg"="cloning repo" "origin"="https://<username>:<token>@git.launchpad.net/~<redacted>/+git/cos-config"
    "path"="/git"
  - 2023-08-18 12:10:29 +0000 UTC I0818 12:06:54.311270     306 main.go:929] "level"=0
    "msg"="git root exists and is not empty (previous crash?), cleaning up" "path"="/git"
  - '2023-08-18 12:10:30 +0000 UTC E0818 12:10:29.295155     306 main.go:525] "msg"="too
    many failures, aborting" "error"="Run(git clone -v --no-checkout -b <branch>
    --depth 1 https://<username>:<token>@git.launchpad.net/~<redacted>/+git/cos-config
    /git): context deadline exceeded: { stdout: "", stderr: "Cloning into ''/git''...\nfatal:
    unable to access ''https://git.launchpad.net/~<redacted>/+git/cos-config/'':
    Failed to connect to git.launchpad.net port 443: Connection timed out\n" }" "failCount"=0'
  message: 'Sync error: Exited with code 1.'
  results: {}
  status: failed
  timing:
    completed: 2023-08-18 12:10:30 +0000 UTC
    enqueued: 2023-08-18 12:03:02 +0000 UTC
    started: 2023-08-18 12:06:54 +0000 UTC

Repository is accessible through the proxy from the cos-config git-sync container:

$ juju ssh --container git-sync cos-config/0

# export https_proxy=http://<proxy_url>:8000
# git clone -v --no-checkout -b <branch> --depth 1 https://<username>:<token>@git.launchpad.net/~<redacted>/+git/cos-config
Cloning into 'cos-config'...
POST git-upload-pack (415 bytes)
POST git-upload-pack (157 bytes)
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), 16.93 KiB | 298.00 KiB/s, done.

Without the proxy env var it throws the same error as the sync-now action:

$ juju ssh --container git-sync cos-config/0

# unset https_proxy
# git clone -v --no-checkout -b <branch> --depth 1 https://<username>:<token>@git.launchpad.net/~<redacted>/+git/cos-config
Cloning into 'cos-config'...
fatal: unable to access 'https://git.launchpad.net/~<redacted>/+git/cos-config/': Failed to connect to git.launchpad.net port 443: Connection timed out

Environment

cos-configuration-k8s-operator rev 38 running behind proxya

Relevant log output

juju run-action cos-config/0 sync-now --wait
unit-cos-config-0:
  UnitId: cos-config/0
  id: "6"
  log:
  - 2023-08-18 12:06:54 +0000 UTC Calling git-sync with --one-time...
  - 2023-08-18 12:10:29 +0000 UTC I0818 12:06:54.309038     306 main.go:473] "level"=0
    "msg"="starting up" "pid"=306 "args"=["/git-sync","--repo","https://<username>:<token>@git.launchpad.net/~<redacted>/+git/cos-config","--branch","<branch>","--r
ev","HEAD","--depth","1","--root","/git","--dest","repo","--one-time"]
  - 2023-08-18 12:10:29 +0000 UTC I0818 12:06:54.309175     306 main.go:923] "level"=0
    "msg"="cloning repo" "origin"="https://<username>:<token>@git.launchpad.net/~<redacted>/+git/cos-config"
    "path"="/git"
  - 2023-08-18 12:10:29 +0000 UTC I0818 12:06:54.311270     306 main.go:929] "level"=0
    "msg"="git root exists and is not empty (previous crash?), cleaning up" "path"="/git"
  - '2023-08-18 12:10:30 +0000 UTC E0818 12:10:29.295155     306 main.go:525] "msg"="too
    many failures, aborting" "error"="Run(git clone -v --no-checkout -b <branch>
    --depth 1 https://<username>:<token>@git.launchpad.net/~<redacted>/+git/cos-config
    /git): context deadline exceeded: { stdout: "", stderr: "Cloning into ''/git''...\nfatal:
    unable to access ''https://git.launchpad.net/~<redacted>/+git/cos-config/'':
    Failed to connect to git.launchpad.net port 443: Connection timed out\n" }" "failCount"=0'
  message: 'Sync error: Exited with code 1.'
  results: {}
  status: failed
  timing:
    completed: 2023-08-18 12:10:30 +0000 UTC
    enqueued: 2023-08-18 12:03:02 +0000 UTC
    started: 2023-08-18 12:06:54 +0000 UTC

Additional context

Fixing it for ssh protocol might be tricky.

Abuelodelanada commented 10 months ago

Example implementation: https://github.com/canonical/grafana-k8s-operator/pull/242/files#diff-b9ed39bbc9c0387bd3e07da31d13373745534a1cd723d3e292c73496b12e307c