@@ -27,8 +27,8 @@ import (
2727)
2828
2929const (
30- chartCollection = "charts"
31- chartReadmeCollection = "readmes "
30+ chartCollection = "charts"
31+ chartFilesCollection = "files "
3232)
3333
3434type importChartFilesJob struct {
@@ -84,8 +84,8 @@ func main() {
8484// Syncing is performed in the following steps:
8585// 1. Update database to match chart metadata from index
8686// 2. Concurrently process icons for charts (concurrently)
87- // 3. Concurrently process the README for the latest chart version of each chart
88- // 4. Concurrently process READMEs for historic chart versions
87+ // 3. Concurrently process the README and values.yaml for the latest chart version of each chart
88+ // 4. Concurrently process READMEs and values.yaml for historic chart versions
8989//
9090// These steps are processed in this way to ensure relevant chart data is
9191// imported into the database as fast as possible. E.g. we want all icons for
@@ -231,7 +231,7 @@ func importCharts(charts []chart) error {
231231 // Upsert pairs of selectors, charts
232232 bulk .Upsert (pairs ... )
233233
234- // Remove charts no longer existing in index
234+ // Remove charts no longer existing in index
235235 bulk .RemoveAll (bson.M {
236236 "_id" : bson.M {
237237 "$nin" : chartIDs ,
@@ -252,9 +252,9 @@ func importWorker(wg *sync.WaitGroup, icons <-chan chart, chartFiles <-chan impo
252252 }
253253 }
254254 for j := range chartFiles {
255- log .WithFields (log.Fields {"name" : j .Name , "version" : j .ChartVersion .Version }).Debug ("importing readme" )
256- if err := fetchAndImportReadme (j .Name , j .Repo , j .ChartVersion ); err != nil {
257- log .WithFields (log.Fields {"name" : j .Name , "version" : j .ChartVersion .Version }).WithError (err ).Error ("failed to import readme " )
255+ log .WithFields (log.Fields {"name" : j .Name , "version" : j .ChartVersion .Version }).Debug ("importing readme and values " )
256+ if err := fetchAndImportFiles (j .Name , j .Repo , j .ChartVersion ); err != nil {
257+ log .WithFields (log.Fields {"name" : j .Name , "version" : j .ChartVersion .Version }).WithError (err ).Error ("failed to import files " )
258258 }
259259 }
260260}
@@ -297,15 +297,15 @@ func fetchAndImportIcon(c chart) error {
297297 return db .C (chartCollection ).UpdateId (c .ID , bson.M {"$set" : bson.M {"raw_icon" : b .Bytes ()}})
298298}
299299
300- func fetchAndImportReadme (name string , r repo , cv chartVersion ) error {
301- chartReadmeID := fmt .Sprintf ("%s/%s-%s" , r .Name , name , cv .Version )
300+ func fetchAndImportFiles (name string , r repo , cv chartVersion ) error {
301+ chartFilesID := fmt .Sprintf ("%s/%s-%s" , r .Name , name , cv .Version )
302302 db , closer := dbSession .DB ()
303303 defer closer ()
304- if err := db .C (chartReadmeCollection ).FindId (chartReadmeID ).One (& chartReadme {}); err == nil {
305- log .WithFields (log.Fields {"name" : name , "version" : cv .Version }).Debug ("skipping existing readme " )
304+ if err := db .C (chartFilesCollection ).FindId (chartFilesID ).One (& chartFiles {}); err == nil {
305+ log .WithFields (log.Fields {"name" : name , "version" : cv .Version }).Debug ("skipping existing files " )
306306 return nil
307307 }
308- log .WithFields (log.Fields {"name" : name , "version" : cv .Version }).Debug ("fetching readme " )
308+ log .WithFields (log.Fields {"name" : name , "version" : cv .Version }).Debug ("fetching files " )
309309
310310 url := chartTarballURL (r , cv )
311311 req , err := http .NewRequest ("GET" , url , nil )
@@ -333,22 +333,37 @@ func fetchAndImportReadme(name string, r repo, cv chartVersion) error {
333333 tarf := tar .NewReader (gzf )
334334
335335 readmeFileName := name + "/README.md"
336- readme , err := extractFileFromTarball (readmeFileName , tarf )
337- if err != nil && ! strings .Contains (err .Error (), "file not found" ) {
338- return err
339- }
336+ valuesFileName := name + "/values.yaml"
337+ fileNames := []string {valuesFileName , readmeFileName }
340338
341- // Even if the readme doesn't exist, we create an empty entry to avoid
342- // refetching for this chart version in the future
343- if readme == "" {
344- log .WithFields (log.Fields {"name" : name , "version" : cv .Version }).Info ("readme not found" )
345- }
339+ files , err := getFiles (cv , name , fileNames , tarf )
340+ values := files [0 ]
341+ readme := files [1 ]
346342
347- db .C (chartReadmeCollection ).Insert (chartReadme { chartReadmeID , readme })
343+ db .C (chartFilesCollection ).Insert (chartFiles { chartFilesID , readme , values })
348344
349345 return nil
350346}
351347
348+ func getFiles (cv chartVersion , name string , filenames []string , tarf * tar.Reader ) ([]string , error ) {
349+ var files []string
350+
351+ for _ , filename := range filenames {
352+ file , err := extractFileFromTarball (filename , tarf )
353+ if err != nil && ! strings .Contains (err .Error (), "file not found" ) {
354+ return nil , err
355+ }
356+
357+ if file == "" {
358+ log .WithFields (log.Fields {"name" : name , "version" : cv .Version }).Info (filename + " not found" )
359+ }
360+
361+ files = append (files , file )
362+ }
363+
364+ return files , nil
365+ }
366+
352367func chartTarballURL (r repo , cv chartVersion ) string {
353368 source := cv .URLs [0 ]
354369 if _ , err := url .ParseRequestURI (source ); err != nil {
0 commit comments