mirror of
https://github.com/containers/podman.git
synced 2025-10-29 08:57:26 +08:00
Add emptyDir volume support to kube play
When a kube yaml has a volume set as empty dir, podman will create an anonymous volume with the empty dir name and attach it to the containers running in the pod. When the pod is removed, the empy dir volume created is also removed. Add tests and docs for this as well. Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
This commit is contained in:
@ -387,9 +387,10 @@ func createContainerOptions(rt *libpod.Runtime, s *specgen.SpecGenerator, pod *l
|
||||
var vols []*libpod.ContainerNamedVolume
|
||||
for _, v := range volumes {
|
||||
vols = append(vols, &libpod.ContainerNamedVolume{
|
||||
Name: v.Name,
|
||||
Dest: v.Dest,
|
||||
Options: v.Options,
|
||||
Name: v.Name,
|
||||
Dest: v.Dest,
|
||||
Options: v.Options,
|
||||
IsAnonymous: v.IsAnonymous,
|
||||
})
|
||||
}
|
||||
options = append(options, libpod.WithNamedVolumes(vols))
|
||||
|
||||
@ -406,8 +406,15 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
|
||||
Name: volumeSource.Source,
|
||||
Options: options,
|
||||
}
|
||||
|
||||
s.Volumes = append(s.Volumes, &secretVolume)
|
||||
case KubeVolumeTypeEmptyDir:
|
||||
emptyDirVolume := specgen.NamedVolume{
|
||||
Dest: volume.MountPath,
|
||||
Name: volumeSource.Source,
|
||||
Options: options,
|
||||
IsAnonymous: true,
|
||||
}
|
||||
s.Volumes = append(s.Volumes, &emptyDirVolume)
|
||||
default:
|
||||
return nil, errors.New("unsupported volume source type")
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ const (
|
||||
KubeVolumeTypeBlockDevice
|
||||
KubeVolumeTypeCharDevice
|
||||
KubeVolumeTypeSecret
|
||||
KubeVolumeTypeEmptyDir
|
||||
)
|
||||
|
||||
//nolint:revive
|
||||
@ -219,8 +220,13 @@ func VolumeFromConfigMap(configMapVolumeSource *v1.ConfigMapVolumeSource, config
|
||||
return kv, nil
|
||||
}
|
||||
|
||||
// Create a kubeVolume for an emptyDir volume
|
||||
func VolumeFromEmptyDir(emptyDirVolumeSource *v1.EmptyDirVolumeSource, name string) (*KubeVolume, error) {
|
||||
return &KubeVolume{Type: KubeVolumeTypeEmptyDir, Source: name}, nil
|
||||
}
|
||||
|
||||
// Create a KubeVolume from one of the supported VolumeSource
|
||||
func VolumeFromSource(volumeSource v1.VolumeSource, configMaps []v1.ConfigMap, secretsManager *secrets.SecretsManager) (*KubeVolume, error) {
|
||||
func VolumeFromSource(volumeSource v1.VolumeSource, configMaps []v1.ConfigMap, secretsManager *secrets.SecretsManager, volName string) (*KubeVolume, error) {
|
||||
switch {
|
||||
case volumeSource.HostPath != nil:
|
||||
return VolumeFromHostPath(volumeSource.HostPath)
|
||||
@ -230,8 +236,10 @@ func VolumeFromSource(volumeSource v1.VolumeSource, configMaps []v1.ConfigMap, s
|
||||
return VolumeFromConfigMap(volumeSource.ConfigMap, configMaps)
|
||||
case volumeSource.Secret != nil:
|
||||
return VolumeFromSecret(volumeSource.Secret, secretsManager)
|
||||
case volumeSource.EmptyDir != nil:
|
||||
return VolumeFromEmptyDir(volumeSource.EmptyDir, volName)
|
||||
default:
|
||||
return nil, errors.New("HostPath, ConfigMap, and PersistentVolumeClaim are currently the only supported VolumeSource")
|
||||
return nil, errors.New("HostPath, ConfigMap, EmptyDir, and PersistentVolumeClaim are currently the only supported VolumeSource")
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,7 +248,7 @@ func InitializeVolumes(specVolumes []v1.Volume, configMaps []v1.ConfigMap, secre
|
||||
volumes := make(map[string]*KubeVolume)
|
||||
|
||||
for _, specVolume := range specVolumes {
|
||||
volume, err := VolumeFromSource(specVolume.VolumeSource, configMaps, secretsManager)
|
||||
volume, err := VolumeFromSource(specVolume.VolumeSource, configMaps, secretsManager, specVolume.Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create volume %q: %w", specVolume.Name, err)
|
||||
}
|
||||
|
||||
@ -23,6 +23,9 @@ type NamedVolume struct {
|
||||
Dest string
|
||||
// Options are options that the named volume will be mounted with.
|
||||
Options []string
|
||||
// IsAnonymous sets the named volume as anonymous even if it has a name
|
||||
// This is used for emptyDir volumes from a kube yaml
|
||||
IsAnonymous bool
|
||||
}
|
||||
|
||||
// OverlayVolume holds information about a overlay volume that will be mounted into
|
||||
|
||||
Reference in New Issue
Block a user