forked from LaconicNetwork/kompose
Make deployment the default controller, create -rc for rc, and enable copying all types of controller to chart templates
This commit is contained in:
parent
8871baf9be
commit
0bcec2aa23
@ -563,6 +563,7 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
|||||||
createDS := c.BoolT("daemonset")
|
createDS := c.BoolT("daemonset")
|
||||||
createRS := c.BoolT("replicaset")
|
createRS := c.BoolT("replicaset")
|
||||||
createChart := c.BoolT("chart")
|
createChart := c.BoolT("chart")
|
||||||
|
createRC := c.BoolT("replicationcontroller")
|
||||||
singleOutput := len(outFile) != 0 || toStdout
|
singleOutput := len(outFile) != 0 || toStdout
|
||||||
|
|
||||||
// Validate the flags
|
// Validate the flags
|
||||||
@ -583,6 +584,9 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
|||||||
if createRS {
|
if createRS {
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
|
if createRC {
|
||||||
|
count++
|
||||||
|
}
|
||||||
if count > 1 {
|
if count > 1 {
|
||||||
logrus.Fatalf("Error: only one type of Kubernetes controller can be generated when --out or --stdout is specified")
|
logrus.Fatalf("Error: only one type of Kubernetes controller can be generated when --out or --stdout is specified")
|
||||||
}
|
}
|
||||||
@ -811,8 +815,7 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can create RC when we either don't print to --out or --stdout, or we don't create any other controllers
|
if createRC {
|
||||||
if !singleOutput || (!createD && !createDS && !createRS) {
|
|
||||||
for k, v := range mReplicationControllers {
|
for k, v := range mReplicationControllers {
|
||||||
print(k, "rc", v, toStdout, generateYaml, f)
|
print(k, "rc", v, toStdout, generateYaml, f)
|
||||||
}
|
}
|
||||||
@ -823,7 +826,7 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if createChart {
|
if createChart {
|
||||||
err := generateHelm(composeFile, svcnames, generateYaml)
|
err := generateHelm(composeFile, svcnames, generateYaml, createD, createDS, createRS, createRC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatalf("Failed to create Chart data: %s\n", err)
|
logrus.Fatalf("Failed to create Chart data: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import (
|
|||||||
/**
|
/**
|
||||||
* Generate Helm Chart configuration
|
* Generate Helm Chart configuration
|
||||||
*/
|
*/
|
||||||
func generateHelm(filename string, svcnames []string, generateYaml bool) error {
|
func generateHelm(filename string, svcnames []string, generateYaml, createD, createDS, createRS, createRC bool) error {
|
||||||
type ChartDetails struct {
|
type ChartDetails struct {
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
@ -89,26 +89,35 @@ home:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Copy all related json/yaml files into the newly created manifests directory */
|
/* 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?
|
// TODO: support copying the file specified by --out?
|
||||||
for _, svcname := range svcnames {
|
for _, svcname := range svcnames {
|
||||||
extension := ".json"
|
extension := ".json"
|
||||||
if generateYaml {
|
if generateYaml {
|
||||||
extension = ".yaml"
|
extension = ".yaml"
|
||||||
}
|
}
|
||||||
infile, err := ioutil.ReadFile(svcname + "-rc" + extension)
|
if createD {
|
||||||
if err != nil {
|
if err = cpToChart(manifestDir, svcname, "deployment", extension); err != nil {
|
||||||
logrus.Infof("Error reading %s: %s\n", svcname+"-rc"+extension, err)
|
return err
|
||||||
return err
|
}
|
||||||
}
|
}
|
||||||
|
if createDS {
|
||||||
err = ioutil.WriteFile(manifestDir+string(os.PathSeparator)+svcname+"-rc"+extension, infile, 0644)
|
if err = cpToChart(manifestDir, svcname, "daemonset", extension); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
}
|
||||||
|
}
|
||||||
|
if createRC {
|
||||||
|
if err = cpToChart(manifestDir, svcname, "replicationcontroller", extension); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if createRS {
|
||||||
|
if err = cpToChart(manifestDir, svcname, "replicaset", extension); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The svc file is optional */
|
/* The svc file is optional */
|
||||||
infile, err = ioutil.ReadFile(svcname + "-svc" + extension)
|
infile, err := ioutil.ReadFile(svcname + "-svc" + extension)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -121,3 +130,13 @@ home:
|
|||||||
fmt.Fprintf(os.Stdout, "chart created in %q\n", "."+string(os.PathSeparator)+dirName+string(os.PathSeparator))
|
fmt.Fprintf(os.Stdout, "chart created in %q\n", "."+string(os.PathSeparator)+dirName+string(os.PathSeparator))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cpToChart(manifestDir, svcname, trailing, extension string) error {
|
||||||
|
infile, err := ioutil.ReadFile(svcname + "-" + trailing + extension)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Infof("Error reading %s: %s\n", svcname+"-"+trailing+extension, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ioutil.WriteFile(manifestDir+string(os.PathSeparator)+svcname+"-"+trailing+extension, infile, 0644)
|
||||||
|
}
|
||||||
|
|||||||
@ -41,14 +41,18 @@ func ConvertCommand(factory app.ProjectFactory) cli.Command {
|
|||||||
EnvVar: "OUTPUT_FILE",
|
EnvVar: "OUTPUT_FILE",
|
||||||
},
|
},
|
||||||
// TODO: validate the flags and make sure only one type is specified
|
// TODO: validate the flags and make sure only one type is specified
|
||||||
cli.BoolFlag{
|
cli.BoolTFlag{
|
||||||
Name: "deployment,d",
|
Name: "deployment,d",
|
||||||
Usage: "Generate a deployment resource file",
|
Usage: "Generate a deployment resource file (default on)",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "daemonset,ds",
|
Name: "daemonset,ds",
|
||||||
Usage: "Generate a daemonset resource file",
|
Usage: "Generate a daemonset resource file",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "replicationcontroller,rc",
|
||||||
|
Usage: "Generate a replicationcontroller file",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "replicaset,rs",
|
Name: "replicaset,rs",
|
||||||
Usage: "Generate a replicaset resource file",
|
Usage: "Generate a replicaset resource file",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user