Load chartfile into chart on chart file load.

Best commit message ever.
pull/195/head
Matt Butcher 9 years ago
parent 90f1d3d567
commit ffe15f1585

@ -14,6 +14,8 @@ import (
"github.com/kubernetes/deployment-manager/log"
)
const ChartfileName string = "Chart.yaml"
const (
preTemplates string = "templates/"
preHooks string = "hooks/"
@ -42,11 +44,13 @@ type Chart interface {
// Dir returns a directory where the chart can be accessed.
Dir() string
// Close cleans up a chart.
Close() error
}
type dirChart struct {
chartfile *Chartfile
dir string
}
func (d *dirChart) Chartfile() *Chartfile {
@ -99,6 +103,7 @@ func LoadDir(chart string) (Chart, error) {
c := &dirChart{
chartfile: cf,
dir: chart,
}
return c, nil
@ -128,10 +133,20 @@ func Load(archive string) (Chart, error) {
defer unzipped.Close()
untarred := tar.NewReader(unzipped)
return loadTar(untarred)
c, err := loadTar(untarred)
if err != nil {
return c, err
}
cf, err := LoadChartfile(filepath.Join(c.tmpDir, ChartfileName))
if err != nil {
return c, err
}
c.chartfile = cf
return c, nil
}
func loadTar(r *tar.Reader) (Chart, error) {
func loadTar(r *tar.Reader) (*tarChart, error) {
td, err := ioutil.TempDir("", "chart-")
if err != nil {
return nil, err

@ -6,10 +6,13 @@ import (
"github.com/kubernetes/deployment-manager/log"
)
const testfile = "testdata/frobnitz/Chart.yaml"
const testdir = "testdata/frobnitz/"
const testarchive = "testdata/frobnitz-0.0.1.tgz"
const testill = "testdata/ill-1.2.3.tgz"
const (
testfile = "testdata/frobnitz/Chart.yaml"
testdir = "testdata/frobnitz/"
testarchive = "testdata/frobnitz-0.0.1.tgz"
testill = "testdata/ill-1.2.3.tgz"
testnochart = "testdata/nochart.tgz"
)
func init() {
log.IsDebugging = true
@ -62,3 +65,10 @@ func TestLoadIll(t *testing.T) {
return
}
}
func TestLoadNochart(t *testing.T) {
_, err := Load(testnochart)
if err == nil {
t.Error("Nochart should not have loaded at all.")
}
}

@ -31,8 +31,8 @@ func TestLoadChartfile(t *testing.T) {
t.Errorf("Expected second dependency to be thingerbob: %q", f.Dependencies[0].Name)
}
if f.Source[0] != "https://example.com/helm" {
t.Errorf("Expected https://example.com/helm, got %s", f.Source)
if f.Source[0] != "https://example.com/foo/bar" {
t.Errorf("Expected https://example.com/foo/bar, got %s", f.Source)
}
}

Binary file not shown.
Loading…
Cancel
Save