@@ -62,57 +62,41 @@ func (d *Downloader) getRepoInfo(name string, ns string) (*repo.Entry, error) {
62
62
return entry , err
63
63
}
64
64
65
- // cal the local path for a chart
66
- // name: <repo>/<name>
67
- func getChartPath (name , version string ) string {
68
- new := strings .Replace (name , "/" , "-" , - 1 )
69
- return fmt .Sprintf ("%s/%s-%s.tgz" , ChartsDir , new , version )
70
- }
71
-
65
+ // downloadChart download a chart from helm repo to local disk and return the path
66
+ // name: <repo>/<chart>
72
67
func (d * Downloader ) downloadChart (name string , version string ) (string , error ) {
73
68
log := d .log
74
69
75
- repo , chart := getRepoAndChart (name )
76
- if repo == "" && chart == "" {
70
+ repoName , chart := getRepoAndChart (name )
71
+ if repoName == "" && chart == "" {
77
72
return "" , errors .New ("cannot parse chart name" )
78
73
}
79
-
80
74
log .Info ("get chart" , "name" , name , "version" , version )
81
75
82
76
dir := ChartsDir
83
-
84
- if version != "" {
85
- // we can check the path now
86
- checkPath := getChartPath (name , version )
87
- if _ , err := os .Stat (checkPath ); ! os .IsNotExist (err ) {
88
- log .Info ("chart already downloaded, use it" , "path" , checkPath )
89
- return checkPath , nil
77
+ if _ , err := os .Stat (dir ); os .IsNotExist (err ) {
78
+ if err = os .MkdirAll (dir , 0755 ); err != nil {
79
+ return "" , err
90
80
}
81
+ log .Info ("helm charts dir not exist, create it: " , "dir" , dir )
91
82
}
92
83
93
- entry , err := d .getRepoInfo (repo , d .ns )
84
+ entry , err := d .getRepoInfo (repoName , d .ns )
94
85
if err != nil {
95
86
log .Error (err , "get chartrepo error" )
96
87
return "" , err
97
88
}
98
89
99
- chartResourceName := fmt .Sprintf ("%s.%s" , strings .ToLower (chart ), repo )
100
-
101
- path , err := chartrepo .GetChart (chartResourceName , version , d .ns , d .cfg )
90
+ chartResourceName := fmt .Sprintf ("%s.%s" , strings .ToLower (chart ), repoName )
91
+ cv , err := chartrepo .GetChart (chartResourceName , version , d .ns , d .cfg )
102
92
if err != nil {
103
93
log .Error (err , "get chart error" )
104
94
return "" , err
105
95
}
106
96
107
- if _ , err := os .Stat (dir ); os .IsNotExist (err ) {
108
- if err = os .MkdirAll (dir , 0755 ); err != nil {
109
- return "" , err
110
- }
111
- log .Info ("dir not exist, create it: " , "dir" , dir )
112
- }
113
-
97
+ path := cv .URLs [0 ]
114
98
fileName := strings .Split (path , "/" )[1 ]
115
- filePath := fmt .Sprintf ("%s/%s-%s" , dir , repo , fileName )
99
+ filePath := fmt .Sprintf ("%s/%s-%s-%s " , dir , repoName , cv . Digest , fileName )
116
100
117
101
if _ , err := os .Stat (filePath ); ! os .IsNotExist (err ) {
118
102
log .Info ("chart already downloaded, use it" , "path" , filePath )
@@ -124,6 +108,8 @@ func (d *Downloader) downloadChart(name string, version string) (string, error)
124
108
return "" , err
125
109
}
126
110
111
+ log .Info ("download chart to disk" , "path" , filePath )
112
+
127
113
return filePath , nil
128
114
129
115
}
0 commit comments