forked from LaconicNetwork/kompose
Merge pull request #28 from janetkuo/chart-hint-verify
Validate flags when generating charts, and prints message for file created
This commit is contained in:
commit
8871baf9be
@ -562,12 +562,16 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
||||
createD := c.BoolT("deployment")
|
||||
createDS := c.BoolT("daemonset")
|
||||
createRS := c.BoolT("replicaset")
|
||||
createChart := c.BoolT("chart")
|
||||
singleOutput := len(outFile) != 0 || toStdout
|
||||
|
||||
// Validate the flags
|
||||
if len(outFile) != 0 && toStdout {
|
||||
logrus.Fatalf("Error: --out and --stdout can't be set at the same time")
|
||||
}
|
||||
if createChart && toStdout {
|
||||
logrus.Fatalf("Error: chart cannot be generated when --stdout is specified")
|
||||
}
|
||||
if singleOutput {
|
||||
count := 0
|
||||
if createD {
|
||||
@ -593,8 +597,11 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
||||
logrus.Fatalf("Failed to parse the compose project from %s: %v", composeFile, err)
|
||||
}
|
||||
|
||||
f := createOutFile(outFile)
|
||||
defer f.Close()
|
||||
var f *os.File
|
||||
if !createChart {
|
||||
f = createOutFile(outFile)
|
||||
defer f.Close()
|
||||
}
|
||||
|
||||
var mServices map[string][]byte = make(map[string][]byte)
|
||||
var mReplicationControllers map[string][]byte = make(map[string][]byte)
|
||||
@ -602,8 +609,10 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
||||
var mDaemonSets map[string][]byte = make(map[string][]byte)
|
||||
var mReplicaSets map[string][]byte = make(map[string][]byte)
|
||||
var serviceLinks []string
|
||||
var svcnames []string
|
||||
|
||||
for name, service := range p.Configs {
|
||||
svcnames = append(svcnames, name)
|
||||
|
||||
checkUnsupportedKey(*service)
|
||||
|
||||
@ -813,13 +822,10 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
||||
fmt.Fprintf(os.Stdout, "file %q created\n", outFile)
|
||||
}
|
||||
|
||||
/* Need to iterate through one more time to ensure we capture all service/rc */
|
||||
for name := range p.Configs {
|
||||
if c.BoolT("chart") {
|
||||
err := generateHelm(composeFile, name, generateYaml)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to create Chart data: %s\n", err)
|
||||
}
|
||||
if createChart {
|
||||
err := generateHelm(composeFile, svcnames, generateYaml)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to create Chart data: %s\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
@ -31,7 +32,7 @@ import (
|
||||
/**
|
||||
* Generate Helm Chart configuration
|
||||
*/
|
||||
func generateHelm(filename string, svcname string, generateYaml bool) error {
|
||||
func generateHelm(filename string, svcnames []string, generateYaml bool) error {
|
||||
type ChartDetails struct {
|
||||
Name string
|
||||
}
|
||||
@ -90,29 +91,33 @@ home:
|
||||
/* Copy all related json/yaml files into the newly created manifests directory */
|
||||
// TODO: support copying controller files other than rc?
|
||||
// TODO: support copying the file specified by --out?
|
||||
extension := ".json"
|
||||
if generateYaml {
|
||||
extension = ".yaml"
|
||||
}
|
||||
infile, err := ioutil.ReadFile(svcname + "-rc" + extension)
|
||||
if err != nil {
|
||||
logrus.Infof("Error reading %s: %s\n", svcname+"-rc"+extension, err)
|
||||
return err
|
||||
}
|
||||
for _, svcname := range svcnames {
|
||||
extension := ".json"
|
||||
if generateYaml {
|
||||
extension = ".yaml"
|
||||
}
|
||||
infile, err := ioutil.ReadFile(svcname + "-rc" + extension)
|
||||
if err != nil {
|
||||
logrus.Infof("Error reading %s: %s\n", svcname+"-rc"+extension, err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(manifestDir+string(os.PathSeparator)+svcname+"-rc"+extension, infile, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(manifestDir+string(os.PathSeparator)+svcname+"-rc"+extension, infile, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
/* The svc file is optional */
|
||||
infile, err = ioutil.ReadFile(svcname + "-svc" + extension)
|
||||
if err == nil {
|
||||
/* The svc file is optional */
|
||||
infile, err = ioutil.ReadFile(svcname + "-svc" + extension)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
err = ioutil.WriteFile(manifestDir+string(os.PathSeparator)+svcname+"-svc"+extension, infile, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stdout, "chart created in %q\n", "."+string(os.PathSeparator)+dirName+string(os.PathSeparator))
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user