@@ -215,13 +215,14 @@ func makeChart(appname, targetDir string) error {
215215 return ioutil .WriteFile (filepath .Join (targetDir , "Chart.yaml" ), hmetadata , 0644 )
216216}
217217
218- func helmRender (appname string , targetDir string , composeFiles []string , settingsFile []string , env map [string ]string , beta1 bool ) error {
218+ func helmRender (appname string , targetDir string , composeFiles []string , settingsFile []string , env map [string ]string , stackVersion string ) error {
219219 rendered , err := Render (appname , composeFiles , settingsFile , env )
220220 if err != nil {
221221 return err
222222 }
223223 var stack interface {}
224- if ! beta1 {
224+ switch stackVersion {
225+ case V1Beta2 :
225226 stackSpec := conversion .FromComposeConfig (rendered )
226227 stack = v1beta2.Stack {
227228 TypeMeta : metav1.TypeMeta {
@@ -233,7 +234,7 @@ func helmRender(appname string, targetDir string, composeFiles []string, setting
233234 },
234235 Spec : stackSpec ,
235236 }
236- } else {
237+ case V1Beta1 :
237238 composeFile , err := yaml .Marshal (rendered )
238239 if err != nil {
239240 return err
@@ -250,6 +251,8 @@ func helmRender(appname string, targetDir string, composeFiles []string, setting
250251 ComposeFile : string (composeFile ),
251252 },
252253 }
254+ default :
255+ return fmt .Errorf ("invalid stack version %q" , stackVersion )
253256 }
254257 stackData , err := yaml .Marshal (stack )
255258 if err != nil {
@@ -259,7 +262,7 @@ func helmRender(appname string, targetDir string, composeFiles []string, setting
259262}
260263
261264//makeStack converts data into a helm template for a stack
262- func makeStack (appname string , targetDir string , data []byte , beta1 bool ) error {
265+ func makeStack (appname string , targetDir string , data []byte , stackVersion string ) error {
263266 parsed , err := loader .ParseYAML (data )
264267 if err != nil {
265268 return errors .Wrap (err , "failed to parse template compose" )
@@ -270,7 +273,8 @@ func makeStack(appname string, targetDir string, data []byte, beta1 bool) error
270273 }
271274 os .Mkdir (filepath .Join (targetDir , "templates" ), 0755 )
272275 var stack interface {}
273- if ! beta1 {
276+ switch stackVersion {
277+ case V1Beta2 :
274278 stackSpec := templateconversion .FromComposeConfig (rendered )
275279 stack = templatev1beta2.Stack {
276280 TypeMeta : metav1.TypeMeta {
@@ -283,7 +287,7 @@ func makeStack(appname string, targetDir string, data []byte, beta1 bool) error
283287 },
284288 Spec : stackSpec ,
285289 }
286- } else {
290+ case V1Beta1 :
287291 composeFile , err := yaml .Marshal (rendered )
288292 if err != nil {
289293 return err
@@ -301,6 +305,8 @@ func makeStack(appname string, targetDir string, data []byte, beta1 bool) error
301305 ComposeFile : string (composeFile ),
302306 },
303307 }
308+ default :
309+ return fmt .Errorf ("invalid stack version %q" , stackVersion )
304310 }
305311 stackData , err := yaml .Marshal (stack )
306312 if err != nil {
@@ -325,7 +331,6 @@ func makeStack(appname string, targetDir string, data []byte, beta1 bool) error
325331// Helm renders an app as an Helm Chart
326332func Helm (appname string , composeFiles []string , settingsFile []string , env map [string ]string , render bool , stackVersion string ) error {
327333 targetDir := internal .AppNameFromDir (appname ) + ".chart"
328- beta1 := stackVersion == V1Beta1
329334 if err := os .Mkdir (targetDir , 0755 ); err != nil && ! os .IsExist (err ) {
330335 return errors .Wrap (err , "failed to create Chart directory" )
331336 }
@@ -334,7 +339,7 @@ func Helm(appname string, composeFiles []string, settingsFile []string, env map[
334339 return err
335340 }
336341 if render {
337- return helmRender (appname , targetDir , composeFiles , settingsFile , env , beta1 )
342+ return helmRender (appname , targetDir , composeFiles , settingsFile , env , stackVersion )
338343 }
339344 data , err := ioutil .ReadFile (filepath .Join (appname , internal .ComposeFileName ))
340345 if err != nil {
@@ -344,7 +349,7 @@ func Helm(appname string, composeFiles []string, settingsFile []string, env map[
344349 if err != nil {
345350 return errors .Wrap (err , "failed to parse docker-compose.yml, maybe because it is a template" )
346351 }
347- err = makeStack (appname , targetDir , data , beta1 )
352+ err = makeStack (appname , targetDir , data , stackVersion )
348353 if err != nil {
349354 return err
350355 }
0 commit comments