Commit f5986db1 authored by liaoj's avatar liaoj Committed by Matthew Fisher

fix: helm fetch wrong version chart (#4850)

when customer use --version flag, the version format include the Build
metadata, the metadata will be ingorned
Signed-off-by: 's avatarjliao <jliao@alauda.io>
parent 70c509e7
......@@ -168,6 +168,15 @@ func (i IndexFile) Get(name, version string) (*ChartVersion, error) {
}
}
// when customer input exact version, check whether have exact match one first
if len(version) != 0 {
for _, ver := range vs {
if version == ver.Version {
return ver, nil
}
}
}
for _, ver := range vs {
test, err := semver.NewVersion(ver.Version)
if err != nil {
......
......@@ -20,6 +20,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"k8s.io/helm/pkg/getter"
......@@ -39,14 +40,17 @@ func TestIndexFile(t *testing.T) {
i.Add(&chart.Metadata{Name: "cutter", Version: "0.1.1"}, "cutter-0.1.1.tgz", "http://example.com/charts", "sha256:1234567890abc")
i.Add(&chart.Metadata{Name: "cutter", Version: "0.1.0"}, "cutter-0.1.0.tgz", "http://example.com/charts", "sha256:1234567890abc")
i.Add(&chart.Metadata{Name: "cutter", Version: "0.2.0"}, "cutter-0.2.0.tgz", "http://example.com/charts", "sha256:1234567890abc")
i.Add(&chart.Metadata{Name: "setter", Version: "0.1.9+alpha"}, "setter-0.1.9+alpha.tgz", "http://example.com/charts", "sha256:1234567890abc")
i.Add(&chart.Metadata{Name: "setter", Version: "0.1.9+beta"}, "setter-0.1.9+beta.tgz", "http://example.com/charts", "sha256:1234567890abc")
i.SortEntries()
if i.APIVersion != APIVersionV1 {
t.Error("Expected API version v1")
}
if len(i.Entries) != 2 {
t.Errorf("Expected 2 charts. Got %d", len(i.Entries))
if len(i.Entries) != 3 {
t.Errorf("Expected 3 charts. Got %d", len(i.Entries))
}
if i.Entries["clipper"][0].Name != "clipper" {
......@@ -54,13 +58,23 @@ func TestIndexFile(t *testing.T) {
}
if len(i.Entries["cutter"]) != 3 {
t.Error("Expected two cutters.")
t.Error("Expected three cutters.")
}
// Test that the sort worked. 0.2 should be at the first index for Cutter.
if v := i.Entries["cutter"][0].Version; v != "0.2.0" {
t.Errorf("Unexpected first version: %s", v)
}
cv, err := i.Get("setter", "0.1.9")
if err == nil && strings.Index(cv.Metadata.Version, "0.1.9") < 0 {
t.Errorf("Unexpected version: %s", cv.Metadata.Version)
}
cv, err = i.Get("setter", "0.1.9+alpha")
if err != nil || cv.Metadata.Version != "0.1.9+alpha" {
t.Errorf("Expected version: 0.1.9+alpha")
}
}
func TestLoadIndex(t *testing.T) {
......
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