Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helm dependency build failing with empty index.yaml file #48

Open
piljaechae opened this issue Oct 2, 2024 · 19 comments
Open

helm dependency build failing with empty index.yaml file #48

piljaechae opened this issue Oct 2, 2024 · 19 comments
Labels
bug Something isn't working

Comments

@piljaechae
Copy link

Hi @dag-andersen, I came across your nice project. I succeed when I run docker container for few applications (I first tested with 4). However, if I increase the application numbers (31), I'm constantly getting error below.

❌ our-release1 Failed to load target state: failed to generate manifest for source 1 of 1: rpc error: code = Unknown desc = `helm dependency build` failed exit status 1: Error: error loading /helm-working-dir/repository/https:--our.chartmuseum.repo-index.yaml: empty index.yaml file

I keep failing at the last application, but the application that's causing the ComparisonError is actually random. So I'm guessing that the chart itself would not be the problem.

⏳ Waiting for 1 out of 31 applications to become 'OutOfSync'. Retrying in 5 seconds. 

Maybe the issue is related with helm itself but none of the solutions seemed to work.

I was wondering if you've encountered this issue?

@dag-andersen
Copy link
Owner

Hi @piljaechae!

Unfortunately, I haven't encountered that issue before.
What happens if you set --timeout=600? Does it eventually render correctly? 🤔 If so, I think I can work on a fix for it.

Are you running these 31 applications in a "real" ArgoCD cluster? If so, you might want to check the ArgoCD configuration you're using in your "real" cluster and replicate it in the argocd-diff-preview tool. You can modify the ArgoCD installation like this: link 🚀

@piljaechae
Copy link
Author

piljaechae commented Oct 4, 2024

I think the timeout isn't the core problem here. The problem I'm facing isn't really deterministic, but I can verify that the problem is closely related to the stage of fetching the chart from the chartmuseum.

⏳ Waiting for 31 out of 31 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 600 seconds...
⏳ Waiting for 31 out of 31 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 595 seconds...
⏳ Waiting for 31 out of 31 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 590 seconds...
⏳ Waiting for 31 out of 31 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 585 seconds...
⏳ Waiting for 31 out of 31 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 580 seconds...
❌ Failed to process application: release-10 with error: 
Failed to load target state: failed to generate manifest for source 1 of 1: rpc error: code = Unknown desc = `helm dependency build` failed exit status 1: Error: could not download https://our.chartmuseum.repo/charts/ms-order-3.17.1.tgz: no cached repo found. (try 'helm repo update'): error loading /helm-working-dir/repository/https:--our.chartmuseum.repo-index.yaml: error converting YAML to JSON: yaml: line 5083: found unexpected end of stream
Error: "Failed to process applications"
Error: Process completed with exit code 1.

@piljaechae
Copy link
Author

Yes and indeed, we have about 50 argocd applications in a single cluster. Running diff for 31 of them (only ones related to our backend) is having problems, whereas running diff for only 3~7 applications (for frontend, infra, ml, .. - we group these) works without any problems.

@piljaechae
Copy link
Author

btw, I'm curious if the speed can be improved. Spinning up the local cluster, setting up argocd, and running syncs for the applications seems to be quite slow. I like the idea, but having to wait a few minutes for the diff to show up may not be optimal I believe.

@dag-andersen
Copy link
Owner

❌ Failed to process application: release-10 with error: 
Failed to load target state: failed to generate manifest for source 1 of 1: rpc error: code = Unknown desc = `helm dependency build` failed exit status 1: Error: could not download https://our.chartmuseum.repo/charts/ms-order-3.17.1.tgz: no cached repo found. (try 'helm repo update'): error loading /helm-working-dir/repository/https:--our.chartmuseum.repo-index.yaml: error converting YAML to JSON: yaml: line 5083: found unexpected end of stream
Error: "Failed to process applications"
Error: Process completed with exit code 1.

