Added --controller feature

Previously we used to mention controller type as `--deployment`,
`--replication-controller` or `--daemonset` as argument.
But now,
it will be like,

ex.

```
kompose convert --controller=daemonset
```
This commit is contained in:
Suraj Narwade
2017-10-04 12:43:45 +05:30
parent 4d4cc3b017
commit 4f8babd623
9 changed files with 799 additions and 6 deletions
+11 -2
View File
@@ -76,6 +76,10 @@ func ValidateFlags(bundle string, args []string, cmd *cobra.Command, opt *kobjec
replicationController := cmd.Flags().Lookup("replication-controller").Changed
deployment := cmd.Flags().Lookup("deployment").Changed
// Get the controller
controller := opt.Controller
log.Debug("Checking validation of controller %s", controller)
// Check validations against provider flags
switch {
case provider == "openshift":
@@ -91,6 +95,9 @@ func ValidateFlags(bundle string, args []string, cmd *cobra.Command, opt *kobjec
if deployment {
log.Fatalf("--deployment, -d is a Kubernetes only flag")
}
if controller == "daemonset" || controller == "replicationcontroller" || controller == "deployment" {
log.Fatalf("--controller= daemonset, replicationcontroller or deployment is a Kubernetes only flag")
}
case provider == "kubernetes":
if deploymentConfig {
log.Fatalf("--deployment-config is an OpenShift only flag")
@@ -101,6 +108,9 @@ func ValidateFlags(bundle string, args []string, cmd *cobra.Command, opt *kobjec
if buildBranch {
log.Fatalf("--build-branch is an Openshift only flag")
}
if controller == "deploymentconfig" {
log.Fatalf("--controller=deploymentConfig is an OpenShift only flag")
}
}
// Standard checks regardless of provider
@@ -159,10 +169,9 @@ func ValidateComposeFile(opt *kobject.ConvertOptions) {
func validateControllers(opt *kobject.ConvertOptions) {
singleOutput := len(opt.OutFile) != 0 || opt.OutFile == "-" || opt.ToStdout
if opt.Provider == "kubernetes" {
// create deployment by default if no controller has been set
if !opt.CreateD && !opt.CreateDS && !opt.CreateRC {
if !opt.CreateD && !opt.CreateDS && !opt.CreateRC && opt.Controller == "" {
opt.CreateD = true
}
if singleOutput {
+1
View File
@@ -51,6 +51,7 @@ type ConvertOptions struct {
OutFile string
Provider string
Namespace string
Controller string
IsDeploymentFlag bool
IsDaemonSetFlag bool
IsReplicationControllerFlag bool
+3 -4
View File
@@ -507,14 +507,13 @@ func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.Servic
log.Warning("Global mode not yet supported, containers will only be replicated once throughout the cluster. DaemonSet support will be added in the future.")
replica = 1
}
if opt.CreateD {
if opt.CreateD || opt.Controller == "deployment" {
objects = append(objects, k.InitD(name, service, replica))
}
if opt.CreateDS {
if opt.CreateDS || opt.Controller == "daemonset" {
objects = append(objects, k.InitDS(name, service))
}
if opt.CreateRC {
if opt.CreateRC || opt.Controller == "replicationcontroller" {
objects = append(objects, k.InitRC(name, service, replica))
}