fix(pkg/downloader) Generate digest from both chart deps and lock file

> Commits would be squashed after reviews.

To make digest includes information about Chart.yaml dependencies, not
only the lock file, digest calculation is changed to accept both
contents.

Signed-off-by: Hang Park <hangpark@kaist.ac.kr>
pull/6655/head
Hang Park 6 years ago
parent 0c5308d185
commit 7693a7498a
No known key found for this signature in database
GPG Key ID: 35E3D27C832D49A2

@ -123,7 +123,7 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
return nil, errors.Errorf("can't get a valid version for repositories %s. Try changing the version constraint in Chart.yaml", strings.Join(missing, ", "))
}
digest, err := HashReq(locked)
digest, err := HashReq(reqs, locked)
if err != nil {
return nil, err
}
@ -139,8 +139,8 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
//
// This should be used only to compare against another hash generated by this
// function.
func HashReq(req []*chart.Dependency) (string, error) {
data, err := json.Marshal(req)
func HashReq(req []*chart.Dependency, lock []*chart.Dependency) (string, error) {
data, err := json.Marshal([2][]*chart.Dependency{req, lock})
if err != nil {
return "", err
}

@ -125,7 +125,7 @@ func TestResolve(t *testing.T) {
t.Fatalf("Expected error in test %q", tt.name)
}
if h, err := HashReq(tt.expect.Dependencies); err != nil {
if h, err := HashReq(tt.req, tt.expect.Dependencies); err != nil {
t.Fatal(err)
} else if h != l.Digest {
t.Errorf("%q: hashes don't match.", tt.name)
@ -150,11 +150,14 @@ func TestResolve(t *testing.T) {
}
func TestHashReq(t *testing.T) {
expect := "sha256:d661820b01ed7bcf26eed8f01cf16380e0a76326ba33058d3150f919d9b15bc0"
expect := "sha256:96045f8dfd8769a3a1af6202449fa620c900992277803e799fe31c3897f179e8"
req := []*chart.Dependency{
{Name: "alpine", Version: "0.1.0", Repository: "http://localhost:8879/charts"},
{Name: "alpine", Version: "^0.1.0", Repository: "http://localhost:8879/charts"},
}
h, err := HashReq(req)
lock := []*chart.Dependency{
{Name: "alpine", Version: "0.1.2", Repository: "http://localhost:8879/charts"},
}
h, err := HashReq(req, lock)
if err != nil {
t.Fatal(err)
}
@ -162,8 +165,21 @@ func TestHashReq(t *testing.T) {
t.Errorf("Expected %q, got %q", expect, h)
}
req = []*chart.Dependency{}
h, err = HashReq(req)
req2 := []*chart.Dependency{
{Name: "alpine", Version: "^0.1.2", Repository: "http://localhost:8879/charts"},
}
h, err = HashReq(req2, lock)
if err != nil {
t.Fatal(err)
}
if expect == h {
t.Errorf("Expected %q != %q", expect, h)
}
lock2 := []*chart.Dependency{
{Name: "alpine", Version: "0.1.3", Repository: "http://localhost:8879/charts"},
}
h, err = HashReq(req, lock2)
if err != nil {
t.Fatal(err)
}

@ -79,7 +79,7 @@ func (m *Manager) Build() error {
}
req := c.Metadata.Dependencies
if sum, err := resolver.HashReq(req); err != nil || sum != lock.Digest {
if sum, err := resolver.HashReq(req, lock.Dependencies); err != nil || sum != lock.Digest {
return errors.New("Chart.lock is out of sync with Chart.yaml")
}

Loading…
Cancel
Save