Skip to content

Commit

Permalink
Save Chart.lock to helm package tar
Browse files Browse the repository at this point in the history
Signed-off-by: Song Shukun <song.shukun@fujitsu.com>
Signed-off-by: Matheus Hunsche <matheus.hunsche@ifood.com.br>
  • Loading branch information
Song Shukun authored and Matheus Hunsche committed Oct 2, 2020
1 parent bb09150 commit dfe7939
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/chartutil/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ func writeTarContents(out *tar.Writer, c *chart.Chart, prefix string) error {
return err
}

// Save Chart.lock
// TODO: remove the APIVersion check when APIVersionV1 is not used anymore
if c.Metadata.APIVersion == chart.APIVersionV2 {
if c.Lock != nil {
ldata, err := yaml.Marshal(c.Lock)
if err != nil {
return err
}
if err := writeToTar(out, filepath.Join(base, "Chart.lock"), ldata); err != nil {
return err
}
}
}

// Save values.yaml
for _, f := range c.Raw {
if f.Name == ValuesfileName {
Expand Down
22 changes: 22 additions & 0 deletions pkg/chartutil/save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func TestSave(t *testing.T) {
Name: "ahab",
Version: "1.2.3",
},
Lock: &chart.Lock{
Digest: "testdigest",
},
Files: []*chart.File{
{Name: "scheherazade/shahryar.txt", Data: []byte("1,001 Nights")},
},
Expand Down Expand Up @@ -77,6 +80,9 @@ func TestSave(t *testing.T) {
if len(c2.Files) != 1 || c2.Files[0].Name != "scheherazade/shahryar.txt" {
t.Fatal("Files data did not match")
}
if c2.Lock != nil {
t.Fatal("Expected v1 chart archive not to contain Chart.lock file")
}

if !bytes.Equal(c.Schema, c2.Schema) {
indentation := 4
Expand All @@ -87,6 +93,22 @@ func TestSave(t *testing.T) {
if _, err := Save(&chartWithInvalidJSON, dest); err == nil {
t.Fatalf("Invalid JSON was not caught while saving chart")
}

c.Metadata.APIVersion = chart.APIVersionV2
where, err = Save(c, dest)
if err != nil {
t.Fatalf("Failed to save: %s", err)
}
c2, err = loader.LoadFile(where)
if err != nil {
t.Fatal(err)
}
if c2.Lock == nil {
t.Fatal("Expected v2 chart archive to containe a Chart.lock file")
}
if c2.Lock.Digest != c.Lock.Digest {
t.Fatal("Chart.lock data did not match")
}
})
}
}
Expand Down

0 comments on commit dfe7939

Please sign in to comment.