ref(*): remove protobuf any type

pull/3945/head
Adam Reese 7 years ago
parent 91a6ebfed5
commit 36536d77ba
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -22,10 +22,10 @@ import (
"strings" "strings"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/golang/protobuf/ptypes/any"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/hapi/chart"
) )
const inspectDesc = ` const inspectDesc = `
@ -248,15 +248,15 @@ func (i *inspectCmd) run() error {
if readme == nil { if readme == nil {
return nil return nil
} }
fmt.Fprintln(i.out, string(readme.Value)) fmt.Fprintln(i.out, string(readme.Data))
} }
return nil return nil
} }
func findReadme(files []*any.Any) (file *any.Any) { func findReadme(files []*chart.File) (file *chart.File) {
for _, file := range files { for _, file := range files {
for _, n := range readmeFileNames { for _, n := range readmeFileNames {
if strings.EqualFold(file.TypeUrl, n) { if strings.EqualFold(file.Name, n) {
return file return file
} }
} }

@ -482,7 +482,7 @@ func defaultNamespace() string {
func checkDependencies(ch *chart.Chart, reqs *chartutil.Requirements) error { func checkDependencies(ch *chart.Chart, reqs *chartutil.Requirements) error {
missing := []string{} missing := []string{}
deps := ch.GetDependencies() deps := ch.Dependencies
for _, r := range reqs.Dependencies { for _, r := range reqs.Dependencies {
found := false found := false
for _, d := range deps { for _, d := range deps {

4
glide.lock generated

@ -1,5 +1,5 @@
hash: b78f3d1f316474c2afd90074058cb5b1b4eda432b7bc270e4b76141199387d37 hash: f61bc9a14aff4543b59b89891e4ad0ae787a0ce0e6d775d02b8964e857d41aad
updated: 2018-04-16T23:16:59.971946077Z updated: 2018-04-18T23:27:56.45176431Z
imports: imports:
- name: cloud.google.com/go - name: cloud.google.com/go
version: 3b1ae45394a234c385be014e9a488f2bb6eef821 version: 3b1ae45394a234c385be014e9a488f2bb6eef821

@ -15,12 +15,6 @@ import:
- package: github.com/Masterminds/semver - package: github.com/Masterminds/semver
version: ~1.3.1 version: ~1.3.1
- package: github.com/technosophos/moniker - package: github.com/technosophos/moniker
- package: github.com/golang/protobuf
version: 1643683e1b54a9e88ad26d98f81400c8c9d9f4f9
subpackages:
- proto
- ptypes/any
- ptypes/timestamp
- package: github.com/gosuri/uitable - package: github.com/gosuri/uitable
- package: github.com/asaskevich/govalidator - package: github.com/asaskevich/govalidator
version: ^4.0.0 version: ^4.0.0

@ -299,11 +299,11 @@ func CreateFrom(chartfile *chart.Metadata, dest string, src string) error {
schart.Metadata = chartfile schart.Metadata = chartfile
var updatedTemplates []*chart.Template var updatedTemplates []*chart.File
for _, template := range schart.Templates { for _, template := range schart.Templates {
newData := Transform(string(template.Data), "<CHARTNAME>", schart.Metadata.Name) newData := Transform(string(template.Data), "<CHARTNAME>", schart.Metadata.Name)
updatedTemplates = append(updatedTemplates, &chart.Template{Name: template.Name, Data: newData}) updatedTemplates = append(updatedTemplates, &chart.File{Name: template.Name, Data: newData})
} }
schart.Templates = updatedTemplates schart.Templates = updatedTemplates

@ -22,11 +22,11 @@ import (
"path" "path"
"strings" "strings"
"github.com/ghodss/yaml"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"github.com/ghodss/yaml"
"github.com/gobwas/glob" "github.com/gobwas/glob"
"github.com/golang/protobuf/ptypes/any"
"k8s.io/helm/pkg/hapi/chart"
) )
// Files is a map of files in a chart that can be accessed from a template. // Files is a map of files in a chart that can be accessed from a template.
@ -34,12 +34,10 @@ type Files map[string][]byte
// NewFiles creates a new Files from chart files. // NewFiles creates a new Files from chart files.
// Given an []*any.Any (the format for files in a chart.Chart), extract a map of files. // Given an []*any.Any (the format for files in a chart.Chart), extract a map of files.
func NewFiles(from []*any.Any) Files { func NewFiles(from []*chart.File) Files {
files := map[string][]byte{} files := map[string][]byte{}
if from != nil {
for _, f := range from { for _, f := range from {
files[f.TypeUrl] = f.Value files[f.Name] = f.Data
}
} }
return files return files
} }

@ -18,7 +18,6 @@ package chartutil
import ( import (
"testing" "testing"
"github.com/golang/protobuf/ptypes/any"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -32,16 +31,16 @@ var cases = []struct {
{"multiline/test.txt", "bar\nfoo"}, {"multiline/test.txt", "bar\nfoo"},
} }
func getTestFiles() []*any.Any { func getTestFiles() Files {
a := []*any.Any{} a := make(Files, len(cases))
for _, c := range cases { for _, c := range cases {
a = append(a, &any.Any{TypeUrl: c.path, Value: []byte(c.data)}) a[c.path] = []byte(c.data)
} }
return a return a
} }
func TestNewFiles(t *testing.T) { func TestNewFiles(t *testing.T) {
files := NewFiles(getTestFiles()) files := getTestFiles()
if len(files) != len(cases) { if len(files) != len(cases) {
t.Errorf("Expected len() = %d, got %d", len(cases), len(files)) t.Errorf("Expected len() = %d, got %d", len(cases), len(files))
} }
@ -59,7 +58,7 @@ func TestNewFiles(t *testing.T) {
func TestFileGlob(t *testing.T) { func TestFileGlob(t *testing.T) {
as := assert.New(t) as := assert.New(t)
f := NewFiles(getTestFiles()) f := getTestFiles()
matched := f.Glob("story/**") matched := f.Glob("story/**")
@ -70,7 +69,7 @@ func TestFileGlob(t *testing.T) {
func TestToConfig(t *testing.T) { func TestToConfig(t *testing.T) {
as := assert.New(t) as := assert.New(t)
f := NewFiles(getTestFiles()) f := getTestFiles()
out := f.Glob("**/captain.txt").AsConfig() out := f.Glob("**/captain.txt").AsConfig()
as.Equal("captain.txt: The Captain", out) as.Equal("captain.txt: The Captain", out)
@ -81,7 +80,7 @@ func TestToConfig(t *testing.T) {
func TestToSecret(t *testing.T) { func TestToSecret(t *testing.T) {
as := assert.New(t) as := assert.New(t)
f := NewFiles(getTestFiles()) f := getTestFiles()
out := f.Glob("ship/**").AsSecrets() out := f.Glob("ship/**").AsSecrets()
as.Equal("captain.txt: VGhlIENhcHRhaW4=\nstowaway.txt: TGVnYXR0", out) as.Equal("captain.txt: VGhlIENhcHRhaW4=\nstowaway.txt: TGVnYXR0", out)
@ -90,7 +89,7 @@ func TestToSecret(t *testing.T) {
func TestLines(t *testing.T) { func TestLines(t *testing.T) {
as := assert.New(t) as := assert.New(t)
f := NewFiles(getTestFiles()) f := getTestFiles()
out := f.Lines("multiline/test.txt") out := f.Lines("multiline/test.txt")
as.Len(out, 2) as.Len(out, 2)

@ -28,8 +28,6 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/golang/protobuf/ptypes/any"
"k8s.io/helm/pkg/hapi/chart" "k8s.io/helm/pkg/hapi/chart"
"k8s.io/helm/pkg/ignore" "k8s.io/helm/pkg/ignore"
"k8s.io/helm/pkg/sympath" "k8s.io/helm/pkg/sympath"
@ -136,10 +134,10 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
} else if f.Name == "values.yaml" { } else if f.Name == "values.yaml" {
c.Values = &chart.Config{Raw: string(f.Data)} c.Values = &chart.Config{Raw: string(f.Data)}
} else if strings.HasPrefix(f.Name, "templates/") { } else if strings.HasPrefix(f.Name, "templates/") {
c.Templates = append(c.Templates, &chart.Template{Name: f.Name, Data: f.Data}) c.Templates = append(c.Templates, &chart.File{Name: f.Name, Data: f.Data})
} else if strings.HasPrefix(f.Name, "charts/") { } else if strings.HasPrefix(f.Name, "charts/") {
if filepath.Ext(f.Name) == ".prov" { if filepath.Ext(f.Name) == ".prov" {
c.Files = append(c.Files, &any.Any{TypeUrl: f.Name, Value: f.Data}) c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data})
continue continue
} }
cname := strings.TrimPrefix(f.Name, "charts/") cname := strings.TrimPrefix(f.Name, "charts/")
@ -151,7 +149,7 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
scname := parts[0] scname := parts[0]
subcharts[scname] = append(subcharts[scname], &BufferedFile{Name: cname, Data: f.Data}) subcharts[scname] = append(subcharts[scname], &BufferedFile{Name: cname, Data: f.Data})
} else { } else {
c.Files = append(c.Files, &any.Any{TypeUrl: f.Name, Value: f.Data}) c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data})
} }
} }

@ -97,27 +97,13 @@ icon: https://example.com/64x64.png
t.Errorf("Expected number of templates == 2, got %d", len(c.Templates)) t.Errorf("Expected number of templates == 2, got %d", len(c.Templates))
} }
c, err = LoadFiles([]*BufferedFile{}) _, err = LoadFiles([]*BufferedFile{})
if err == nil { if err == nil {
t.Fatal("Expected err to be non-nil") t.Fatal("Expected err to be non-nil")
} }
if err.Error() != "chart metadata (Chart.yaml) missing" { if err.Error() != "chart metadata (Chart.yaml) missing" {
t.Errorf("Expected chart metadata missing error, got '%s'", err.Error()) t.Errorf("Expected chart metadata missing error, got '%s'", err.Error())
} }
// legacy check
c, err = LoadFiles([]*BufferedFile{
{
Name: "values.toml",
Data: []byte{},
},
})
if err == nil {
t.Fatal("Expected err to be non-nil")
}
if err.Error() != "values.toml is illegal as of 2.0.0-alpha.2" {
t.Errorf("Expected values.toml to be illegal, got '%s'", err.Error())
}
} }
// Packaging the chart on a Windows machine will produce an // Packaging the chart on a Windows machine will produce an
@ -145,7 +131,7 @@ func verifyChart(t *testing.T, c *chart.Chart) {
if len(c.Files) != numfiles { if len(c.Files) != numfiles {
t.Errorf("Expected %d extra files, got %d", numfiles, len(c.Files)) t.Errorf("Expected %d extra files, got %d", numfiles, len(c.Files))
for _, n := range c.Files { for _, n := range c.Files {
t.Logf("\t%s", n.TypeUrl) t.Logf("\t%s", n.Name)
} }
} }

@ -98,8 +98,8 @@ type RequirementsLock struct {
func LoadRequirements(c *chart.Chart) (*Requirements, error) { func LoadRequirements(c *chart.Chart) (*Requirements, error) {
var data []byte var data []byte
for _, f := range c.Files { for _, f := range c.Files {
if f.TypeUrl == requirementsName { if f.Name == requirementsName {
data = f.Value data = f.Data
} }
} }
if len(data) == 0 { if len(data) == 0 {
@ -113,8 +113,8 @@ func LoadRequirements(c *chart.Chart) (*Requirements, error) {
func LoadRequirementsLock(c *chart.Chart) (*RequirementsLock, error) { func LoadRequirementsLock(c *chart.Chart) (*RequirementsLock, error) {
var data []byte var data []byte
for _, f := range c.Files { for _, f := range c.Files {
if f.TypeUrl == lockfileName { if f.Name == lockfileName {
data = f.Value data = f.Data
} }
} }
if len(data) == 0 { if len(data) == 0 {
@ -392,7 +392,7 @@ func processImportValues(c *chart.Chart) error {
if err != nil { if err != nil {
return err return err
} }
b := make(map[string]interface{}, 0) b := make(map[string]interface{})
// import values from each dependency if specified in import-values // import values from each dependency if specified in import-values
for _, r := range reqs.Dependencies { for _, r := range reqs.Dependencies {
if len(r.ImportValues) > 0 { if len(r.ImportValues) > 0 {

@ -287,7 +287,7 @@ func verifyRequirementsImportValues(t *testing.T, c *chart.Chart, v *chart.Confi
if err != nil { if err != nil {
t.Errorf("Error processing import values requirements %v", err) t.Errorf("Error processing import values requirements %v", err)
} }
cv := c.GetValues() cv := c.Values
cc, err := ReadValues([]byte(cv.Raw)) cc, err := ReadValues([]byte(cv.Raw))
if err != nil { if err != nil {
t.Errorf("Error reading import values %v", err) t.Errorf("Error reading import values %v", err)

@ -69,14 +69,14 @@ func SaveDir(c *chart.Chart, dest string) error {
// Save files // Save files
for _, f := range c.Files { for _, f := range c.Files {
n := filepath.Join(outdir, f.TypeUrl) n := filepath.Join(outdir, f.Name)
d := filepath.Dir(n) d := filepath.Dir(n)
if err := os.MkdirAll(d, 0755); err != nil { if err := os.MkdirAll(d, 0755); err != nil {
return err return err
} }
if err := ioutil.WriteFile(n, f.Value, 0755); err != nil { if err := ioutil.WriteFile(n, f.Data, 0755); err != nil {
return err return err
} }
} }
@ -186,8 +186,8 @@ func writeTarContents(out *tar.Writer, c *chart.Chart, prefix string) error {
// Save files // Save files
for _, f := range c.Files { for _, f := range c.Files {
n := filepath.Join(base, f.TypeUrl) n := filepath.Join(base, f.Name)
if err := writeToTar(out, n, f.Value); err != nil { if err := writeToTar(out, n, f.Data); err != nil {
return err return err
} }
} }

@ -22,8 +22,6 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/golang/protobuf/ptypes/any"
"k8s.io/helm/pkg/hapi/chart" "k8s.io/helm/pkg/hapi/chart"
) )
@ -42,8 +40,8 @@ func TestSave(t *testing.T) {
Values: &chart.Config{ Values: &chart.Config{
Raw: "ship: Pequod", Raw: "ship: Pequod",
}, },
Files: []*any.Any{ Files: []*chart.File{
{TypeUrl: "scheherazade/shahryar.txt", Value: []byte("1,001 Nights")}, {Name: "scheherazade/shahryar.txt", Data: []byte("1,001 Nights")},
}, },
} }
@ -69,7 +67,7 @@ func TestSave(t *testing.T) {
if c2.Values.Raw != c.Values.Raw { if c2.Values.Raw != c.Values.Raw {
t.Fatal("Values data did not match") t.Fatal("Values data did not match")
} }
if len(c2.Files) != 1 || c2.Files[0].TypeUrl != "scheherazade/shahryar.txt" { if len(c2.Files) != 1 || c2.Files[0].Name != "scheherazade/shahryar.txt" {
t.Fatal("Files data did not match") t.Fatal("Files data did not match")
} }
} }
@ -89,8 +87,8 @@ func TestSaveDir(t *testing.T) {
Values: &chart.Config{ Values: &chart.Config{
Raw: "ship: Pequod", Raw: "ship: Pequod",
}, },
Files: []*any.Any{ Files: []*chart.File{
{TypeUrl: "scheherazade/shahryar.txt", Value: []byte("1,001 Nights")}, {Name: "scheherazade/shahryar.txt", Data: []byte("1,001 Nights")},
}, },
} }
@ -109,7 +107,7 @@ func TestSaveDir(t *testing.T) {
if c2.Values.Raw != c.Values.Raw { if c2.Values.Raw != c.Values.Raw {
t.Fatal("Values data did not match") t.Fatal("Values data did not match")
} }
if len(c2.Files) != 1 || c2.Files[0].TypeUrl != "scheherazade/shahryar.txt" { if len(c2.Files) != 1 || c2.Files[0].Name != "scheherazade/shahryar.txt" {
t.Fatal("Files data did not match") t.Fatal("Files data did not match")
} }
} }

@ -417,8 +417,7 @@ func (v Values) PathValue(ypath string) (interface{}, error) {
table := yps[:ypsLen-1] table := yps[:ypsLen-1]
st := strings.Join(table, ".") st := strings.Join(table, ".")
// get the last element as a string key // get the last element as a string key
key := yps[ypsLen-1:] sk := yps[ypsLen-1:][0]
sk := string(key[0])
// get our table for table path // get our table for table path
t, err := v.Table(st) t, err := v.Table(st)
if err != nil { if err != nil {

@ -24,8 +24,6 @@ import (
"text/template" "text/template"
"time" "time"
"github.com/golang/protobuf/ptypes/any"
kversion "k8s.io/apimachinery/pkg/version" kversion "k8s.io/apimachinery/pkg/version"
"k8s.io/helm/pkg/hapi/chart" "k8s.io/helm/pkg/hapi/chart"
@ -90,7 +88,7 @@ where:
c := &chart.Chart{ c := &chart.Chart{
Metadata: &chart.Metadata{Name: "test"}, Metadata: &chart.Metadata{Name: "test"},
Templates: []*chart.Template{}, Templates: []*chart.File{},
Values: &chart.Config{Raw: chartValues}, Values: &chart.Config{Raw: chartValues},
Dependencies: []*chart.Chart{ Dependencies: []*chart.Chart{
{ {
@ -98,8 +96,8 @@ where:
Values: &chart.Config{Raw: ""}, Values: &chart.Config{Raw: ""},
}, },
}, },
Files: []*any.Any{ Files: []*chart.File{
{TypeUrl: "scheherazade/shahryar.txt", Value: []byte("1,001 Nights")}, {Name: "scheherazade/shahryar.txt", Data: []byte("1,001 Nights")},
}, },
} }
v := &chart.Config{Raw: overideValues} v := &chart.Config{Raw: overideValues}
@ -153,9 +151,7 @@ where:
t.Error("Expected Capabilities to have a Kube version") t.Error("Expected Capabilities to have a Kube version")
} }
var vals Values vals := res["Values"].(Values)
vals = res["Values"].(Values)
if vals["name"] != "Haroun" { if vals["name"] != "Haroun" {
t.Errorf("Expected 'Haroun', got %q (%v)", vals["name"], vals) t.Errorf("Expected 'Haroun', got %q (%v)", vals["name"], vals)
} }

@ -23,8 +23,6 @@ import (
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/hapi/chart" "k8s.io/helm/pkg/hapi/chart"
"github.com/golang/protobuf/ptypes/any"
) )
func TestSortTemplates(t *testing.T) { func TestSortTemplates(t *testing.T) {
@ -94,7 +92,7 @@ func TestRender(t *testing.T) {
Name: "moby", Name: "moby",
Version: "1.2.3", Version: "1.2.3",
}, },
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/test1", Data: []byte("{{.outer | title }} {{.inner | title}}")}, {Name: "templates/test1", Data: []byte("{{.outer | title }} {{.inner | title}}")},
{Name: "templates/test2", Data: []byte("{{.global.callme | lower }}")}, {Name: "templates/test2", Data: []byte("{{.global.callme | lower }}")},
{Name: "templates/test3", Data: []byte("{{.noValue}}")}, {Name: "templates/test3", Data: []byte("{{.noValue}}")},
@ -203,20 +201,20 @@ func TestParallelRenderInternals(t *testing.T) {
func TestAllTemplates(t *testing.T) { func TestAllTemplates(t *testing.T) {
ch1 := &chart.Chart{ ch1 := &chart.Chart{
Metadata: &chart.Metadata{Name: "ch1"}, Metadata: &chart.Metadata{Name: "ch1"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/foo", Data: []byte("foo")}, {Name: "templates/foo", Data: []byte("foo")},
{Name: "templates/bar", Data: []byte("bar")}, {Name: "templates/bar", Data: []byte("bar")},
}, },
Dependencies: []*chart.Chart{ Dependencies: []*chart.Chart{
{ {
Metadata: &chart.Metadata{Name: "laboratory mice"}, Metadata: &chart.Metadata{Name: "laboratory mice"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/pinky", Data: []byte("pinky")}, {Name: "templates/pinky", Data: []byte("pinky")},
{Name: "templates/brain", Data: []byte("brain")}, {Name: "templates/brain", Data: []byte("brain")},
}, },
Dependencies: []*chart.Chart{{ Dependencies: []*chart.Chart{{
Metadata: &chart.Metadata{Name: "same thing we do every night"}, Metadata: &chart.Metadata{Name: "same thing we do every night"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/innermost", Data: []byte("innermost")}, {Name: "templates/innermost", Data: []byte("innermost")},
}}, }},
}, },
@ -237,13 +235,13 @@ func TestRenderDependency(t *testing.T) {
toptpl := `Hello {{template "myblock"}}` toptpl := `Hello {{template "myblock"}}`
ch := &chart.Chart{ ch := &chart.Chart{
Metadata: &chart.Metadata{Name: "outerchart"}, Metadata: &chart.Metadata{Name: "outerchart"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/outer", Data: []byte(toptpl)}, {Name: "templates/outer", Data: []byte(toptpl)},
}, },
Dependencies: []*chart.Chart{ Dependencies: []*chart.Chart{
{ {
Metadata: &chart.Metadata{Name: "innerchart"}, Metadata: &chart.Metadata{Name: "innerchart"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/inner", Data: []byte(deptpl)}, {Name: "templates/inner", Data: []byte(deptpl)},
}, },
}, },
@ -278,7 +276,7 @@ func TestRenderNestedValues(t *testing.T) {
deepest := &chart.Chart{ deepest := &chart.Chart{
Metadata: &chart.Metadata{Name: "deepest"}, Metadata: &chart.Metadata{Name: "deepest"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: deepestpath, Data: []byte(`And this same {{.Values.what}} that smiles {{.Values.global.when}}`)}, {Name: deepestpath, Data: []byte(`And this same {{.Values.what}} that smiles {{.Values.global.when}}`)},
{Name: checkrelease, Data: []byte(`Tomorrow will be {{default "happy" .Release.Name }}`)}, {Name: checkrelease, Data: []byte(`Tomorrow will be {{default "happy" .Release.Name }}`)},
}, },
@ -287,7 +285,7 @@ func TestRenderNestedValues(t *testing.T) {
inner := &chart.Chart{ inner := &chart.Chart{
Metadata: &chart.Metadata{Name: "herrick"}, Metadata: &chart.Metadata{Name: "herrick"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: innerpath, Data: []byte(`Old {{.Values.who}} is still a-flyin'`)}, {Name: innerpath, Data: []byte(`Old {{.Values.who}} is still a-flyin'`)},
}, },
Values: &chart.Config{Raw: `who: "Robert"`}, Values: &chart.Config{Raw: `who: "Robert"`},
@ -296,7 +294,7 @@ func TestRenderNestedValues(t *testing.T) {
outer := &chart.Chart{ outer := &chart.Chart{
Metadata: &chart.Metadata{Name: "top"}, Metadata: &chart.Metadata{Name: "top"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: outerpath, Data: []byte(`Gather ye {{.Values.what}} while ye may`)}, {Name: outerpath, Data: []byte(`Gather ye {{.Values.what}} while ye may`)},
}, },
Values: &chart.Config{ Values: &chart.Config{
@ -363,21 +361,21 @@ global:
func TestRenderBuiltinValues(t *testing.T) { func TestRenderBuiltinValues(t *testing.T) {
inner := &chart.Chart{ inner := &chart.Chart{
Metadata: &chart.Metadata{Name: "Latium"}, Metadata: &chart.Metadata{Name: "Latium"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/Lavinia", Data: []byte(`{{.Template.Name}}{{.Chart.Name}}{{.Release.Name}}`)}, {Name: "templates/Lavinia", Data: []byte(`{{.Template.Name}}{{.Chart.Name}}{{.Release.Name}}`)},
{Name: "templates/From", Data: []byte(`{{.Files.author | printf "%s"}} {{.Files.Get "book/title.txt"}}`)}, {Name: "templates/From", Data: []byte(`{{.Files.author | printf "%s"}} {{.Files.Get "book/title.txt"}}`)},
}, },
Values: &chart.Config{Raw: ``}, Values: &chart.Config{Raw: ``},
Dependencies: []*chart.Chart{}, Dependencies: []*chart.Chart{},
Files: []*any.Any{ Files: []*chart.File{
{TypeUrl: "author", Value: []byte("Virgil")}, {Name: "author", Data: []byte("Virgil")},
{TypeUrl: "book/title.txt", Value: []byte("Aeneid")}, {Name: "book/title.txt", Data: []byte("Aeneid")},
}, },
} }
outer := &chart.Chart{ outer := &chart.Chart{
Metadata: &chart.Metadata{Name: "Troy"}, Metadata: &chart.Metadata{Name: "Troy"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/Aeneas", Data: []byte(`{{.Template.Name}}{{.Chart.Name}}{{.Release.Name}}`)}, {Name: "templates/Aeneas", Data: []byte(`{{.Template.Name}}{{.Chart.Name}}{{.Release.Name}}`)},
}, },
Values: &chart.Config{Raw: ``}, Values: &chart.Config{Raw: ``},
@ -415,7 +413,7 @@ func TestRenderBuiltinValues(t *testing.T) {
func TestAlterFuncMap(t *testing.T) { func TestAlterFuncMap(t *testing.T) {
c := &chart.Chart{ c := &chart.Chart{
Metadata: &chart.Metadata{Name: "conrad"}, Metadata: &chart.Metadata{Name: "conrad"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/quote", Data: []byte(`{{include "conrad/templates/_partial" . | indent 2}} dead.`)}, {Name: "templates/quote", Data: []byte(`{{include "conrad/templates/_partial" . | indent 2}} dead.`)},
{Name: "templates/_partial", Data: []byte(`{{.Release.Name}} - he`)}, {Name: "templates/_partial", Data: []byte(`{{.Release.Name}} - he`)},
}, },
@ -443,7 +441,7 @@ func TestAlterFuncMap(t *testing.T) {
reqChart := &chart.Chart{ reqChart := &chart.Chart{
Metadata: &chart.Metadata{Name: "conan"}, Metadata: &chart.Metadata{Name: "conan"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/quote", Data: []byte(`All your base are belong to {{ required "A valid 'who' is required" .Values.who }}`)}, {Name: "templates/quote", Data: []byte(`All your base are belong to {{ required "A valid 'who' is required" .Values.who }}`)},
{Name: "templates/bases", Data: []byte(`All {{ required "A valid 'bases' is required" .Values.bases }} of them!`)}, {Name: "templates/bases", Data: []byte(`All {{ required "A valid 'bases' is required" .Values.bases }} of them!`)},
}, },
@ -478,7 +476,7 @@ func TestAlterFuncMap(t *testing.T) {
tplChart := &chart.Chart{ tplChart := &chart.Chart{
Metadata: &chart.Metadata{Name: "TplFunction"}, Metadata: &chart.Metadata{Name: "TplFunction"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/base", Data: []byte(`Evaluate tpl {{tpl "Value: {{ .Values.value}}" .}}`)}, {Name: "templates/base", Data: []byte(`Evaluate tpl {{tpl "Value: {{ .Values.value}}" .}}`)},
}, },
Values: &chart.Config{Raw: ``}, Values: &chart.Config{Raw: ``},
@ -507,7 +505,7 @@ func TestAlterFuncMap(t *testing.T) {
tplChartWithFunction := &chart.Chart{ tplChartWithFunction := &chart.Chart{
Metadata: &chart.Metadata{Name: "TplFunction"}, Metadata: &chart.Metadata{Name: "TplFunction"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/base", Data: []byte(`Evaluate tpl {{tpl "Value: {{ .Values.value | quote}}" .}}`)}, {Name: "templates/base", Data: []byte(`Evaluate tpl {{tpl "Value: {{ .Values.value | quote}}" .}}`)},
}, },
Values: &chart.Config{Raw: ``}, Values: &chart.Config{Raw: ``},
@ -536,7 +534,7 @@ func TestAlterFuncMap(t *testing.T) {
tplChartWithInclude := &chart.Chart{ tplChartWithInclude := &chart.Chart{
Metadata: &chart.Metadata{Name: "TplFunction"}, Metadata: &chart.Metadata{Name: "TplFunction"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/base", Data: []byte(`{{ tpl "{{include ` + "`" + `TplFunction/templates/_partial` + "`" + ` . | quote }}" .}}`)}, {Name: "templates/base", Data: []byte(`{{ tpl "{{include ` + "`" + `TplFunction/templates/_partial` + "`" + ` . | quote }}" .}}`)},
{Name: "templates/_partial", Data: []byte(`{{.Template.Name}}`)}, {Name: "templates/_partial", Data: []byte(`{{.Template.Name}}`)},
}, },

@ -1,54 +1,17 @@
package chart package chart
import google_protobuf "github.com/golang/protobuf/ptypes/any"
// Chart is a helm package that contains metadata, a default config, zero or more // Chart is a helm package that contains metadata, a default config, zero or more
// optionally parameterizable templates, and zero or more charts (dependencies). // optionally parameterizable templates, and zero or more charts (dependencies).
type Chart struct { type Chart struct {
// Contents of the Chartfile. // Contents of the Chartfile.
Metadata *Metadata `json:"metadata,omitempty"` Metadata *Metadata `json:"metadata,omitempty"`
// Templates for this chart. // Templates for this chart.
Templates []*Template `json:"templates,omitempty"` Templates []*File `json:"templates,omitempty"`
// Charts that this chart depends on. // Charts that this chart depends on.
Dependencies []*Chart `json:"dependencies,omitempty"` Dependencies []*Chart `json:"dependencies,omitempty"`
// Default config for this template. // Default config for this template.
Values *Config `json:"values,omitempty"` Values *Config `json:"values,omitempty"`
// Miscellaneous files in a chart archive, // Miscellaneous files in a chart archive,
// e.g. README, LICENSE, etc. // e.g. README, LICENSE, etc.
Files []*google_protobuf.Any `json:"files,omitempty"` Files []*File `json:"files,omitempty"`
}
func (m *Chart) GetMetadata() *Metadata {
if m != nil {
return m.Metadata
}
return nil
}
func (m *Chart) GetTemplates() []*Template {
if m != nil {
return m.Templates
}
return nil
}
func (m *Chart) GetDependencies() []*Chart {
if m != nil {
return m.Dependencies
}
return nil
}
func (m *Chart) GetValues() *Config {
if m != nil {
return m.Values
}
return nil
}
func (m *Chart) GetFiles() []*google_protobuf.Any {
if m != nil {
return m.Files
}
return nil
} }

@ -1,26 +1,12 @@
package chart package chart
// Template represents a template as a name/value pair. // File represents a file as a name/value pair.
// //
// By convention, name is a relative path within the scope of the chart's // By convention, name is a relative path within the scope of the chart's
// base directory. // base directory.
type Template struct { type File struct {
// Name is the path-like name of the template. // Name is the path-like name of the template.
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
// Data is the template as byte data. // Data is the template as byte data.
Data []byte `json:"data,omitempty"` Data []byte `json:"data,omitempty"`
} }
func (m *Template) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *Template) GetData() []byte {
if m != nil {
return m.Data
}
return nil
}

@ -211,7 +211,7 @@ func ReleaseMock(opts *MockReleaseOptions) *release.Release {
Name: "foo", Name: "foo",
Version: "0.1.0-beta.1", Version: "0.1.0-beta.1",
}, },
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/foo.tpl", Data: []byte(MockManifest)}, {Name: "templates/foo.tpl", Data: []byte(MockManifest)},
}, },
} }

@ -113,7 +113,7 @@ func Templates(linter *support.Linter, values []byte, namespace string, strict b
// NOTE: disabled for now, Refs https://github.com/kubernetes/helm/issues/1037 // NOTE: disabled for now, Refs https://github.com/kubernetes/helm/issues/1037
// linter.RunLinterRule(support.WarningSev, path, validateQuotes(string(preExecutedTemplate))) // linter.RunLinterRule(support.WarningSev, path, validateQuotes(string(preExecutedTemplate)))
renderedContent := renderedContentMap[filepath.Join(chart.GetMetadata().Name, fileName)] renderedContent := renderedContentMap[filepath.Join(chart.Metadata.Name, fileName)]
var yamlStruct K8sYamlStruct var yamlStruct K8sYamlStruct
// Even though K8sYamlStruct only defines Metadata namespace, an error in any other // Even though K8sYamlStruct only defines Metadata namespace, an error in any other
// key will be raised as well // key will be raised as well

@ -217,7 +217,7 @@ func chartStub() *chart.Chart {
Metadata: &chart.Metadata{ Metadata: &chart.Metadata{
Name: "nemo", Name: "nemo",
}, },
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")}, {Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithTestSuccessHook)}, {Name: "templates/hooks", Data: []byte(manifestWithTestSuccessHook)},
}, },

@ -267,7 +267,7 @@ func (s *ReleaseServer) renderResources(ch *chart.Chart, values chartutil.Values
} }
} }
s.Log("rendering %s chart using values", ch.GetMetadata().Name) s.Log("rendering %s chart using values", ch.Metadata.Name)
renderer := s.engine(ch) renderer := s.engine(ch)
files, err := renderer.Render(ch, values) files, err := renderer.Render(ch, values)
if err != nil { if err != nil {

@ -112,7 +112,7 @@ func buildChart(opts ...chartOption) *chart.Chart {
Name: "hello", Name: "hello",
}, },
// This adds a basic template and hooks. // This adds a basic template and hooks.
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")}, {Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithHook)}, {Name: "templates/hooks", Data: []byte(manifestWithHook)},
}, },
@ -140,7 +140,7 @@ func withDependency(dependencyOpts ...chartOption) chartOption {
func withNotes(notes string) chartOption { func withNotes(notes string) chartOption {
return func(opts *chartOptions) { return func(opts *chartOptions) {
opts.Templates = append(opts.Templates, &chart.Template{ opts.Templates = append(opts.Templates, &chart.File{
Name: "templates/NOTES.txt", Name: "templates/NOTES.txt",
Data: []byte(notes), Data: []byte(notes),
}) })
@ -149,7 +149,7 @@ func withNotes(notes string) chartOption {
func withSampleTemplates() chartOption { func withSampleTemplates() chartOption {
return func(opts *chartOptions) { return func(opts *chartOptions) {
sampleTemplates := []*chart.Template{ sampleTemplates := []*chart.File{
// This adds basic templates and partials. // This adds basic templates and partials.
{Name: "templates/goodbye", Data: []byte("goodbye: world")}, {Name: "templates/goodbye", Data: []byte("goodbye: world")},
{Name: "templates/empty", Data: []byte("")}, {Name: "templates/empty", Data: []byte("")},
@ -361,7 +361,7 @@ func releaseWithKeepStub(rlsName string) *release.Release {
Metadata: &chart.Metadata{ Metadata: &chart.Metadata{
Name: "bunnychart", Name: "bunnychart",
}, },
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/configmap", Data: []byte(manifestWithKeep)}, {Name: "templates/configmap", Data: []byte(manifestWithKeep)},
}, },
} }

@ -36,7 +36,7 @@ func TestUpdateRelease(t *testing.T) {
Name: rel.Name, Name: rel.Name,
Chart: &chart.Chart{ Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")}, {Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)}, {Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)},
}, },
@ -108,7 +108,7 @@ func TestUpdateRelease_ResetValues(t *testing.T) {
Name: rel.Name, Name: rel.Name,
Chart: &chart.Chart{ Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")}, {Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)}, {Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)},
}, },
@ -133,7 +133,7 @@ func TestUpdateRelease_ComplexReuseValues(t *testing.T) {
Namespace: "spaced", Namespace: "spaced",
Chart: &chart.Chart{ Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")}, {Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithHook)}, {Name: "templates/hooks", Data: []byte(manifestWithHook)},
}, },
@ -153,7 +153,7 @@ func TestUpdateRelease_ComplexReuseValues(t *testing.T) {
Name: rel.Name, Name: rel.Name,
Chart: &chart.Chart{ Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")}, {Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)}, {Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)},
}, },
@ -177,7 +177,7 @@ func TestUpdateRelease_ComplexReuseValues(t *testing.T) {
Name: rel.Name, Name: rel.Name,
Chart: &chart.Chart{ Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")}, {Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)}, {Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)},
}, },
@ -203,7 +203,7 @@ func TestUpdateRelease_ComplexReuseValues(t *testing.T) {
Name: rel.Name, Name: rel.Name,
Chart: &chart.Chart{ Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")}, {Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)}, {Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)},
}, },
@ -233,7 +233,7 @@ func TestUpdateRelease_ReuseValues(t *testing.T) {
Name: rel.Name, Name: rel.Name,
Chart: &chart.Chart{ Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")}, {Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)}, {Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)},
}, },
@ -270,7 +270,7 @@ func TestUpdateRelease_ResetReuseValues(t *testing.T) {
Name: rel.Name, Name: rel.Name,
Chart: &chart.Chart{ Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")}, {Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)}, {Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)},
}, },
@ -301,7 +301,7 @@ func TestUpdateReleaseFailure(t *testing.T) {
DisableHooks: true, DisableHooks: true,
Chart: &chart.Chart{ Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/something", Data: []byte("hello: world")}, {Name: "templates/something", Data: []byte("hello: world")},
}, },
}, },
@ -343,7 +343,7 @@ func TestUpdateReleaseFailure_Force(t *testing.T) {
DisableHooks: true, DisableHooks: true,
Chart: &chart.Chart{ Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/something", Data: []byte("text: 'Did you ever hear the tragedy of Darth Plagueis the Wise? I thought not. Its not a story the Jedi would tell you. Its a Sith legend. Darth Plagueis was a Dark Lord of the Sith, so powerful and so wise he could use the Force to influence the Midichlorians to create life... He had such a knowledge of the Dark Side that he could even keep the ones he cared about from dying. The Dark Side of the Force is a pathway to many abilities some consider to be unnatural. He became so powerful... The only thing he was afraid of was losing his power, which eventually, of course, he did. Unfortunately, he taught his apprentice everything he knew, then his apprentice killed him in his sleep. Ironic. He could save others from death, but not himself.'")}, {Name: "templates/something", Data: []byte("text: 'Did you ever hear the tragedy of Darth Plagueis the Wise? I thought not. Its not a story the Jedi would tell you. Its a Sith legend. Darth Plagueis was a Dark Lord of the Sith, so powerful and so wise he could use the Force to influence the Midichlorians to create life... He had such a knowledge of the Dark Side that he could even keep the ones he cared about from dying. The Dark Side of the Force is a pathway to many abilities some consider to be unnatural. He became so powerful... The only thing he was afraid of was losing his power, which eventually, of course, he did. Unfortunately, he taught his apprentice everything he knew, then his apprentice killed him in his sleep. Ironic. He could save others from death, but not himself.'")},
}, },
}, },
@ -385,7 +385,7 @@ func TestUpdateReleaseNoHooks(t *testing.T) {
DisableHooks: true, DisableHooks: true,
Chart: &chart.Chart{ Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")}, {Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)}, {Name: "templates/hooks", Data: []byte(manifestWithUpgradeHooks)},
}, },

Loading…
Cancel
Save