helm / chart-testing

CLI tool for linting and testing Helm charts
Apache License 2.0
1.36k stars 215 forks source link

CT_CONFIG_DIR seems to control dependency downloads #655

Closed dataviruset closed 2 months ago

dataviruset commented 5 months ago

Is this a request for help?: Yes


Is this a BUG REPORT or FEATURE REQUEST? (choose one): Bug report

Version of Helm and Kubernetes:

$ helm version
version.BuildInfo{Version:"v3.14.3", GitCommit:"f03cc04caaa8f6d7c3e67cf918929150cf6f3f12", GitTreeState:"clean", GoVersion:"go1.22.1"}

$ kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.0", GitCommit:"b46a3f887ca979b1a5d14fd39cb1af43e7e5d12d", GitTreeState:"clean", BuildDate:"2022-12-08T19:51:43Z", GoVersion:"go1.19.4", Compiler:"gc", Platform:"darwin/arm64"}
Kustomize Version: v4.5.7
Server Version: version.Info{Major:"1", Minor:"30", GitVersion:"v1.30.0", GitCommit:"7c48c2bd72b9bf5c44d21d7338cc7bea77d0ad2a", GitTreeState:"clean", BuildDate:"2024-05-13T22:02:25Z", GoVersion:"go1.22.2", Compiler:"gc", Platform:"linux/arm64"}
WARNING: version difference between client (1.26) and server (1.30) exceeds the supported minor version skew of +/-1

$ ct version
Version:     3.11.0
Git commit:  a2ecd82b650c223a8d264920fd0bab40de16b915
Date:        2024-04-21
License:     Apache 2.0

What happened: With any value of CT_CONFIG_DIR, when Chart.lock already exists, the following ct install invocations fail because for some reason ct refuses to download dependent charts:

$ CT_CONFIG_DIR=foo ct install --target-branch main
Installing charts...

------------------------------------------------------------------------------------------------------------------------
 Charts to be processed:
------------------------------------------------------------------------------------------------------------------------
 domain-server => (version: "0.1.0", path: "charts/domain-server")
------------------------------------------------------------------------------------------------------------------------

Error: no repository definition for https://charts.bitnami.com/bitnami. Please add the missing repos via 'helm repo add'

------------------------------------------------------------------------------------------------------------------------
No chart changes detected.
------------------------------------------------------------------------------------------------------------------------
Error: failed installing charts: failed building dependencies for chart "domain-server => (version: \"0.1.0\", path: \"charts/domain-server\")": failed waiting for process: exit status 1
failed installing charts: failed building dependencies for chart "domain-server => (version: \"0.1.0\", path: \"charts/domain-server\")": failed waiting for process: exit status 1

$ cat charts/domain-server/Chart.yaml
apiVersion: v2
name: domain-server
description: foo
type: application
version: 0.1.0
appVersion: "0.2"
maintainers:
  - name: dataviruset
dependencies:
  - name: postgresql
    version: 15.4.2
    repository: https://charts.bitnami.com/bitnami
    condition: postgresql.enabled

What you expected to happen: ct install to install the dependent chart and run normally as if CT_CONFIG_DIR wouldn't be set:

$ ct install --target-branch main
Installing charts...

------------------------------------------------------------------------------------------------------------------------
 Charts to be processed:
------------------------------------------------------------------------------------------------------------------------
 domain-server => (version: "0.1.0", path: "charts/domain-server")
------------------------------------------------------------------------------------------------------------------------

"bitnami" has been added to your repositories
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "istio" chart repository
...Successfully got an update from the "bitnami" chart repository
Update Complete. ⎈Happy Helming!⎈
Saving 1 charts
Downloading postgresql from repo https://charts.bitnami.com/bitnami
Deleting outdated charts
Installing chart "domain-server => (version: \"0.1.0\", path: \"charts/domain-server\")"...
Creating namespace "domain-server-xsqj98a8oz"...
[...]
namespace "domain-server-xsqj98a8oz" deleted
Namespace "domain-server-xsqj98a8oz" terminated.

------------------------------------------------------------------------------------------------------------------------
 ✔︎ domain-server => (version: "0.1.0", path: "charts/domain-server")
------------------------------------------------------------------------------------------------------------------------
All charts installed successfully

How to reproduce it (as minimally and precisely as possible): See "What happened" above.

Anything else we need to know: I tried to understand how setting the environment variable could prevent the downloading of dependent charts (from the Bitnami repository in my case) but didn't understand how this code could affect it: https://github.com/helm/chart-testing/blob/65fa127f1d9c3972fc0bfbe41332b6c5d1d9665f/pkg/config/config.go#L209

When I used ct in GitHub Actions from chart-testing-action it seems unset CT_CONFIG_DIR wasn't enough but I also had to add a ct.yaml file in the root of the repo containing this to make it working:

chart-repos:
  - bitnami=https://charts.bitnami.com/bitnami
wzooff commented 4 months ago

CT_CONFIG_DIR just specifies where to look for ct.yaml configuration file.

If you want to add additional repository, which is the reason for your error:

Error: no repository definition for https://charts.bitnami.com/bitnami.

you can use

$ ct lint --help
      ...
      --chart-repos strings                  Additional chart repositories for dependency resolutions.
                                             Repositories should be formatted as 'name=url' (ex: local=http://127.0.0.1:8879/charts).
                                             May be specified multiple times or separate values with commas

In your case use --chart-repos=bitnami=https://charts.bitnami.com/bitnami right after --target-branch main

github-actions[bot] commented 3 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

dataviruset commented 3 months ago

CT_CONFIG_DIR just specifies where to look for ct.yaml configuration file.

If you want to add additional repository, which is the reason for your error:

Error: no repository definition for https://charts.bitnami.com/bitnami.

you can use

$ ct lint --help
      ...
      --chart-repos strings                  Additional chart repositories for dependency resolutions.
                                             Repositories should be formatted as 'name=url' (ex: local=http://127.0.0.1:8879/charts).
                                             May be specified multiple times or separate values with commas

In your case use --chart-repos=bitnami=https://charts.bitnami.com/bitnami right after --target-branch main

I think it's bad that ct or helm can't find the dependencies by itself even though they are defined with URLs in Chart.yaml but I guess that's a separate issue. I worked around it like this:

repos="$(yq '.dependencies[] | select(.repository != null) | "\(.name)=\(.repository)"' charts/*/Chart.yaml)"
repo_args="$(echo "$repos" | sed '/^=$/d' | sort -u | awk '{printf "%s,", $0}' | sed 's/,$//')"
test -n "$repo_args" && chart_repos="--chart-repos $repo_args" || chart_repos=""
ct install --target-branch main $chart_repos

And now it seems to work for me.

But in some cases people might prefer to use a ct.yaml file as it could be cleaner if they have multiple dependencies, as compared to adding a lot of --chart-repos flags to the ct command. But even though the dependencies added to the ct.yaml file, the issue is still there. It seems the default CT_CONFIG_DIR doesn't actually look in the same directory as the ct install command is run in, because the dependency downloads don't work, as described in my issue.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 2 months ago

This issue was closed because it has been stalled for 5 days with no activity.