mirror of
https://github.com/containers/podman.git
synced 2025-06-24 11:28:24 +08:00
expose block and char devices with play kube
[NO NEW TESTS NEEDED] Signed-off-by: Cosmin Tupangiu <cosmin@redhat.com>
This commit is contained in:
@ -381,6 +381,22 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
|
||||
Options: options,
|
||||
}
|
||||
s.Volumes = append(s.Volumes, &cmVolume)
|
||||
case KubeVolumeTypeCharDevice:
|
||||
// We are setting the path as hostPath:mountPath to comply with DeviceFromPath (https://github.com/containers/podman/blob/eb26fa45f1326191dea27f2afabf82cb8b934140/pkg/specgen/generate/config_linux.go#L72)
|
||||
// The type is here just to improve readability as it is not taken into account when the actual device is created.
|
||||
device := spec.LinuxDevice{
|
||||
Path: fmt.Sprintf("%s:%s", volumeSource.Source, volume.MountPath),
|
||||
Type: "c",
|
||||
}
|
||||
s.Devices = append(s.Devices, device)
|
||||
case KubeVolumeTypeBlockDevice:
|
||||
// We are setting the path as hostPath:mountPath to comply with DeviceFromPath (https://github.com/containers/podman/blob/eb26fa45f1326191dea27f2afabf82cb8b934140/pkg/specgen/generate/config_linux.go#L72)
|
||||
// The type is here just to improve readability as it is not taken into account when the actual device is created.
|
||||
device := spec.LinuxDevice{
|
||||
Path: fmt.Sprintf("%s:%s", volumeSource.Source, volume.MountPath),
|
||||
Type: "b",
|
||||
}
|
||||
s.Devices = append(s.Devices, device)
|
||||
default:
|
||||
return nil, errors.Errorf("Unsupported volume source type")
|
||||
}
|
||||
|
@ -22,8 +22,10 @@ type KubeVolumeType int
|
||||
|
||||
const (
|
||||
KubeVolumeTypeBindMount KubeVolumeType = iota
|
||||
KubeVolumeTypeNamed KubeVolumeType = iota
|
||||
KubeVolumeTypeConfigMap KubeVolumeType = iota
|
||||
KubeVolumeTypeNamed
|
||||
KubeVolumeTypeConfigMap
|
||||
KubeVolumeTypeBlockDevice
|
||||
KubeVolumeTypeCharDevice
|
||||
)
|
||||
|
||||
//nolint:revive
|
||||
@ -78,7 +80,30 @@ func VolumeFromHostPath(hostPath *v1.HostPathVolumeSource) (*KubeVolume, error)
|
||||
if st.Mode()&os.ModeSocket != os.ModeSocket {
|
||||
return nil, errors.Errorf("checking HostPathSocket: path %s is not a socket", hostPath.Path)
|
||||
}
|
||||
|
||||
case v1.HostPathBlockDev:
|
||||
dev, err := os.Stat(hostPath.Path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error checking HostPathBlockDevice")
|
||||
}
|
||||
if dev.Mode()&os.ModeDevice != os.ModeDevice {
|
||||
return nil, errors.Errorf("checking HosPathDevice: path %s is not a block device", hostPath.Path)
|
||||
}
|
||||
return &KubeVolume{
|
||||
Type: KubeVolumeTypeBlockDevice,
|
||||
Source: hostPath.Path,
|
||||
}, nil
|
||||
case v1.HostPathCharDev:
|
||||
dev, err := os.Stat(hostPath.Path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error checking HostPathCharDevice")
|
||||
}
|
||||
if dev.Mode()&os.ModeCharDevice != os.ModeCharDevice {
|
||||
return nil, errors.Errorf("checking HosPathCharDevice: path %s is not a character device", hostPath.Path)
|
||||
}
|
||||
return &KubeVolume{
|
||||
Type: KubeVolumeTypeCharDevice,
|
||||
Source: hostPath.Path,
|
||||
}, nil
|
||||
case v1.HostPathDirectory:
|
||||
case v1.HostPathFile:
|
||||
case v1.HostPathUnset:
|
||||
|
Reference in New Issue
Block a user