forked from LaconicNetwork/kompose
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:
parent
30752b7b93
commit
df09fd5193
@ -223,6 +223,8 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) (
|
|||||||
volumes := []api.Volume{}
|
volumes := []api.Volume{}
|
||||||
var PVCs []*api.PersistentVolumeClaim
|
var PVCs []*api.PersistentVolumeClaim
|
||||||
|
|
||||||
|
useEmptyVolumes := true
|
||||||
|
|
||||||
var count int
|
var count int
|
||||||
for _, volume := range service.Volumes {
|
for _, volume := range service.Volumes {
|
||||||
volumeName, host, container, mode, err := transformer.ParseVolume(volume)
|
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)
|
logrus.Warningf("Failed to configure container volume: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if volumeName == "" {
|
|
||||||
volumeName = fmt.Sprintf("%s-claim%d", name, count)
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
// check if ro/rw mode is defined, default rw
|
// check if ro/rw mode is defined, default rw
|
||||||
readonly := len(mode) > 0 && mode == "ro"
|
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{
|
volmount := api.VolumeMount{
|
||||||
Name: volumeName,
|
Name: volumeName,
|
||||||
ReadOnly: readonly,
|
ReadOnly: readonly,
|
||||||
@ -244,25 +253,47 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) (
|
|||||||
}
|
}
|
||||||
volumeMounts = append(volumeMounts, 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{
|
vol := api.Volume{
|
||||||
Name: volumeName,
|
Name: volumeName,
|
||||||
VolumeSource: api.VolumeSource{
|
VolumeSource: *volsource,
|
||||||
PersistentVolumeClaim: &api.PersistentVolumeClaimVolumeSource{
|
|
||||||
ClaimName: volumeName,
|
|
||||||
ReadOnly: readonly,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
volumes = append(volumes, vol)
|
volumes = append(volumes, vol)
|
||||||
|
|
||||||
if len(host) > 0 {
|
if len(host) > 0 {
|
||||||
logrus.Warningf("Volume mount on the host %q isn't supported - ignoring path on the host", host)
|
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
|
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.
|
// Configure the environment variables.
|
||||||
func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig) []api.EnvVar {
|
func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig) []api.EnvVar {
|
||||||
envs := []api.EnvVar{}
|
envs := []api.EnvVar{}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user