Unverified Commit cad89240 authored by Matthew Fisher's avatar Matthew Fisher Committed by GitHub

Merge pull request #3187 from hoesler/fix/chart_downloader

fix(helm): resolve relative chart paths
parents 7c79d1c7 98e0bd2e
...@@ -79,18 +79,19 @@ round-trip to the Tiller server. ...@@ -79,18 +79,19 @@ round-trip to the Tiller server.
If --verify is set, the chart MUST have a provenance file, and the provenenace If --verify is set, the chart MUST have a provenance file, and the provenenace
fall MUST pass all verification steps. fall MUST pass all verification steps.
There are four different ways you can express the chart you want to install: There are five different ways you can express the chart you want to install:
1. By chart reference: helm install stable/mariadb 1. By chart reference: helm install stable/mariadb
2. By path to a packaged chart: helm install ./nginx-1.2.3.tgz 2. By path to a packaged chart: helm install ./nginx-1.2.3.tgz
3. By path to an unpacked chart directory: helm install ./nginx 3. By path to an unpacked chart directory: helm install ./nginx
4. By absolute URL: helm install https://example.com/charts/nginx-1.2.3.tgz 4. By absolute URL: helm install https://example.com/charts/nginx-1.2.3.tgz
5. By chart reference and repo url: helm install --repo https://example.com/charts/ nginx
CHART REFERENCES CHART REFERENCES
A chart reference is a convenient way of reference a chart in a chart repository. A chart reference is a convenient way of reference a chart in a chart repository.
When you use a chart reference ('stable/mariadb'), Helm will look in the local When you use a chart reference with a repo prefix ('stable/mariadb'), Helm will look in the local
configuration for a chart repository named 'stable', and will then look for a configuration for a chart repository named 'stable', and will then look for a
chart in that repository whose name is 'mariadb'. It will install the latest chart in that repository whose name is 'mariadb'. It will install the latest
version of that chart unless you also supply a version number with the version of that chart unless you also supply a version number with the
...@@ -443,7 +444,7 @@ func locateChartPath(repoURL, name, version string, verify bool, keyring, ...@@ -443,7 +444,7 @@ func locateChartPath(repoURL, name, version string, verify bool, keyring,
return filename, err return filename, err
} }
return filename, fmt.Errorf("file %q not found", name) return filename, fmt.Errorf("failed to download %q", name)
} }
func generateName(nameTemplate string) (string, error) { func generateName(nameTemplate string) (string, error) {
......
...@@ -40,18 +40,19 @@ round-trip to the Tiller server. ...@@ -40,18 +40,19 @@ round-trip to the Tiller server.
If --verify is set, the chart MUST have a provenance file, and the provenenace If --verify is set, the chart MUST have a provenance file, and the provenenace
fall MUST pass all verification steps. fall MUST pass all verification steps.
There are four different ways you can express the chart you want to install: There are five different ways you can express the chart you want to install:
1. By chart reference: helm install stable/mariadb 1. By chart reference: helm install stable/mariadb
2. By path to a packaged chart: helm install ./nginx-1.2.3.tgz 2. By path to a packaged chart: helm install ./nginx-1.2.3.tgz
3. By path to an unpacked chart directory: helm install ./nginx 3. By path to an unpacked chart directory: helm install ./nginx
4. By absolute URL: helm install https://example.com/charts/nginx-1.2.3.tgz 4. By absolute URL: helm install https://example.com/charts/nginx-1.2.3.tgz
5. By chart reference and repo url: helm install --repo https://example.com/charts/ nginx
CHART REFERENCES CHART REFERENCES
A chart reference is a convenient way of reference a chart in a chart repository. A chart reference is a convenient way of reference a chart in a chart repository.
When you use a chart reference ('stable/mariadb'), Helm will look in the local When you use a chart reference with a repo prefix ('stable/mariadb'), Helm will look in the local
configuration for a chart repository named 'stable', and will then look for a configuration for a chart repository named 'stable', and will then look for a
chart in that repository whose name is 'mariadb'. It will install the latest chart in that repository whose name is 'mariadb'. It will install the latest
version of that chart unless you also supply a version number with the version of that chart unless you also supply a version number with the
...@@ -108,4 +109,4 @@ helm install [CHART] ...@@ -108,4 +109,4 @@ helm install [CHART]
### SEE ALSO ### SEE ALSO
* [helm](helm.md) - The Helm package manager for Kubernetes. * [helm](helm.md) - The Helm package manager for Kubernetes.
###### Auto generated by spf13/cobra on 7-Nov-2017 ###### Auto generated by spf13/cobra on 22-Nov-2017
...@@ -184,7 +184,7 @@ func (r *ChartRepository) generateIndex() error { ...@@ -184,7 +184,7 @@ func (r *ChartRepository) generateIndex() error {
} }
// FindChartInRepoURL finds chart in chart repository pointed by repoURL // FindChartInRepoURL finds chart in chart repository pointed by repoURL
// without adding repo to repostiories // without adding repo to repositories
func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers) (string, error) { func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers) (string, error) {
// Download and write the index file to a temporary location // Download and write the index file to a temporary location
...@@ -227,5 +227,28 @@ func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caF ...@@ -227,5 +227,28 @@ func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caF
return "", fmt.Errorf("%s has no downloadable URLs", errMsg) return "", fmt.Errorf("%s has no downloadable URLs", errMsg)
} }
return cv.URLs[0], nil chartURL := cv.URLs[0]
absoluteChartURL, err := ResolveReferenceURL(repoURL, chartURL)
if err != nil {
return "", fmt.Errorf("failed to make chart URL absolute: %v", err)
}
return absoluteChartURL, nil
}
// ResolveReferenceURL resolves refURL relative to baseURL.
// If refURL is absolute, it simply returns refURL.
func ResolveReferenceURL(baseURL, refURL string) (string, error) {
parsedBaseURL, err := url.Parse(baseURL)
if err != nil {
return "", fmt.Errorf("failed to parse %s as URL: %v", baseURL, err)
}
parsedRefURL, err := url.Parse(refURL)
if err != nil {
return "", fmt.Errorf("failed to parse %s as URL: %v", refURL, err)
}
return parsedBaseURL.ResolveReference(parsedRefURL).String(), nil
} }
...@@ -277,3 +277,21 @@ func TestErrorFindChartInRepoURL(t *testing.T) { ...@@ -277,3 +277,21 @@ func TestErrorFindChartInRepoURL(t *testing.T) {
t.Errorf("Expected error for chart not found, but got a different error (%v)", err) t.Errorf("Expected error for chart not found, but got a different error (%v)", err)
} }
} }
func TestResolveReferenceURL(t *testing.T) {
chartURL, err := ResolveReferenceURL("http://localhost:8123/charts/", "nginx-0.2.0.tgz")
if err != nil {
t.Errorf("%s", err)
}
if chartURL != "http://localhost:8123/charts/nginx-0.2.0.tgz" {
t.Errorf("%s", chartURL)
}
chartURL, err = ResolveReferenceURL("http://localhost:8123", "https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz")
if err != nil {
t.Errorf("%s", err)
}
if chartURL != "https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz" {
t.Errorf("%s", chartURL)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment