Skip to content

Commit

Permalink
Merge pull request #24852 from rhatdan/kube
Browse files Browse the repository at this point in the history
When generating host volumes for k8s, force to lowercase
  • Loading branch information
openshift-merge-bot[bot] authored Dec 18, 2024
2 parents 2d73ca4 + 8b23e6d commit 0836325
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions libpod/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions test/system/710-kube.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0836325

Please sign in to comment.