mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Merge pull request #24868 from rhatdan/kube
Kube volumes can not contain _
This commit is contained in:
@ -1188,7 +1188,7 @@ func generateKubePersistentVolumeClaim(v *ContainerNamedVolume) (v1.VolumeMount,
|
|||||||
ro := slices.Contains(v.Options, "ro")
|
ro := slices.Contains(v.Options, "ro")
|
||||||
|
|
||||||
// To avoid naming conflicts with any host path mounts, add a unique suffix to the volume's name.
|
// To avoid naming conflicts with any host path mounts, add a unique suffix to the volume's name.
|
||||||
vName := strings.ToLower(v.Name)
|
vName := fixKubeVolumeName(v.Name)
|
||||||
name := vName + "-pvc"
|
name := vName + "-pvc"
|
||||||
|
|
||||||
vm := v1.VolumeMount{}
|
vm := v1.VolumeMount{}
|
||||||
@ -1262,6 +1262,15 @@ func isHostPathDirectory(hostPathSource string) (bool, error) {
|
|||||||
return info.Mode().IsDir(), nil
|
return info.Mode().IsDir(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fixKubeVolumeName(source string) string {
|
||||||
|
// Trim trailing slashes,
|
||||||
|
// Replace slashes with dashes.
|
||||||
|
// Replace underscores with dashes.
|
||||||
|
// Force all letters to lower case
|
||||||
|
// Thus, /mnt/data/ will become mnt-data
|
||||||
|
return strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(strings.Trim(source, "/"), "/", "-"), "_", "-"))
|
||||||
|
}
|
||||||
|
|
||||||
func convertVolumePathToName(hostSourcePath string) (string, error) {
|
func convertVolumePathToName(hostSourcePath string) (string, error) {
|
||||||
if len(hostSourcePath) == 0 {
|
if len(hostSourcePath) == 0 {
|
||||||
return "", errors.New("hostSourcePath must be specified to generate volume name")
|
return "", errors.New("hostSourcePath must be specified to generate volume name")
|
||||||
@ -1273,9 +1282,7 @@ func convertVolumePathToName(hostSourcePath string) (string, error) {
|
|||||||
// add special case name
|
// add special case name
|
||||||
return "root", nil
|
return "root", nil
|
||||||
}
|
}
|
||||||
// First, trim trailing slashes, then replace slashes with dashes.
|
return fixKubeVolumeName(hostSourcePath), nil
|
||||||
// Thus, /mnt/data/ will become mnt-data
|
|
||||||
return strings.ToLower(strings.ReplaceAll(strings.Trim(hostSourcePath, "/"), "/", "-")), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func determineCapAddDropFromCapabilities(defaultCaps, containerCaps []string) *v1.Capabilities {
|
func determineCapAddDropFromCapabilities(defaultCaps, containerCaps []string) *v1.Capabilities {
|
||||||
|
@ -99,12 +99,12 @@ status | = | null
|
|||||||
KUBE=$PODMAN_TMPDIR/kube.yaml
|
KUBE=$PODMAN_TMPDIR/kube.yaml
|
||||||
source=$PODMAN_TMPDIR/Upper/Case/Path
|
source=$PODMAN_TMPDIR/Upper/Case/Path
|
||||||
mkdir -p ${source}
|
mkdir -p ${source}
|
||||||
run_podman create --name $cname -v $source:/mnt -v UPPERCASEVolume:/volume $IMAGE
|
run_podman create --name $cname -v $source:/mnt -v UPPERCASE_Volume:/volume $IMAGE
|
||||||
run_podman kube generate $cname -f $KUBE
|
run_podman kube generate $cname -f $KUBE
|
||||||
assert "$(< $KUBE)" =~ "name: uppercasevolume-pvc" "Lowercase volume name"
|
assert "$(< $KUBE)" =~ "name: uppercase-volume-pvc" "Lowercase volume name"
|
||||||
assert "$(< $KUBE)" =~ "upper-case-path" "Lowercase volume paths"
|
assert "$(< $KUBE)" =~ "upper-case-path" "Lowercase volume paths"
|
||||||
run_podman rm $cname
|
run_podman rm $cname
|
||||||
run_podman volume rm UPPERCASEVolume
|
run_podman volume rm UPPERCASE_Volume
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "podman kube generate - pod" {
|
@test "podman kube generate - pod" {
|
||||||
|
Reference in New Issue
Block a user