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

Fix Helm index validation for Artifactory #1516

Merged
merged 1 commit into from
Jul 22, 2024
Merged

Conversation

bb-Ricardo
Copy link
Contributor

Implements mitigation suggested in #1515

just a copy of the updated validation logic in Helm 3.14.0+

Copy link
Contributor

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanation in #1515 and this fix.
Looking at the upstream fix, it won't be fixed with a dependency update as we have our own index loading code and I don't see any upstream work on fixing the validation that causes this issue.
This change looks good to me.

Left a comment to add a reference for more information about where the code came from.

internal/helm/repository/chart_repository.go Outdated Show resolved Hide resolved
@darkowlzz darkowlzz added the area/helm Helm related issues and pull requests label Jun 27, 2024
@darkowlzz darkowlzz changed the title mitigate issue with chart validation in Helm 3.14 #1515 mitigate issue with chart validation in Helm 3.14 Jun 27, 2024
@bb-Ricardo
Copy link
Contributor Author

The validation of the index is also not ideal. Have tests lying around which I were not able to commit and hope to push next week. But the same issue is present in the same bit of code in Helm. As I said, hope to finish this next week.

@bb-Ricardo
Copy link
Contributor Author

Sorry it took longer than expected.

Added some tests and also comments of where the code came from.

@bb-Ricardo
Copy link
Contributor Author

Added additional tests to verify index filtering is working as expected.

Also opened issue in for Helm helm/helm#13176

@stefanprodan
Copy link
Member

@bb-Ricardo can you please rebase with upstream main and force push

@bb-Ricardo
Copy link
Contributor Author

bb-Ricardo commented Jul 15, 2024

@stefanprodan, rebased on fluxed/source-controller main branch. please have a look

@bb-Ricardo
Copy link
Contributor Author

I can see failing test, lets see if I can reproduce and fix them

@bb-Ricardo
Copy link
Contributor Author

Hi @stefanprodan,

After looking at it for a while I now assume that the tests are kind of broken.

Due to the fixed validation the Helm charts are removed from the index as they failed validation and now are missing in the test.

The issue is subtle. The last chart in the index was always kept in the index, no matter if invalid or not. Now they are probably removed and the test fail as they try to test against an invalid chart.

Two options I guess:

  • remove the test (not desired)
  • fix the test Helm chart, which probably causes other tests to fail.

Can you have a look? What do you think?

@darkowlzz
Copy link
Contributor

I had a look at the failing test and it seems the underlying error that results in the chart version to be removed comes from the index value used in that particular test. In

- urls:
- https://example.com/grafana.tgz
description: string
version: 6.17.4
, no name is set. In all the other test indices used in the other tests, we set a name field which makes the index entries valid. Without it, the Validate() method returns validation: chart.metadata.name is required which is not a skippable error.
I added the following and it fixed the test

diff --git a/internal/helm/chart/builder_remote_test.go b/internal/helm/chart/builder_remote_test.go
index d43966d..ebe31ae 100644
--- a/internal/helm/chart/builder_remote_test.go
+++ b/internal/helm/chart/builder_remote_test.go
@@ -99,6 +99,7 @@ entries:
         - https://example.com/grafana.tgz
       description: string
       version: 6.17.4
+      name: grafana
 `)
 
        mockGetter := &mockIndexChartGetter{

This was not an issue before as you found out, the original entries were not mutated, returning the index content as read from the input.

@bb-Ricardo
Copy link
Contributor Author

bb-Ricardo commented Jul 18, 2024

@darkowlzz,

thank you. so simple and actually obvious, feeling a bit stupid now.

however, I added the name to the chart in the index and these test then passed successfully. I also rebased the branch again on top of upstream/main.

please have a look

@stefanprodan stefanprodan changed the title mitigate issue with chart validation in Helm 3.14 Fix Helm index validation for Artifactory Jul 18, 2024
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @bb-Ricardo 🏅

PS. Please squash your commits and force push.

@bb-Ricardo
Copy link
Contributor Author

Hi,

I added suggested changes, squashed the changes into one commit and pushed it again.

Copy link
Contributor

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Thanks for the fix and all the tests.

I suggested a minor test rename which can be accepted, if it sounds good, before merging.

internal/helm/repository/chart_repository_test.go Outdated Show resolved Hide resolved
Signed-off-by: ricardo.bartels@telekom.de <ricardo.bartels@telekom.de>
@darkowlzz darkowlzz merged commit 218af57 into fluxcd:main Jul 22, 2024
9 checks passed
@fluxcdbot
Copy link
Member

Successfully created backport PR for release/v1.3.x:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/helm Helm related issues and pull requests backport:release/v1.3.x To be backported to release/v1.3.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants