mirror of https://github.com/containers/podman.git
Use tmpfs mounts when creating a memory-backed emptyDir volume
Signed-off-by: Andre Marianiello <andremarianiello@users.noreply.github.com>
This commit is contained in:
parent
f4f96a226f
commit
c89dd4a92f
|
@ -554,6 +554,13 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
|
|||
SubPath: volume.SubPath,
|
||||
}
|
||||
s.Volumes = append(s.Volumes, &emptyDirVolume)
|
||||
case KubeVolumeTypeEmptyDirTmpfs:
|
||||
memVolume := spec.Mount{
|
||||
Destination: volume.MountPath,
|
||||
Type: define.TypeTmpfs,
|
||||
Source: define.TypeTmpfs,
|
||||
}
|
||||
s.Mounts = append(s.Mounts, memVolume)
|
||||
default:
|
||||
return nil, errors.New("unsupported volume source type")
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ const (
|
|||
KubeVolumeTypeCharDevice
|
||||
KubeVolumeTypeSecret
|
||||
KubeVolumeTypeEmptyDir
|
||||
KubeVolumeTypeEmptyDirTmpfs
|
||||
)
|
||||
|
||||
//nolint:revive
|
||||
|
@ -263,7 +264,17 @@ func VolumeFromConfigMap(configMapVolumeSource *v1.ConfigMapVolumeSource, config
|
|||
|
||||
// Create a kubeVolume for an emptyDir volume
|
||||
func VolumeFromEmptyDir(emptyDirVolumeSource *v1.EmptyDirVolumeSource, name string) (*KubeVolume, error) {
|
||||
return &KubeVolume{Type: KubeVolumeTypeEmptyDir, Source: name}, nil
|
||||
if emptyDirVolumeSource.Medium == v1.StorageMediumMemory {
|
||||
return &KubeVolume{
|
||||
Type: KubeVolumeTypeEmptyDirTmpfs,
|
||||
Source: name,
|
||||
}, nil
|
||||
} else {
|
||||
return &KubeVolume{
|
||||
Type: KubeVolumeTypeEmptyDir,
|
||||
Source: name,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Create a KubeVolume from one of the supported VolumeSource
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
//go:build !remote
|
||||
|
||||
package kube
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
v1 "github.com/containers/podman/v4/pkg/k8s.io/api/core/v1"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestVolumeFromEmptyDir(t *testing.T) {
|
||||
emptyDirSource := v1.EmptyDirVolumeSource{}
|
||||
emptyDirVol, err := VolumeFromEmptyDir(&emptyDirSource, "emptydir")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, emptyDirVol.Type, KubeVolumeTypeEmptyDir)
|
||||
|
||||
memEmptyDirSource := v1.EmptyDirVolumeSource{
|
||||
Medium: v1.StorageMediumMemory,
|
||||
}
|
||||
memEmptyDirVol, err := VolumeFromEmptyDir(&memEmptyDirSource, "emptydir")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, memEmptyDirVol.Type, KubeVolumeTypeEmptyDirTmpfs)
|
||||
}
|
Loading…
Reference in New Issue