From f290cd6541884f08ce836a1e84ab9d37d9fe237e Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Tue, 25 Oct 2016 16:21:12 -0400 Subject: [PATCH 1/6] ConfigVolumes: rename volumesMount to volumeMounts --- pkg/transformer/kubernetes/kubernetes.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index 45761cea..567eedc2 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -219,7 +219,7 @@ func (k *Kubernetes) ConfigServicePorts(name string, service kobject.ServiceConf // Configure the container volumes. func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ([]api.VolumeMount, []api.Volume, []*api.PersistentVolumeClaim) { - volumesMount := []api.VolumeMount{} + volumeMounts := []api.VolumeMount{} volumes := []api.Volume{} var pvc []*api.PersistentVolumeClaim @@ -242,7 +242,7 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( ReadOnly: readonly, MountPath: container, } - volumesMount = append(volumesMount, volmount) + volumeMounts = append(volumeMounts, volmount) vol := api.Volume{ Name: volumeName, @@ -260,7 +260,7 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( } pvc = append(pvc, k.CreatePVC(volumeName, mode)) } - return volumesMount, volumes, pvc + return volumeMounts, volumes, pvc } // Configure the environment variables. From 30752b7b93e46d408d3e8c0573995c52abf766eb Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Tue, 25 Oct 2016 22:26:04 -0400 Subject: [PATCH 2/6] ConfigVolumes: rename pvc var to PVCs It is a list of persistent volume claims. --- pkg/transformer/kubernetes/kubernetes.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index 567eedc2..c275dd67 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -221,7 +221,7 @@ func (k *Kubernetes) ConfigServicePorts(name string, service kobject.ServiceConf func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ([]api.VolumeMount, []api.Volume, []*api.PersistentVolumeClaim) { volumeMounts := []api.VolumeMount{} volumes := []api.Volume{} - var pvc []*api.PersistentVolumeClaim + var PVCs []*api.PersistentVolumeClaim var count int for _, volume := range service.Volumes { @@ -258,9 +258,9 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( if len(host) > 0 { logrus.Warningf("Volume mount on the host %q isn't supported - ignoring path on the host", host) } - pvc = append(pvc, k.CreatePVC(volumeName, mode)) + PVCs = append(PVCs, k.CreatePVC(volumeName, mode)) } - return volumeMounts, volumes, pvc + return volumeMounts, volumes, PVCs } // Configure the environment variables. From df09fd5193061ab706dbe687883ed965dd52cec4 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Tue, 25 Oct 2016 22:34:21 -0400 Subject: [PATCH 3/6] ConfigVolumes: enable creating EmptyDir volumes again Will enable the user to specify which type of volume they want in a subsequent commit. --- pkg/transformer/kubernetes/kubernetes.go | 55 ++++++++++++++++++------ 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index c275dd67..7f3bd814 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -223,6 +223,8 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( volumes := []api.Volume{} var PVCs []*api.PersistentVolumeClaim + useEmptyVolumes := true + var count int for _, volume := range service.Volumes { volumeName, host, container, mode, err := transformer.ParseVolume(volume) @@ -230,13 +232,20 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( logrus.Warningf("Failed to configure container volume: %v", err) continue } - if volumeName == "" { - volumeName = fmt.Sprintf("%s-claim%d", name, count) - count++ - } + // check if ro/rw mode is defined, default rw readonly := len(mode) > 0 && mode == "ro" + if volumeName == "" { + if useEmptyVolumes { + volumeName = fmt.Sprintf("%s-empty%d", name, count) + } else { + volumeName = fmt.Sprintf("%s-claim%d", name, count) + } + count++ + } + + // create a new volume mount object and append to list volmount := api.VolumeMount{ Name: volumeName, ReadOnly: readonly, @@ -244,25 +253,47 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( } volumeMounts = append(volumeMounts, volmount) + // Get a volume source based on the type of volume we are using + // For PVC we will also create a PVC object and add to list + var volsource *api.VolumeSource + if useEmptyVolumes { + volsource = k.ConfigEmptyVolumeSource() + } else { + volsource = k.ConfigPVCVolumeSource(volumeName, readonly) + PVCs = append(PVCs, k.CreatePVC(volumeName, mode)) + } + + // create a new volume object using the volsource and add to list vol := api.Volume{ - Name: volumeName, - VolumeSource: api.VolumeSource{ - PersistentVolumeClaim: &api.PersistentVolumeClaimVolumeSource{ - ClaimName: volumeName, - ReadOnly: readonly, - }, - }, + Name: volumeName, + VolumeSource: *volsource, } volumes = append(volumes, vol) if len(host) > 0 { logrus.Warningf("Volume mount on the host %q isn't supported - ignoring path on the host", host) } - PVCs = append(PVCs, k.CreatePVC(volumeName, mode)) } return volumeMounts, volumes, PVCs } +// helper function to create an EmptyDir api.VolumeSource +func (k *Kubernetes) ConfigEmptyVolumeSource() *api.VolumeSource { + return &api.VolumeSource{ + EmptyDir: &api.EmptyDirVolumeSource{}, + } +} + +// helper function to create an api.VolumeSource with a PVC +func (k *Kubernetes) ConfigPVCVolumeSource(name string, readonly bool) *api.VolumeSource { + return &api.VolumeSource{ + PersistentVolumeClaim: &api.PersistentVolumeClaimVolumeSource{ + ClaimName: name, + ReadOnly: readonly, + }, + } +} + // Configure the environment variables. func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig) []api.EnvVar { envs := []api.EnvVar{} From 9ce3f0cf157b1294185a7ee21acf67b4eadf8422 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Tue, 25 Oct 2016 23:38:11 -0400 Subject: [PATCH 4/6] cli: add --emptyvols option --- cli/app/app.go | 1 + cli/command/command.go | 8 ++++++++ pkg/kobject/kobject.go | 1 + pkg/transformer/kubernetes/kubernetes.go | 4 +++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cli/app/app.go b/cli/app/app.go index bb2052d1..6717d383 100644 --- a/cli/app/app.go +++ b/cli/app/app.go @@ -139,6 +139,7 @@ func Convert(c *cli.Context) { CreateDS: c.BoolT("daemonset"), CreateRC: c.BoolT("replicationcontroller"), CreateDeploymentConfig: c.BoolT("deploymentconfig"), + EmptyVols: c.BoolT("emptyvols"), } validateFlags(c, &opt) diff --git a/cli/command/command.go b/cli/command/command.go index 19ad595a..9e104ee2 100644 --- a/cli/command/command.go +++ b/cli/command/command.go @@ -88,6 +88,10 @@ func ConvertKubernetesCommand() cli.Command { Name: "chart,c", Usage: "Create a Helm chart for converted objects", }, + cli.BoolFlag{ + Name: "emptyvols", + Usage: "Use Empty Volumes. Don't generate PVCs", + }, cli.BoolFlag{ Name: "deployment,d", Usage: "Generate a Kubernetes deployment object (default on)", @@ -119,6 +123,10 @@ func ConvertOpenShiftCommand() cli.Command { Name: "deploymentconfig,dc", Usage: "Generate a OpenShift DeploymentConfig object", }, + cli.BoolFlag{ + Name: "emptyvols", + Usage: "Use Empty Volumes. Don't generate PVCs", + }, }, } command.Flags = append(command.Flags, commonConvertFlags()...) diff --git a/pkg/kobject/kobject.go b/pkg/kobject/kobject.go index fea19dc8..66885c9e 100644 --- a/pkg/kobject/kobject.go +++ b/pkg/kobject/kobject.go @@ -113,6 +113,7 @@ type ConvertOptions struct { CreateDeploymentConfig bool CreateChart bool GenerateYaml bool + EmptyVols bool Replicas int InputFile string OutFile string diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index 7f3bd814..e3544cea 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -223,7 +223,9 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( volumes := []api.Volume{} var PVCs []*api.PersistentVolumeClaim - useEmptyVolumes := true + // Set a var based on if the user wants to use emtpy volumes + // as opposed to persistent volumes and volume claims + useEmptyVolumes := k.Opt.EmptyVols var count int for _, volume := range service.Volumes { From f67fca8be191b736402fb982fdcfb6e3d67ac4cb Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Thu, 27 Oct 2016 18:13:17 -0400 Subject: [PATCH 5/6] cli: move emtpyvols to common convert options --- cli/command/command.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cli/command/command.go b/cli/command/command.go index 9e104ee2..3fcbf428 100644 --- a/cli/command/command.go +++ b/cli/command/command.go @@ -88,10 +88,6 @@ func ConvertKubernetesCommand() cli.Command { Name: "chart,c", Usage: "Create a Helm chart for converted objects", }, - cli.BoolFlag{ - Name: "emptyvols", - Usage: "Use Empty Volumes. Don't generate PVCs", - }, cli.BoolFlag{ Name: "deployment,d", Usage: "Generate a Kubernetes deployment object (default on)", @@ -123,10 +119,6 @@ func ConvertOpenShiftCommand() cli.Command { Name: "deploymentconfig,dc", Usage: "Generate a OpenShift DeploymentConfig object", }, - cli.BoolFlag{ - Name: "emptyvols", - Usage: "Use Empty Volumes. Don't generate PVCs", - }, }, } command.Flags = append(command.Flags, commonConvertFlags()...) @@ -153,6 +145,10 @@ func commonConvertFlags() []cli.Flag { Name: "stdout", Usage: "Print converted objects to stdout", }, + cli.BoolFlag{ + Name: "emptyvols", + Usage: "Use Empty Volumes. Don't generate PVCs", + }, } } From 7349dc9c9f8bf7422b930ea6c70231d50cbcc062 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Thu, 27 Oct 2016 18:18:16 -0400 Subject: [PATCH 6/6] cli: add --emptyvols to Up/Down --- cli/app/app.go | 2 ++ cli/command/command.go | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/cli/app/app.go b/cli/app/app.go index 6717d383..835eb327 100644 --- a/cli/app/app.go +++ b/cli/app/app.go @@ -172,6 +172,7 @@ func Up(c *cli.Context) { InputFile: c.GlobalString("file"), Replicas: 1, Provider: strings.ToLower(c.GlobalString("provider")), + EmptyVols: c.BoolT("emptyvols"), } validateFlags(c, &opt) validateControllers(&opt) @@ -203,6 +204,7 @@ func Down(c *cli.Context) { InputFile: c.GlobalString("file"), Replicas: 1, Provider: strings.ToLower(c.GlobalString("provider")), + EmptyVols: c.BoolT("emptyvols"), } validateFlags(c, &opt) validateControllers(&opt) diff --git a/cli/command/command.go b/cli/command/command.go index 3fcbf428..a3cc5420 100644 --- a/cli/command/command.go +++ b/cli/command/command.go @@ -160,6 +160,12 @@ func UpCommand() cli.Command { Action: func(c *cli.Context) { app.Up(c) }, + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "emptyvols", + Usage: "Use Empty Volumes. Don't generate PVCs", + }, + }, } } @@ -171,6 +177,12 @@ func DownCommand() cli.Command { Action: func(c *cli.Context) { app.Down(c) }, + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "emptyvols", + Usage: "Use Empty Volumes. Don't generate PVCs", + }, + }, } }