@ -53,10 +53,10 @@ func Load(name string) (*chart.Chart, error) {
return LoadFile ( name )
}
// af ile represents an archive file buffered for later processing.
type af ile struct {
n ame string
d ata [ ] byte
// BufferedF ile represents an archive file buffered for later processing.
type BufferedF ile struct {
N ame string
D ata [ ] byte
}
// LoadArchive loads from a reader containing a compressed tar archive.
@ -67,7 +67,7 @@ func LoadArchive(in io.Reader) (*chart.Chart, error) {
}
defer unzipped . Close ( )
files := [ ] * af ile{ }
files := [ ] * BufferedF ile{ }
tr := tar . NewReader ( unzipped )
for {
b := bytes . NewBuffer ( nil )
@ -105,7 +105,7 @@ func LoadArchive(in io.Reader) (*chart.Chart, error) {
return & chart . Chart { } , err
}
files = append ( files , & afile{ name : n , d ata: b . Bytes ( ) } )
files = append ( files , & BufferedFile{ Name : n , D ata: b . Bytes ( ) } )
b . Reset ( )
}
@ -113,41 +113,42 @@ func LoadArchive(in io.Reader) (*chart.Chart, error) {
return nil , errors . New ( "no files in chart archive" )
}
return l oadFiles( files )
return L oadFiles( files )
}
func loadFiles ( files [ ] * afile ) ( * chart . Chart , error ) {
// LoadFiles loads from in-memory files.
func LoadFiles ( files [ ] * BufferedFile ) ( * chart . Chart , error ) {
c := & chart . Chart { }
subcharts := map [ string ] [ ] * af ile{ }
subcharts := map [ string ] [ ] * BufferedF ile{ }
for _ , f := range files {
if f . n ame == "Chart.yaml" {
m , err := UnmarshalChartfile ( f . d ata)
if f . N ame == "Chart.yaml" {
m , err := UnmarshalChartfile ( f . D ata)
if err != nil {
return c , err
}
c . Metadata = m
} else if f . n ame == "values.toml" {
} else if f . N ame == "values.toml" {
return c , errors . New ( "values.toml is illegal as of 2.0.0-alpha.2" )
} else if f . n ame == "values.yaml" {
c . Values = & chart . Config { Raw : string ( f . d ata) }
} else if strings . HasPrefix ( f . n ame, "templates/" ) {
c . Templates = append ( c . Templates , & chart . Template { Name : f . name, Data : f . d ata} )
} else if strings . HasPrefix ( f . n ame, "charts/" ) {
if filepath . Ext ( f . n ame) == ".prov" {
c . Files = append ( c . Files , & any . Any { TypeUrl : f . name, Value : f . d ata} )
} else if f . N ame == "values.yaml" {
c . Values = & chart . Config { Raw : string ( f . D ata) }
} else if strings . HasPrefix ( f . N ame, "templates/" ) {
c . Templates = append ( c . Templates , & chart . Template { Name : f . Name, Data : f . D ata} )
} else if strings . HasPrefix ( f . N ame, "charts/" ) {
if filepath . Ext ( f . N ame) == ".prov" {
c . Files = append ( c . Files , & any . Any { TypeUrl : f . Name, Value : f . D ata} )
continue
}
cname := strings . TrimPrefix ( f . n ame, "charts/" )
cname := strings . TrimPrefix ( f . N ame, "charts/" )
if strings . IndexAny ( cname , "._" ) == 0 {
// Ignore charts/ that start with . or _.
continue
}
parts := strings . SplitN ( cname , "/" , 2 )
scname := parts [ 0 ]
subcharts [ scname ] = append ( subcharts [ scname ] , & afile{ name : cname , data : f . d ata} )
subcharts [ scname ] = append ( subcharts [ scname ] , & BufferedFile{ Name : cname , Data : f . D ata} )
} else {
c . Files = append ( c . Files , & any . Any { TypeUrl : f . name, Value : f . d ata} )
c . Files = append ( c . Files , & any . Any { TypeUrl : f . Name, Value : f . D ata} )
}
}
@ -166,25 +167,25 @@ func loadFiles(files []*afile) (*chart.Chart, error) {
continue
} else if filepath . Ext ( n ) == ".tgz" {
file := files [ 0 ]
if file . n ame != n {
return c , fmt . Errorf ( "error unpacking tar in %s: expected %s, got %s" , c . Metadata . Name , n , file . n ame)
if file . N ame != n {
return c , fmt . Errorf ( "error unpacking tar in %s: expected %s, got %s" , c . Metadata . Name , n , file . N ame)
}
// Untar the chart and add to c.Dependencies
b := bytes . NewBuffer ( file . d ata)
b := bytes . NewBuffer ( file . D ata)
sc , err = LoadArchive ( b )
} else {
// We have to trim the prefix off of every file, and ignore any file
// that is in charts/, but isn't actually a chart.
buff := make ( [ ] * af ile, 0 , len ( files ) )
buff := make ( [ ] * BufferedF ile, 0 , len ( files ) )
for _ , f := range files {
parts := strings . SplitN ( f . n ame, "/" , 2 )
parts := strings . SplitN ( f . N ame, "/" , 2 )
if len ( parts ) < 2 {
continue
}
f . n ame = parts [ 1 ]
f . N ame = parts [ 1 ]
buff = append ( buff , f )
}
sc , err = l oadFiles( buff )
sc , err = L oadFiles( buff )
}
if err != nil {
@ -237,7 +238,7 @@ func LoadDir(dir string) (*chart.Chart, error) {
}
rules . AddDefaults ( )
files := [ ] * af ile{ }
files := [ ] * BufferedF ile{ }
topdir += string ( filepath . Separator )
err = symwalk . Walk ( topdir , func ( name string , fi os . FileInfo , err error ) error {
@ -268,12 +269,12 @@ func LoadDir(dir string) (*chart.Chart, error) {
return fmt . Errorf ( "error reading %s: %s" , n , err )
}
files = append ( files , & afile{ name : n , d ata: data } )
files = append ( files , & BufferedFile{ Name : n , D ata: data } )
return nil
} )
if err != nil {
return c , err
}
return l oadFiles( files )
return L oadFiles( files )
}