This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chartsync: use target helm version for download
This commit achieves three things: 1. The logic for resolving the full chart URL has been moved to the client version implementations, adding two new methods `Pull` and `PullWithRepoURL`. The latter implements the logic for retrieving the full chart URL that was earlier present in the `chartsync` package itself. This ensures the accurate repositories index is used when we look for chart repository credentials. 2. The newly introduced `Pull` method makes use of the `downloader.ChartDownloader` for that Helm version. This makes it easier to integrate e.g. the pull of OCI charts once this feature becomes available in Helm v3. It also provides some ground work for working with named repositories which we may want to use later on when we have introduced the Custom Resource for manging Helm repositories, as it now understands the `repo/name` format. 3. The chartsync now maintains a chart cache per Helm version by appending the `helm.Version()` to the `base`.
- Loading branch information
Showing
9 changed files
with
197 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package helm | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"github.com/go-kit/kit/log" | ||
) | ||
|
||
// logWriter wraps a `log.Logger` so it can be used as an `io.Writer` | ||
type logWriter struct { | ||
log.Logger | ||
} | ||
|
||
func NewLogWriter(logger log.Logger) io.Writer { | ||
return &logWriter{logger} | ||
} | ||
|
||
func (l *logWriter) Write(p []byte) (n int, err error) { | ||
origLen := len(p) | ||
if len(p) > 0 && p[len(p)-1] == '\n' { | ||
p = p[:len(p)-1] // Cut terminating newline | ||
} | ||
l.Log("info", fmt.Sprintf("%s", p)) | ||
return origLen, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package v2 | ||
|
||
import ( | ||
"k8s.io/helm/pkg/downloader" | ||
"k8s.io/helm/pkg/repo" | ||
"k8s.io/helm/pkg/urlutil" | ||
|
||
"github.com/fluxcd/helm-operator/pkg/helm" | ||
) | ||
|
||
func (h *HelmV2) Pull(ref, version, dest string) (string, error) { | ||
repositoryConfigLock.RLock() | ||
defer repositoryConfigLock.RUnlock() | ||
|
||
out := helm.NewLogWriter(h.logger) | ||
c := downloader.ChartDownloader{ | ||
Out: out, | ||
HelmHome: helmHome(), | ||
Verify: downloader.VerifyNever, | ||
Getters: getters, | ||
} | ||
d, _, err := c.DownloadTo(ref, version, dest) | ||
return d, err | ||
} | ||
|
||
func (h *HelmV2) PullWithRepoURL(repoURL, name, version, dest string) (string, error) { | ||
// This resolves the repo URL, chart name and chart version to a | ||
// URL for the chart. To be able to resolve the chart name and | ||
// version to a URL, we have to have the index file; and to have | ||
// that, we may need to authenticate. The credentials will be in | ||
// the repository config. | ||
repositoryConfigLock.RLock() | ||
repoFile, err := loadRepositoryConfig() | ||
repositoryConfigLock.RUnlock() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Now find the entry for the repository, if there is one. If not, | ||
// we'll assume there's no auth needed. | ||
repoEntry := &repo.Entry{} | ||
repoEntry.URL = repoURL | ||
for _, entry := range repoFile.Repositories { | ||
if urlutil.Equal(repoEntry.URL, entry.URL) { | ||
repoEntry = entry | ||
// Ensure we have the repository index as this is | ||
// later used by Helm. | ||
if r, err := repo.NewChartRepository(repoEntry, getters); err == nil { | ||
r.DownloadIndexFile(repositoryCache) | ||
} | ||
break | ||
} | ||
} | ||
|
||
// Look up the full URL of the chart with the collected credentials | ||
// and given chart name and version. | ||
chartURL, err := repo.FindChartInAuthRepoURL(repoEntry.URL, repoEntry.Username, repoEntry.Password, name, version, | ||
repoEntry.CertFile, repoEntry.KeyFile, repoEntry.CAFile, getters) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return h.Pull(chartURL, version, dest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.