mirror of
https://github.com/containers/podman.git
synced 2025-05-20 00:27:03 +08:00
When generating host volumes for k8s, force to lowercase
Fixes: https://github.com/containers/podman/issues/16542 Kubernetes only allows lower case persistent volume names. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@ -1188,14 +1188,15 @@ func generateKubePersistentVolumeClaim(v *ContainerNamedVolume) (v1.VolumeMount,
|
||||
ro := slices.Contains(v.Options, "ro")
|
||||
|
||||
// To avoid naming conflicts with any host path mounts, add a unique suffix to the volume's name.
|
||||
name := v.Name + "-pvc"
|
||||
vName := strings.ToLower(v.Name)
|
||||
name := vName + "-pvc"
|
||||
|
||||
vm := v1.VolumeMount{}
|
||||
vm.Name = name
|
||||
vm.MountPath = v.Dest
|
||||
vm.ReadOnly = ro
|
||||
|
||||
pvc := v1.PersistentVolumeClaimVolumeSource{ClaimName: v.Name, ReadOnly: ro}
|
||||
pvc := v1.PersistentVolumeClaimVolumeSource{ClaimName: vName, ReadOnly: ro}
|
||||
vs := v1.VolumeSource{}
|
||||
vs.PersistentVolumeClaim = &pvc
|
||||
vo := v1.Volume{Name: name, VolumeSource: vs}
|
||||
@ -1274,7 +1275,7 @@ func convertVolumePathToName(hostSourcePath string) (string, error) {
|
||||
}
|
||||
// First, trim trailing slashes, then replace slashes with dashes.
|
||||
// Thus, /mnt/data/ will become mnt-data
|
||||
return strings.ReplaceAll(strings.Trim(hostSourcePath, "/"), "/", "-"), nil
|
||||
return strings.ToLower(strings.ReplaceAll(strings.Trim(hostSourcePath, "/"), "/", "-")), nil
|
||||
}
|
||||
|
||||
func determineCapAddDropFromCapabilities(defaultCaps, containerCaps []string) *v1.Capabilities {
|
||||
|
@ -94,6 +94,19 @@ status | = | null
|
||||
run_podman rm $cname
|
||||
}
|
||||
|
||||
@test "podman kube generate volumes" {
|
||||
cname=c-$(safename)
|
||||
KUBE=$PODMAN_TMPDIR/kube.yaml
|
||||
source=$PODMAN_TMPDIR/Upper/Case/Path
|
||||
mkdir -p ${source}
|
||||
run_podman create --name $cname -v $source:/mnt -v UPPERCASEVolume:/volume $IMAGE
|
||||
run_podman kube generate $cname -f $KUBE
|
||||
assert "$(< $KUBE)" =~ "name: uppercasevolume-pvc" "Lowercase volume name"
|
||||
assert "$(< $KUBE)" =~ "upper-case-path" "Lowercase volume paths"
|
||||
run_podman rm $cname
|
||||
run_podman volume rm UPPERCASEVolume
|
||||
}
|
||||
|
||||
@test "podman kube generate - pod" {
|
||||
local pname=p-$(safename)
|
||||
local cname1=c1-$(safename)
|
||||
|
Reference in New Issue
Block a user