Skip to content

Conversation

@relu
Copy link
Member

@relu relu commented Oct 19, 2020

Attempts to resolve limitation documented here.

Chart dependencies must be committed to Git, as the source-controller does not attempt to download them. This limitation may be removed in a future release.

Fixes: #174

@relu relu changed the base branch from gitrepository-helm-deps to main October 19, 2020 21:56
@relu relu mentioned this pull request Oct 19, 2020
@hiddeco hiddeco assigned hiddeco and unassigned hiddeco Oct 19, 2020
@hiddeco hiddeco self-requested a review October 19, 2020 21:57
Copy link
Member

@hiddeco hiddeco left a 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.

@relu relu force-pushed the gitrepository-helm-deps branch from 1d969c6 to d07acf6 Compare October 26, 2020 17:14
@hiddeco hiddeco added area/helm Helm related issues and pull requests enhancement New feature or request labels Oct 27, 2020
@hiddeco hiddeco changed the title Handle helm chart dependencies in tarball Handle Helm chart dependencies Oct 27, 2020
@relu relu force-pushed the gitrepository-helm-deps branch from d07acf6 to 94ba431 Compare October 27, 2020 22:27
@relu relu requested a review from hiddeco October 27, 2020 22:28
@relu relu force-pushed the gitrepository-helm-deps branch from 94ba431 to 2f3fa17 Compare October 28, 2020 10:38
Comment on lines 452 to 540
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,
})
}
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

hiddeco and others added 5 commits October 28, 2020 14:57
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>
@relu relu force-pushed the gitrepository-helm-deps branch from 2f3fa17 to 21ccf1c Compare October 28, 2020 15:44
Re: fluxcd/flux2#380

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
@relu relu force-pushed the gitrepository-helm-deps branch from 21ccf1c to bfd8d4b Compare October 28, 2020 16:08
Copy link
Member

@hiddeco hiddeco left a 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. 🌻

@hiddeco hiddeco merged commit 0c43076 into fluxcd:main Oct 28, 2020
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 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle Helm chart dependencies

2 participants