roboll / helmfile

Deploy Kubernetes Helm Charts
MIT License
4.05k stars 564 forks source link

Helmfile error "There are no repositories defined in your helmfile.yaml" even when repositories exist #2074

Open vitorfhc opened 2 years ago

vitorfhc commented 2 years ago

This was mentioned on #1052 but looks like the error is back.

I created this repo for reproducing the bug.

Helm: version.BuildInfo{Version:"v3.8.0", GitCommit:"d14138609b01886f544b2025f5000351c9eb092e", GitTreeState:"clean", GoVersion:"go1.17.6"}

Helmfile: helmfile version v0.143.0

When I run helmfile deps I get the error:

Adding repo jetstack https://charts.jetstack.io
"jetstack" has been added to your repositories

Updating dependency /var/folders/wn/41tq8rb916xfp0tl5l_492kw0000gp/T/chartify3832583743/dep/dep-01
There are no repositories defined in your helmfile.yaml.
This means helmfile cannot update your dependencies or create a lock file.
See https://github.com/roboll/helmfile/issues/878 for more information.

But, as you can see here, repositories is declared.

denist-huma commented 2 years ago

@vitorfhc Have you tried to remove all related to jetstack?

releases:
- name: dep-01
  namespace: dep
  createNamespace: true
  version: 0.1.0
  chart: ./dep-01
  values:
  - ./values.yaml

There is a usual way to write dependencies in the Helm chart's Chart.yaml Helmfile will not work the way you wrote it anyway. It needs dependencies to be in the same list of releases, to control the sync actions sequence.

vitorfhc commented 2 years ago

@denist-huma One thing that is getting me confused is that I thought the need for it to be in the same releases list was only when using needs.

When you define a dependency using Chart.yaml it creates the release anyway, but it provides a syntax to show it's not just another release but a dependency.

It would be nice to helmfile.yaml to approach itself as much as possible to the original Helm's syntax.

itscaro commented 2 years ago

@vitorfhc I confirmed that there is a bug with deps

Test fixture:

repositories:
- name: jetstack
  url: https://charts.jetstack.io
- name: bitnami
  url: https://charts.bitnami.com/bitnami

releases:
- name: dep-01
  namespace: dep
  createNamespace: true
  version: 9.0.1
  chart: bitnami/apache
  dependencies:
  - alias: certManager
    version: ~v1.7.0
    chart: jetstack/cert-manager

Note the # Source line show that cert-manager is handled as dep of apache

$ helmfile template

Adding repo jetstack https://charts.jetstack.io
"jetstack" has been added to your repositories

Adding repo bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories

Templating release=dep-01, chart=/tmp/chartify3308889910/dep/dep-01/apache
---
# Source: apache/templates/charts/certManager/templates/cainjector-serviceaccount.yaml
$ helmfile deps

Adding repo jetstack https://charts.jetstack.io
"jetstack" has been added to your repositories

Adding repo bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories

Updating dependency /tmp/chartify3254475594/dep/dep-01/apache
There are no repositories defined in your helmfile.yaml.
This means helmfile cannot update your dependencies or create a lock file.
See https://github.com/roboll/helmfile/issues/878 for more information.

Cf. https://github.com/roboll/helmfile/blob/fcf9a7273f9391627118eced20707a35170f33ee/pkg/state/chart_dependency.go#L196-L204

@mumoshu, do you have any hint? I'm not familiar with chartify part.

vitorfhc commented 2 years ago

@itscaro @mumoshu any news on this? I really wish I had enough time to try fixing it, maybe next weekend.

itscaro commented 2 years ago

@vitorfhc Hi, I have not had time to look at this issue. If you can have a look, all contributions are welcomed 😀

vitorfhc commented 2 years ago

This PR-20 should have fixed, but now I get this:

$ helmfile -v
helmfile version v0.143.1

$ helmfile template
Adding repo jetstack https://charts.jetstack.io
"jetstack" has been added to your repositories

Building dependency release=dep-01, chart=/var/folders/wn/41tq8rb916xfp0tl5l_492kw0000gp/T/chartify1298581898/dep/dep-01
in ./helmfile.yaml: [building dependencies of local chart: command "/usr/local/bin/helm" exited with non-zero status:

PATH:
  /usr/local/bin/helm

ARGS:
  0: helm (4 bytes)
  1: dependency (10 bytes)
  2: build (5 bytes)
  3: /var/folders/wn/41tq8rb916xfp0tl5l_492kw0000gp/T/chartify1298581898/dep/dep-01 (78 bytes)

ERROR:
  exit status 1

EXIT STATUS
  1

STDERR:
  Error: the lock file (Chart.lock) is out of sync with the dependencies file (Chart.yaml). Please update the dependencies

COMBINED OUTPUT:
  Error: the lock file (Chart.lock) is out of sync with the dependencies file (Chart.yaml). Please update the dependencies]

I also ran this in a totally isolated Docker container just to be sure.

@itscaro @mumoshu any ideas? I am out of ideas

mumoshu commented 2 years ago

@vitorfhc Thanks for reporting! That's a very interesting error indeed. The PR 20 tries to fix other issue by skipping dependencies that should have been already fetched by helm fetch run by chartify, from subsequent helm dep up run.

If that causes your error, that must mean jetstack/certmanager chart is broken in terms of its charts directories is populated by outdated chart dependencies that arent in-sync with its own Chart.yaml dependencies section.

Would you mind confirming? If that's the case, maybe the remedy would be to somehow fix chartify to detect if the chart dependencies are outdated or not before running helm dep up, so that a broken chart with outdated charts dependencies will go through full helm dep up run and other good charts will not go through full helm dep up run.

mumoshu commented 2 years ago

@vitorfhc NVM. It was an entirely different issue than I thought, and https://github.com/variantdev/chartify/pull/24 fixed the issue with your repro setup (https://github.com/vitorfhc/helmfile-bug-reproduce) for me.