forked from LaconicNetwork/kompose
Merge pull request #248 from dustymabe/dusty-empty-vols
Adding support for choosing empty volumes
This commit is contained in:
commit
d9c5de661a
@ -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)
|
||||
|
||||
@ -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",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -113,6 +113,7 @@ type ConvertOptions struct {
|
||||
CreateDeploymentConfig bool
|
||||
CreateChart bool
|
||||
GenerateYaml bool
|
||||
EmptyVols bool
|
||||
Replicas int
|
||||
InputFile string
|
||||
OutFile string
|
||||
|
||||
@ -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,
|
||||
},
|
||||
},
|
||||
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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user