Interesting! In this case, argocd-diff-preview exits early because of this line. If ArgoCD throws an error including "error converting YAML to JSON", it will terminate early and display the error to the user. This is based on the assumption that the state is unrecoverable and that the application won't suddenly start working during ArgoCD's next reconciliation loop.

If you think this may be a temporary error that shouldn't cause an immediate exit, you can try removing that line from the source code and see if it resolves the issue :) I see you've already forked the repo 🚀

btw, I'm curious if the speed can be improved. Spinning up the local cluster, setting up argocd, and running syncs for the applications seems to be quite slow. I like the idea, but having to wait a few minutes for the diff to show up may not be optimal I believe.

This is the main downside of this solution. It’s slow because you have to start a new cluster each time and install ArgoCD on it. I’ve been exploring whether it’s possible to pre-bake the ArgoCD instance into the Dockerized kind cluster so that when the local kind cluster starts up, ArgoCD would already be set up and ready to go. However, I haven’t been able to make this work yet, and I’m still looking for ways to speed up the process. Any suggestions are highly appreciated 🙌🏻

@seanturner026
Copy link

seanturner026 commented Oct 18, 2024

Have a couple ideas regarding speed.

  1. Could probably have a local docker compose environment that has the bootstrapped kind + argocd running in the background which is then consumed by the rust program. Seems like this would be a quicker feedback loop than waiting for the Github Action to set everything up each iteration.
  2. I wonder if it's possible to evaluate changed files and between the two specified branches, and, only render the corresponding applications. A targeted diff preview. A bit more annoying to write but could also be quicker perhaps? Not really sure if there's much difference between setting up all applications v setting up a couple.

@dag-andersen
Copy link
Owner

I wonder if it's possible to evaluate changed files and between the two specified branches, and, only render the corresponding applications. A targeted diff preview. A bit more annoying to write but could also be quicker perhaps? Not really sure if there's much difference between setting up all applications v setting up a couple.

Automatically detecting which applications need to be rendered is very challenging, as there are many edge cases to handle. argocd-diff-preview already supports a few methods for selecting which applications to render [docs]. However, I am working on another feature that will allow users to define a regex pattern to match only the changed files in the PR, ensuring that only the relevant apps are rendered (as long as you manually add the annotation to all your apps).

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  namespace: argocd
  annotations:
    argocd-diff-preview/watch-pattern: "some/path/.*" # regex - listens for all changes in <root>/some/path/**
spec:
  ...

@dag-andersen
Copy link
Owner

@piljaechae, Are you still experiencing this issue, or can I close the issue? 👼🏻

@piljaechae
Copy link
Author

Sorry @dag-andersen !! I'll take a look at it within a week :)

@dag-andersen dag-andersen added the bug Something isn't working label Nov 4, 2024
@HotThoughts
Copy link
Contributor

HotThoughts commented Jan 10, 2025

We use ApplicationSet and git generator.

Seeing the same problem with argocd-diff-preview v0.0.30:

⏳ Waiting for 6 out of 98 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 4 seconds...
❌ Timed out after 180 seconds
❌ Processed 92 applications, but 6 applications still remain
❌ Applications with 'ComparisonError' errors:
❌ test-app, Failed to load target state: failed to generate manifest for source 1 of 1: rpc error: code = Unknown desc = failed to build helm dependencies: failed to build dependencies: failed to get command args to log: `helm dependency build` failed exit status 1: Error: no cached repository for https:--helm-charts.s3.eu-west-1.amazonaws.com found. (try 'helm repo update'): error loading /helm-working-dir/repository/https:--helm-charts.s3.eu-west-1.amazonaws.com-index.yaml: empty index.yaml file

Unfortunately we have more than 50 applications from one ApplicationSet. The filtering seems only filter ApplicationSet but not the nested applications. Not sure if it something we can improve in argocd-diff-preview. But thie error empty index.yaml file is a problem we constantly see and usually it recovers after sometime.

Update:
Yeah it is a concurrent issue: argoproj/argo-cd#12902

@dag-andersen
Copy link
Owner

