diff --git a/cli/app/app.go b/cli/app/app.go index 2a6d2999..8c3ed404 100644 --- a/cli/app/app.go +++ b/cli/app/app.go @@ -563,6 +563,7 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) { createDS := c.BoolT("daemonset") createRS := c.BoolT("replicaset") createChart := c.BoolT("chart") + createRC := c.BoolT("replicationcontroller") singleOutput := len(outFile) != 0 || toStdout // Validate the flags @@ -583,6 +584,9 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) { if createRS { count++ } + if createRC { + count++ + } if count > 1 { 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 !singleOutput || (!createD && !createDS && !createRS) { + if createRC { for k, v := range mReplicationControllers { print(k, "rc", v, toStdout, generateYaml, f) } @@ -823,7 +826,7 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) { } if createChart { - err := generateHelm(composeFile, svcnames, generateYaml) + err := generateHelm(composeFile, svcnames, generateYaml, createD, createDS, createRS, createRC) if err != nil { logrus.Fatalf("Failed to create Chart data: %s\n", err) } diff --git a/cli/app/k8sutils.go b/cli/app/k8sutils.go index 3d77bcc7..610b451b 100644 --- a/cli/app/k8sutils.go +++ b/cli/app/k8sutils.go @@ -32,7 +32,7 @@ import ( /** * 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 { Name string } @@ -89,26 +89,35 @@ 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? 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 + if createD { + if err = cpToChart(manifestDir, svcname, "deployment", extension); err != nil { + return err + } } - - err = ioutil.WriteFile(manifestDir+string(os.PathSeparator)+svcname+"-rc"+extension, infile, 0644) - if err != nil { - return err + if createDS { + if err = cpToChart(manifestDir, svcname, "daemonset", extension); err != nil { + 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 */ - infile, err = ioutil.ReadFile(svcname + "-svc" + extension) + infile, err := ioutil.ReadFile(svcname + "-svc" + extension) if err != nil { continue } @@ -121,3 +130,13 @@ home: fmt.Fprintf(os.Stdout, "chart created in %q\n", "."+string(os.PathSeparator)+dirName+string(os.PathSeparator)) 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) +} diff --git a/cli/command/command.go b/cli/command/command.go index 72665b3e..2625b0bc 100644 --- a/cli/command/command.go +++ b/cli/command/command.go @@ -41,14 +41,18 @@ func ConvertCommand(factory app.ProjectFactory) cli.Command { EnvVar: "OUTPUT_FILE", }, // TODO: validate the flags and make sure only one type is specified - cli.BoolFlag{ + cli.BoolTFlag{ Name: "deployment,d", - Usage: "Generate a deployment resource file", + Usage: "Generate a deployment resource file (default on)", }, cli.BoolFlag{ Name: "daemonset,ds", Usage: "Generate a daemonset resource file", }, + cli.BoolFlag{ + Name: "replicationcontroller,rc", + Usage: "Generate a replicationcontroller file", + }, cli.BoolFlag{ Name: "replicaset,rs", Usage: "Generate a replicaset resource file",