ConfigVolumes: enable creating EmptyDir volumes again

Will enable the user to specify which type of volume they want
in a subsequent commit.
This commit is contained in:
Dusty Mabe 2016-10-25 22:34:21 -04:00
parent 30752b7b93
commit df09fd5193
No known key found for this signature in database
GPG Key ID: 3302DBD73952E671

View File

@ -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{}