Hi @HotThoughts,

Could you elaborate on this: "Unfortunately we have more than 50 applications from one ApplicationSet. The filtering seems only filter ApplicationSet but not the nested applications."?

It would be helpful if you could share the ApplicationSet that’s generating these applications 🤞🏻

What are you experiencing, and what changes would you like to see? :) Let me know — I might be able to make it happen!

@HotThoughts
Copy link
Contributor

Hi @dag-andersen,

Apologies for the confusion in my previous message. We have 19 ApplicationSet resources, and each generates more than 50 Application resources. Due to the large number of applications, we might encounter Helm build update concurrency issues. To address this, I attempted to use the annotation argocd-diff-preview/watch-pattern to filter out unchanged applications. Here's the configuration:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: app-dev
  namespace: argocd
  annotations:
    argocd-diff-preview/watch-pattern: apps/*/.* 👈🏻 here we watch all under directory apps

In the GitHub Actions workflow, we use --filters to limit changes to the relevant applications:

      - name: Get changed directories
        id: changed-files
        uses: tj-actions/changed-files@v45
        with:
          separator: ","

      - name: Generate Diff
        run: |
          docker run \
            --network=host \
            -v /var/run/docker.sock:/var/run/docker.sock \
            -v $(pwd)/main:/base-branch \
            -v $(pwd)/pull-request:/target-branch \
            -v $(pwd)/output:/output \
            -v $(pwd)/secrets:/secrets \
            -e TARGET_BRANCH=${{ github.head_ref }} \
            -e REPO=${{ github.repository }} \
            -e FILES_CHANGED=${{ steps.changed-files.outputs.all_changed_files }} \ 👈 here we pass changed files
            dagandersen/argocd-diff-preview:v0.0.30

Despite using the watch-pattern annotation and passing only changed files, the process still attempts to render all applications defined by the ApplicationSet. Seems it only filters ApplicationSet. Would be nice if we can go further and only generate changed Application in ArgoCD. In the workflow logs, I can see:

🤖 Found 19 Application[Sets] before filtering
🤖 Found 1 Application[Sets] after filtering
🤖 Patching Application[Sets] for branch: argocd-diff-preview
🤖 Patching 1 Argo CD Application[Sets] for branch: argocd-diff-preview
🚀 Creating cluster...
🚀 Cluster created successfully
🤫 Applied 1 secrets
🦑 Installing Argo CD Helm Chart version: '7.7.15'
🦑 Waiting for Argo CD to start...
🦑 Argo CD is now available
🦑 Installed Chart version: 'argo-cd-7.7.15' and App version: 'v2.13.3'
🦑 Logging in to Argo CD through CLI...
🦑 Argo CD installed successfully
🤖 Generated 98 applications from 2 ApplicationSets for branch: main
🤖 Generated [98](https://github.com/***) applications from 2 ApplicationSets for branch: argocd-diff-preview
💾 Writing 98 Applications from 'main' to ./temp/apps_base_branch.yaml
💾 Writing 98 Applications from 'argocd-diff-preview' to ./temp/apps_target_branch.yaml
🌚 Getting resources from base-branch
⏳ Waiting for 98 out of 98 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 180 seconds...
⏳ Waiting for 98 out of 98 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 175 seconds...
⏳ Waiting for 78 out of 98 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 165 seconds...
⏳ Waiting for 59 out of 98 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 154 seconds...
⏳ Waiting for 39 out of 98 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 144 seconds...
⏳ Waiting for 27 out of 98 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 136 seconds...
⏳ Waiting for 1 out of 98 applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in 128 seconds...

@dag-andersen
Copy link
Owner

@HotThoughts

Thank you for the detailed description! :)

Can you verify that the tools writes ✨ - files-changed: <whatever-file-changed> when the tool starts?
Also try running the tool in debug mode using --debug and check the logs.

It seems like you’re doing everything right, so there might be a bug.
I should probably add some more log statements 👍🏻

You should see something like this: ⤵️ [from example]

[2025-01-09T15:49:39Z INFO  argocd_diff_preview::parsing] 🤖 Will only run on Applications that watch these files: '.github/workflows/generate-diff.yml`, `examples/helm/values/filtered.yaml'
[2025-01-09T15:49:39Z DEBUG argocd_diff_preview::argo_resource] Ignoring application "git-generator-example-appset" due to missing 'argocd-diff-preview/watch-pattern' annotation (examples/git-generator/app/app-set.yaml)
[2025-01-09T15:49:39Z DEBUG argocd_diff_preview::argo_resource] Selected application "my-app-watch-pattern-valid-regex" due to regex pattern 'examples/helm/charts/myApp/.*, examples/helm/values/filtered' matching changed files
[2025-01-09T15:49:39Z DEBUG argocd_diff_preview::argo_resource] Ignoring application "my-app-labels" due to missing 'argocd-diff-preview/watch-pattern' annotation (examples/helm/applications/label-selectors/my-app-labels.yaml)
[2025-01-09T15:49:39Z DEBUG argocd_diff_preview::argo_resource] Ignoring application "my-app-set" due to missing 'argocd-diff-preview/watch-pattern' annotation (examples/helm/applications/my-app-set.yaml)

@dag-andersen
Copy link
Owner

However, after checking again...

It does say: ⬇️ It "correctly" only renders the apps based on the FILES_CHANGED you provided. 🤔

🤖 Found 19 Application[Sets] before filtering
🤖 Found 1 Application[Sets] after filtering

So, I guess the problem is that it doesn’t apply the filtering to the Applications generated by the ApplicationSet.

Seems it only filters ApplicationSet

Looks like you’re right! :)

I think i can fix that 🚀

@dag-andersen
Copy link
Owner

dag-andersen commented Jan 13, 2025

Hi @HotThoughts,

I’ve created a new version of the tool that performs a second filtering after generating apps based on AppSets. Would you mind trying v0.0.31?
I haven’t created a GitHub release for it yet, but I will if this fixes the issue for you 🚀

You will need to add the annotation to both the ApplicationSets and the Applications they are creating.

@HotThoughts
Copy link
Contributor

Hi @dag-andersen,

❤️ Thanks. I tested v0.0.31 and added annotations to Applications, so now:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: app-dev
  namespace: argocd
  annotations:
    argocd-diff-preview/watch-pattern: apps/*/.* 👈🏻 here we watch all under directory apps

