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

Implements DependencyUpdate for helm charts #2135

Merged
merged 5 commits into from
Feb 16, 2024

Conversation

0xavi0
Copy link
Contributor

@0xavi0 0xavi0 commented Feb 8, 2024

Updates dependencies in helm charts by default.
A new flag disableDependencyUpdate is added to the fleet.yaml file in order to disable the feature.

If you don't specify anything, dependencies will be updated.
In order to avoid dependency updates, use disableDependencyUpdate: true in the fleet.yaml file.

A new package helmupdater is added to implement the dependencies update.
The implementation is based on helm's when ussing the --dependency-update flag in the install command.

Dependencies are applied to the bundle (upstream) so they're resolved already when applying downstream.

Note. It also adds a new step when running e2e tests, because the new dependency update tests rely on both, the helm-registry and the git-server

Refers to: #1672

@0xavi0 0xavi0 requested a review from a team as a code owner February 8, 2024 15:19
@0xavi0 0xavi0 force-pushed the 1672-depedency-update branch 8 times, most recently from 331ccd3 to c57393b Compare February 9, 2024 11:09
A new flag `disableDependencyUpdate` is added to the `fleet.yaml`
file in order to disable the feature, which is active by default.

A new package `helmupdater` is added to implement the dependencies
update.
The implementation is based on helm's when ussing the
`--dependency-update` flag in the install command.

Dependencies are applied to the bundle (upstream) to they're resolved
already when applying downstream.

Refers to: rancher#1672

Signed-off-by: Xavi Garcia <[email protected]>
@0xavi0 0xavi0 self-assigned this Feb 9, 2024
@0xavi0 0xavi0 added this to the v2.9.0 milestone Feb 9, 2024
Copy link
Contributor

@weyfonk weyfonk left a comment

Choose a reason for hiding this comment

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

Nice work, thanks for this!
Leaving a few comments, mostly nitpicks.

.github/workflows/e2e-ci.yml Outdated Show resolved Hide resolved
.github/workflows/e2e-ci.yml Outdated Show resolved Hide resolved
internal/bundlereader/loaddirectory.go Outdated Show resolved Hide resolved
internal/helmupdater/helmupdater.go Outdated Show resolved Hide resolved
internal/helmupdater/helmupdater.go Outdated Show resolved Hide resolved
integrationtests/cli/apply/apply_test.go Outdated Show resolved Hide resolved
integrationtests/cli/apply/apply_test.go Outdated Show resolved Hide resolved
presentInBundleResources(path.Join(tmpDir, "Chart.lock"), bundle.Spec.Resources)
presentInBundleResources(path.Join(tmpDir, "charts/config-chart-0.1.0.tgz"), bundle.Spec.Resources)

return !bundle.Spec.KeepResources
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is KeepResources relevant here? Would this be a leftover from reusing specs of already existing test cases? (same question about the test description)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not, indeed. I've deleted that.

integrationtests/cli/apply/apply_test.go Outdated Show resolved Hide resolved
e2e/single-cluster/helm_dependencies_test.go Show resolved Hide resolved
Signed-off-by: Xavi Garcia <[email protected]>
@0xavi0 0xavi0 requested a review from weyfonk February 13, 2024 13:03
Changed from disableDependencyUpdate to disableDepsUpdate

Signed-off-by: Xavi Garcia <[email protected]>
Comment on lines 299 to 300
return true
}).Should(BeTrue())
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this doesn't make much sense: either we should return an expression, which may or may not evaluate as true, or skip this altogether: do we even need Eventually blocks here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought that was because we don't know when the Bundle is going to be ready so Eventually waits up to its timeout (5 minutes) for success.
It would only reach that return true statement when all the statements before that one are successful (at least that's what I got from the tests I did)
As there are quite a few files to check I thought it was better to do that than returning a chain of booleans.
(This file is found and that file is found and... etc)

Given I'm new to Ginkgo I guess there are better ways of doing what I need... I'll investigate. :/

Copy link
Member

Choose a reason for hiding this comment

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

Since the test uses the cli to create the bundle it will be ready when the cli exists. The buffer buf will be in it's final state, as soon as cli.GetBundleFromOutput returns. Eventually is great when we're waiting for resources to appear in k8s. If I understood that correctly, I'd definitely remove them.

I also see a lot of helper functions like onlyPresentInBundleResources, these could be custom matchers: https://onsi.github.io/gomega/#adding-your-own-matchers
But I don't think we're using those anywhere else, no need to do change it.

Copy link
Contributor Author

@0xavi0 0xavi0 Feb 16, 2024

Choose a reason for hiding this comment

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

I've tested deleting the Eventually statements and running in a loop for 10000 times and it passed.
So... Eventually statements deleted.

I've also added a couple of custom matchers and deleted the helpers.

Also... I've changed the already existing tests to use the custom matchers and removed the Eventually statements to avoid future confusions and make the whole file consistent.

Copy link
Contributor

@weyfonk weyfonk 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 converting existing test cases to using matchers, they're much more readable now!

Expect(len(root.Spec.Resources)).To(Equal(5))

Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentA/fleet.yaml").To(bePresentInBundleResources(deploymentA.Spec.Resources))
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentA/fleet.yaml").To(bePresentInBundleResources(deploymentA.Spec.Resources))
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't these two the same check? You have converted it correctly, but I suspect there was a typo in the test case in the first place, eg.:

Suggested change
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentA/fleet.yaml").To(bePresentInBundleResources(deploymentA.Spec.Resources))
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentA/deployment.yaml").To(bePresentInBundleResources(deploymentA.Spec.Resources))

(disclaimer: I haven't tested this)

Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentA/fleet.yaml").To(bePresentInBundleResources(deploymentA.Spec.Resources))
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentC/fleet.yaml").To(bePresentInBundleResources(deploymentC.Spec.Resources))
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentA/fleet.yaml").To(bePresentInBundleResources(root.Spec.Resources))
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentA/fleet.yaml").To(bePresentInBundleResources(root.Spec.Resources))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same doubt as above:

Suggested change
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentA/fleet.yaml").To(bePresentInBundleResources(root.Spec.Resources))
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentA/deployment.yaml").To(bePresentInBundleResources(root.Spec.Resources))

Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentA/fleet.yaml").To(bePresentInBundleResources(root.Spec.Resources))
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentA/fleet.yaml").To(bePresentInBundleResources(root.Spec.Resources))
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentB/svc.yaml").To(bePresentInBundleResources(root.Spec.Resources))
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentC/fleet.yaml").To(bePresentInBundleResources(root.Spec.Resources))
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe one check is missing from the previous version:

Suggested change
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentC/fleet.yaml").To(bePresentInBundleResources(root.Spec.Resources))
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentC/fleet.yaml").To(bePresentInBundleResources(root.Spec.Resources))
Expect(cli.AssetsPath + "nested_mixed_two_levels/nested/deploymentD/deployment.yaml").To(bePresentInBundleResources(root.Spec.Resources))

Eventually is not needed when testing for resources in bundles as we get
the bundle from `cli.GetBundleListFromOutput` and the buffer read will be
in its final state once `cli.GetBundleListFromOutput` returns.

Also addind custom Gomega matchers to avoid using helper functions and
to get the exact line when any test assertion fails.

Already existing tests have been changed to use the custom matchers and
don't use Eventually, also.

Signed-off-by: Xavi Garcia <[email protected]>
@0xavi0 0xavi0 merged commit 3ad25e1 into rancher:master Feb 16, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants