@@ -147,7 +147,20 @@ func CreateChart(projectDir string, opts CreateChartOptions) (*scaffold.Resource
147
147
if err != nil {
148
148
return nil , nil , err
149
149
}
150
- log .Infof ("Created %s/%s/" , HelmChartsDir , c .GetMetadata ().GetName ())
150
+
151
+ relChartPath := filepath .Join (HelmChartsDir , c .GetMetadata ().GetName ())
152
+ absChartPath := filepath .Join (projectDir , relChartPath )
153
+ if err := fetchChartDependencies (absChartPath ); err != nil {
154
+ return nil , nil , err
155
+ }
156
+
157
+ // Reload chart in case dependencies changed
158
+ c , err = chartutil .Load (absChartPath )
159
+ if err != nil {
160
+ return nil , nil , err
161
+ }
162
+
163
+ log .Infof ("Created %s" , relChartPath )
151
164
return r , c , nil
152
165
}
153
166
@@ -172,7 +185,7 @@ func scaffoldChart(destDir, apiVersion, kind string) (*scaffold.Resource, *chart
172
185
return nil , nil , err
173
186
}
174
187
175
- chart , err := chartutil .LoadDir (chartPath )
188
+ chart , err := chartutil .Load (chartPath )
176
189
if err != nil {
177
190
return nil , nil , err
178
191
}
@@ -211,17 +224,7 @@ func fetchChart(destDir string, opts CreateChartOptions) (*scaffold.Resource, *c
211
224
}
212
225
213
226
func createChartFromDisk (destDir , source string , isDir bool ) (* chart.Chart , error ) {
214
- var (
215
- chart * chart.Chart
216
- err error
217
- )
218
-
219
- // If source is a file or directory, attempt to load it
220
- if isDir {
221
- chart , err = chartutil .LoadDir (source )
222
- } else {
223
- chart , err = chartutil .LoadFile (source )
224
- }
227
+ chart , err := chartutil .Load (source )
225
228
if err != nil {
226
229
return nil , err
227
230
}
@@ -279,6 +282,22 @@ func createChartFromRemote(destDir string, opts CreateChartOptions) (*chart.Char
279
282
return createChartFromDisk (destDir , chartArchive , false )
280
283
}
281
284
285
+ func fetchChartDependencies (chartPath string ) error {
286
+ helmHome , ok := os .LookupEnv (helmenv .HomeEnvVar )
287
+ if ! ok {
288
+ helmHome = helmenv .DefaultHelmHome
289
+ }
290
+ getters := getter .All (helmenv.EnvSettings {})
291
+
292
+ man := & downloader.Manager {
293
+ Out : ioutil .Discard ,
294
+ ChartPath : chartPath ,
295
+ HelmHome : helmpath .Home (helmHome ),
296
+ Getters : getters ,
297
+ }
298
+ return man .Build ()
299
+ }
300
+
282
301
// GenerateRoleRules generates lists of cluster-scoped and namespace-scoped rules
283
302
// from the provided helm chart. It renders a release manifest using the chart's
284
303
// default values and uses the Kubernetes discovery API to lookup each resource
0 commit comments