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

@ -6,10 +6,13 @@ import (
"github.com/kubernetes/deployment-manager/log" "github.com/kubernetes/deployment-manager/log"
) )
const testfile = "testdata/frobnitz/Chart.yaml" const (
const testdir = "testdata/frobnitz/" testfile = "testdata/frobnitz/Chart.yaml"
const testarchive = "testdata/frobnitz-0.0.1.tgz" testdir = "testdata/frobnitz/"
const testill = "testdata/ill-1.2.3.tgz" testarchive = "testdata/frobnitz-0.0.1.tgz"
testill = "testdata/ill-1.2.3.tgz"
testnochart = "testdata/nochart.tgz"
)
func init() { func init() {
log.IsDebugging = true log.IsDebugging = true
@ -62,3 +65,10 @@ func TestLoadIll(t *testing.T) {
return 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) t.Errorf("Expected second dependency to be thingerbob: %q", f.Dependencies[0].Name)
} }
if f.Source[0] != "https://example.com/helm" { if f.Source[0] != "https://example.com/foo/bar" {
t.Errorf("Expected https://example.com/helm, got %s", f.Source) t.Errorf("Expected https://example.com/foo/bar, got %s", f.Source)
} }
} }

Binary file not shown.
Loading…
Cancel
Save