diff --git a/chart/chart.go b/chart/chart.go index 514a4001b..2f0a35c42 100644 --- a/chart/chart.go +++ b/chart/chart.go @@ -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 diff --git a/chart/chart_test.go b/chart/chart_test.go index 91f020f3e..5a16dc6bf 100644 --- a/chart/chart_test.go +++ b/chart/chart_test.go @@ -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.") + } +} diff --git a/chart/chartfile_test.go b/chart/chartfile_test.go index 92781d3fa..d1d21d3f3 100644 --- a/chart/chartfile_test.go +++ b/chart/chartfile_test.go @@ -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) } } diff --git a/chart/testdata/nochart.tgz b/chart/testdata/nochart.tgz new file mode 100644 index 000000000..f5a235537 Binary files /dev/null and b/chart/testdata/nochart.tgz differ