From 09313ad26c38d905b7ff87921fa5754ade0152d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20H=C3=B6sler?= Date: Wed, 22 Nov 2017 12:51:06 +0100 Subject: [PATCH 1/6] fix(helm): resolve relative chart paths --- cmd/helm/install.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 1ed179d57..df9bf09fb 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -424,7 +424,22 @@ func locateChartPath(repoURL, name, version string, verify bool, keyring, if err != nil { return "", err } - name = chartURL + + parsedChartURL, err := url.Parse(chartURL) + if err != nil { + return "", err + } + + if parsedChartURL.IsAbs() { + name = chartURL + } else { + parsedRepoUrl, err := url.Parse(repoURL) + if err != nil { + return "", err + } + name = parsedRepoUrl.ResolveReference(parsedChartURL).String() + } + } if _, err := os.Stat(settings.Home.Archive()); os.IsNotExist(err) { From 57daa56b8156d35f9b6b0fc31baec429fab1b3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20H=C3=B6sler?= Date: Wed, 22 Nov 2017 13:17:18 +0100 Subject: [PATCH 2/6] Update installDesc --- cmd/helm/install.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index df9bf09fb..bc44bd0e4 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -79,18 +79,19 @@ round-trip to the Tiller server. If --verify is set, the chart MUST have a provenance file, and the provenenace 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 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 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 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 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 From b45293feb006013094213d6380cb881956a4672b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20H=C3=B6sler?= Date: Wed, 22 Nov 2017 13:27:00 +0100 Subject: [PATCH 3/6] fix: updated docs --- docs/helm/helm_install.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/helm/helm_install.md b/docs/helm/helm_install.md index bb66345f4..6ddb56cee 100644 --- a/docs/helm/helm_install.md +++ b/docs/helm/helm_install.md @@ -40,18 +40,19 @@ round-trip to the Tiller server. If --verify is set, the chart MUST have a provenance file, and the provenenace 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 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 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 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 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 @@ -108,4 +109,4 @@ helm install [CHART] ### SEE ALSO * [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 From 2106766ab81b6fb881809aa25a9e35999a6170f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20H=C3=B6sler?= Date: Wed, 22 Nov 2017 13:46:47 +0100 Subject: [PATCH 4/6] fix: rename variable due to linter warning --- cmd/helm/install.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index bc44bd0e4..088d05106 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -434,11 +434,11 @@ func locateChartPath(repoURL, name, version string, verify bool, keyring, if parsedChartURL.IsAbs() { name = chartURL } else { - parsedRepoUrl, err := url.Parse(repoURL) + parsedRepoURL, err := url.Parse(repoURL) if err != nil { return "", err } - name = parsedRepoUrl.ResolveReference(parsedChartURL).String() + name = parsedRepoURL.ResolveReference(parsedChartURL).String() } } From af9190f956cf8983370fe6b6d96aa30e9552c94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20H=C3=B6sler?= Date: Wed, 22 Nov 2017 18:32:05 +0100 Subject: [PATCH 5/6] feature: let FindChartInRepoURL return absolute chart URLs --- cmd/helm/install.go | 21 +++------------------ docs/helm/helm_install.md | 2 +- pkg/repo/chartrepo.go | 27 +++++++++++++++++++++++++-- pkg/repo/chartrepo_test.go | 18 ++++++++++++++++++ 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 088d05106..218ad7c22 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -85,7 +85,7 @@ There are five different ways you can express the chart you want to install: 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 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 +5. By chart reference and repo url: helm install --repo https://example.com/charts/ nginx CHART REFERENCES @@ -425,22 +425,7 @@ func locateChartPath(repoURL, name, version string, verify bool, keyring, if err != nil { return "", err } - - parsedChartURL, err := url.Parse(chartURL) - if err != nil { - return "", err - } - - if parsedChartURL.IsAbs() { - name = chartURL - } else { - parsedRepoURL, err := url.Parse(repoURL) - if err != nil { - return "", err - } - name = parsedRepoURL.ResolveReference(parsedChartURL).String() - } - + name = chartURL } if _, err := os.Stat(settings.Home.Archive()); os.IsNotExist(err) { @@ -459,7 +444,7 @@ func locateChartPath(repoURL, name, version string, verify bool, keyring, 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) { diff --git a/docs/helm/helm_install.md b/docs/helm/helm_install.md index 6ddb56cee..7e206f721 100644 --- a/docs/helm/helm_install.md +++ b/docs/helm/helm_install.md @@ -46,7 +46,7 @@ There are five different ways you can express the chart you want to install: 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 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 +5. By chart reference and repo url: helm install --repo https://example.com/charts/ nginx CHART REFERENCES diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index 236032eef..a7e0305c5 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -184,7 +184,7 @@ func (r *ChartRepository) generateIndex() error { } // 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) { // Download and write the index file to a temporary location @@ -227,5 +227,28 @@ func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caF return "", fmt.Errorf("%s has no downloadable URLs", errMsg) } - return cv.URLs[0], nil + chartURL := cv.URLs[0] + + absoluteChartURL, err := MakeAbsoluteChartURL(repoURL, chartURL) + if err != nil { + return "", err + } + + return absoluteChartURL, nil +} + +// MakeAbsoluteChartURL resolves chartURL relative to repoURL. +// If chartURL is absolute, it returns chartURL. +func MakeAbsoluteChartURL(repoURL, chartURL string) (string, error) { + parsedRepoURL, err := url.Parse(repoURL) + if err != nil { + return "", err + } + + parsedChartURL, err := url.Parse(chartURL) + if err != nil { + return "", err + } + + return parsedRepoURL.ResolveReference(parsedChartURL).String(), nil } diff --git a/pkg/repo/chartrepo_test.go b/pkg/repo/chartrepo_test.go index 9f1bc995a..cc19fd0b0 100644 --- a/pkg/repo/chartrepo_test.go +++ b/pkg/repo/chartrepo_test.go @@ -277,3 +277,21 @@ func TestErrorFindChartInRepoURL(t *testing.T) { t.Errorf("Expected error for chart not found, but got a different error (%v)", err) } } + +func TestMakeAbsoluteChartURL(t *testing.T) { + chartURL, err := MakeAbsoluteChartURL("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 = MakeAbsoluteChartURL("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) + } +} From 98e0bd2ecb9a276bdc041b73c2b4a531be5cfdb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20H=C3=B6sler?= Date: Thu, 23 Nov 2017 09:41:34 +0100 Subject: [PATCH 6/6] refactor: rename function and improve error messages --- pkg/repo/chartrepo.go | 20 ++++++++++---------- pkg/repo/chartrepo_test.go | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index a7e0305c5..b95a7ae07 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -229,26 +229,26 @@ func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caF chartURL := cv.URLs[0] - absoluteChartURL, err := MakeAbsoluteChartURL(repoURL, chartURL) + absoluteChartURL, err := ResolveReferenceURL(repoURL, chartURL) if err != nil { - return "", err + return "", fmt.Errorf("failed to make chart URL absolute: %v", err) } return absoluteChartURL, nil } -// MakeAbsoluteChartURL resolves chartURL relative to repoURL. -// If chartURL is absolute, it returns chartURL. -func MakeAbsoluteChartURL(repoURL, chartURL string) (string, error) { - parsedRepoURL, err := url.Parse(repoURL) +// 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 "", err + return "", fmt.Errorf("failed to parse %s as URL: %v", baseURL, err) } - parsedChartURL, err := url.Parse(chartURL) + parsedRefURL, err := url.Parse(refURL) if err != nil { - return "", err + return "", fmt.Errorf("failed to parse %s as URL: %v", refURL, err) } - return parsedRepoURL.ResolveReference(parsedChartURL).String(), nil + return parsedBaseURL.ResolveReference(parsedRefURL).String(), nil } diff --git a/pkg/repo/chartrepo_test.go b/pkg/repo/chartrepo_test.go index cc19fd0b0..948ee12d3 100644 --- a/pkg/repo/chartrepo_test.go +++ b/pkg/repo/chartrepo_test.go @@ -278,8 +278,8 @@ func TestErrorFindChartInRepoURL(t *testing.T) { } } -func TestMakeAbsoluteChartURL(t *testing.T) { - chartURL, err := MakeAbsoluteChartURL("http://localhost:8123/charts/", "nginx-0.2.0.tgz") +func TestResolveReferenceURL(t *testing.T) { + chartURL, err := ResolveReferenceURL("http://localhost:8123/charts/", "nginx-0.2.0.tgz") if err != nil { t.Errorf("%s", err) } @@ -287,7 +287,7 @@ func TestMakeAbsoluteChartURL(t *testing.T) { t.Errorf("%s", chartURL) } - chartURL, err = MakeAbsoluteChartURL("http://localhost:8123", "https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz") + chartURL, err = ResolveReferenceURL("http://localhost:8123", "https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz") if err != nil { t.Errorf("%s", err) }