Add kube play support for image volume source

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
This commit is contained in:
Mario Loriedo
2024-08-30 17:13:21 +00:00
parent f22f4cfe50
commit db12343e27
7 changed files with 302 additions and 52 deletions

View File

@ -567,6 +567,14 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
Source: define.TypeTmpfs,
}
s.Mounts = append(s.Mounts, memVolume)
case KubeVolumeTypeImage:
imageVolume := specgen.ImageVolume{
Destination: volume.MountPath,
ReadWrite: false,
Source: volumeSource.Source,
SubPath: "",
}
s.ImageVolumes = append(s.ImageVolumes, &imageVolume)
default:
return nil, errors.New("unsupported volume source type")
}

View File

@ -37,13 +37,14 @@ const (
KubeVolumeTypeSecret
KubeVolumeTypeEmptyDir
KubeVolumeTypeEmptyDirTmpfs
KubeVolumeTypeImage
)
//nolint:revive
type KubeVolume struct {
// Type of volume to create
Type KubeVolumeType
// Path for bind mount or volume name for named volume
// Path for bind mount, volume name for named volume or image name for image volume
Source string
// Items to add to a named volume created where the key is the file name and the value is the data
// This is only used when there are volumes in the yaml that refer to a configmap
@ -56,6 +57,8 @@ type KubeVolume struct {
// DefaultMode sets the permissions on files created for the volume
// This is optional and defaults to 0644
DefaultMode int32
// Used for volumes of type Image. Ignored for other volumes types.
ImagePullPolicy v1.PullPolicy
}
// Create a KubeVolume from an HostPathVolumeSource
@ -279,6 +282,14 @@ func VolumeFromEmptyDir(emptyDirVolumeSource *v1.EmptyDirVolumeSource, name stri
}
}
func VolumeFromImage(imageVolumeSource *v1.ImageVolumeSource, name string) (*KubeVolume, error) {
return &KubeVolume{
Type: KubeVolumeTypeImage,
Source: imageVolumeSource.Reference,
ImagePullPolicy: imageVolumeSource.PullPolicy,
}, nil
}
// Create a KubeVolume from one of the supported VolumeSource
func VolumeFromSource(volumeSource v1.VolumeSource, configMaps []v1.ConfigMap, secretsManager *secrets.SecretsManager, volName, mountLabel string) (*KubeVolume, error) {
switch {
@ -292,6 +303,8 @@ func VolumeFromSource(volumeSource v1.VolumeSource, configMaps []v1.ConfigMap, s
return VolumeFromSecret(volumeSource.Secret, secretsManager)
case volumeSource.EmptyDir != nil:
return VolumeFromEmptyDir(volumeSource.EmptyDir, volName)
case volumeSource.Image != nil:
return VolumeFromImage(volumeSource.Image, volName)
default:
return nil, errors.New("HostPath, ConfigMap, EmptyDir, Secret, and PersistentVolumeClaim are currently the only supported VolumeSource")
}