spec:
  ...
  generators:
  - git:
  ...
  template:
    metadata:
      annotaitons:
        argocd-diff-preview/watch-pattern: '{{ default (printf "apps/%s/.*" (index .path.segments 1) .valuesPath }}/.*' 👈🏻 here we watch all files under one app

Still the same error - argocd trying to render 98 applications while only one changed 😞

@dag-andersen
Copy link
Owner

@HotThoughts
Alright 🤔
Could you verify that it logs a line like this:
[2025-01-09T15:49:39Z DEBUG argocd_diff_preview::argo_resource] Selected application "<your-app>" due to regex pattern '<your regex>' matching changed files
98 times when you run it in --debug mode?

Essentially, I'm asking you to check if this log appears before the line:
💾 Writing 98 Applications from 'main' to ./temp/apps_base_branch.yaml.

@dag-andersen
Copy link
Owner

@HotThoughts
I’d love to help debug this! Feel free to connect with me on LinkedIn or CNCF Slack if you’d like to chat and figure out what is going wrong.

@HotThoughts
Copy link
Contributor

It works now! Argocd-diff-preview filters Applications in ApplicationSet!

I found out the root problem at my end.
Before: The watch pattern annotation was added to ApplicationSet along with the workflow in the same PR, so the action will render all applications in the applicationset
After I added the watch pattern annotation directly to main branch and update the PR: the argocd-diff-preview correctly filters one changed application and renders the diff as comment

Thank you for the help. ❤️ Love the action!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants