diff --git a/cli/app/app.go b/cli/app/app.go index bb2052d1..835eb327 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) @@ -171,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) @@ -202,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 19ad595a..a3cc5420 100644 --- a/cli/command/command.go +++ b/cli/command/command.go @@ -145,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", + }, } } @@ -156,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", + }, + }, } } @@ -167,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", + }, + }, } } 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 a67b704e..f1ddd75e 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -219,9 +219,13 @@ 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 + var PVCs []*api.PersistentVolumeClaim + + // 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 { @@ -230,37 +234,66 @@ 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, MountPath: container, } - volumesMount = append(volumesMount, volmount) + 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) } - pvc = append(pvc, k.CreatePVC(volumeName, mode)) } - return volumesMount, volumes, pvc + 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.