-
Notifications
You must be signed in to change notification settings - Fork 220
Handle Helm chart dependencies #175
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
Conversation
hiddeco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great initial implementation with the basics covered, thanks a lot 🌻
Please have a look at my comments and see if they make sense to you.
1d969c6 to
d07acf6
Compare
d07acf6 to
94ba431
Compare
94ba431 to
2f3fa17
Compare
| var dwr []*DependencyWithRepository | ||
| for _, dep := range reqs { | ||
| // Exclude existing dependencies | ||
| for _, existing := range deps { | ||
| if existing.Name() == dep.Name { | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| // Continue loop if file scheme detected | ||
| if strings.HasPrefix(dep.Repository, "file://") { | ||
| dwr = append(dwr, &DependencyWithRepository{ | ||
| Dependency: dep, | ||
| Repo: nil, | ||
| }) | ||
| continue | ||
| } | ||
|
|
||
| // Discover existing HelmRepository by URL | ||
| repository, err := r.resolveDependencyRepository(ctx, dep, chart.Namespace) | ||
| if err != nil { | ||
| repository = &sourcev1.HelmRepository{ | ||
| Spec: sourcev1.HelmRepositorySpec{ | ||
| URL: dep.Repository, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // Configure ChartRepository getter options | ||
| clientOpts, err := r.getRepositoryClientOptions(ctx, repository) | ||
| if err != nil { | ||
| return sourcev1.HelmChartNotReady(chart, sourcev1.AuthenticationFailedReason, err.Error()), err | ||
| } | ||
|
|
||
| // Initialize the chart repository and load the index file | ||
| chartRepo, err := helm.NewChartRepository(repository.Spec.URL, r.Getters, clientOpts) | ||
| if err != nil { | ||
| switch err.(type) { | ||
| case *url.Error: | ||
| return sourcev1.HelmChartNotReady(chart, sourcev1.URLInvalidReason, err.Error()), err | ||
| default: | ||
| return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err | ||
| } | ||
| } | ||
| if repository.Status.Artifact != nil { | ||
| indexFile, err := os.Open(r.Storage.LocalPath(*repository.GetArtifact())) | ||
| if err != nil { | ||
| return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err | ||
| } | ||
| b, err := ioutil.ReadAll(indexFile) | ||
| if err != nil { | ||
| return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err | ||
| } | ||
| if err = chartRepo.LoadIndex(b); err != nil { | ||
| return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err | ||
| } | ||
| } else { | ||
| // Download index | ||
| err = chartRepo.DownloadIndex() | ||
| if err != nil { | ||
| return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err | ||
| } | ||
| } | ||
|
|
||
| dwr = append(dwr, &DependencyWithRepository{ | ||
| Dependency: dep, | ||
| Repo: chartRepo, | ||
| }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a candidate to be factored out, but while taking into account the limitations around the defer of the client configuration below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The defer related limitation kind of makes it hard to extract the whole thing into something meaningful, I've been trying to wrap my brain around it but couldn't yet figure out a good solution.
Let me know what you have in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get what you mean, and can't come up with anything else than collecting the cleanup funcs and defering that stack. But that's, well... ugly.
To facilitate an inexpensive lookup when collecting credentials and index artifacts while working with chart dependencies. Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
Move the logic to helm/utils exported as func NormalizeChartRepositoryURL Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
Method getHelmRepositorySecret on the HelmChartReconciler Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
Non-packaged charts that don't have their dependencies present in charts/ will now have these dependencies built using the DependencyManager. The idea behind it is to replicate the logic implemeneted in Helm's downloader.Manager with the support for already existing HelmRepository resources and their chart retrieval capabilities. Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2f3fa17 to
21ccf1c
Compare
Re: fluxcd/flux2#380 Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
21ccf1c to
bfd8d4b
Compare
hiddeco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have another look at factoring out things when I get to refactoring parts of the reconcilers in general.
Thanks a lot for tackling this and following through on my review comments, and my compliments for thinking ahead and incorporating review comments from the other PR here. 🌻
Attempts to resolve limitation documented here.
Fixes: #174