fix: correctly escape '.' in volume names

Volume name is derived from the mount path.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
This commit is contained in:
Andrey Smirnov 2022-03-25 21:57:12 +03:00
parent 108fd03a72
commit 0fd2aa08bd
No known key found for this signature in database
GPG Key ID: 7B26396447AB6DFD
2 changed files with 13 additions and 1 deletions

View File

@ -172,6 +172,10 @@ func (suite *K8sControlPlaneSuite) TestReconcileExtraVolumes() {
VolumeHostPath: "/var/lib",
VolumeMountPath: "/var/foo/",
},
{
VolumeHostPath: "/var/lib/a.foo",
VolumeMountPath: "/var/foo/b.foo",
},
},
},
},
@ -187,6 +191,12 @@ func (suite *K8sControlPlaneSuite) TestReconcileExtraVolumes() {
MountPath: "/var/foo/",
ReadOnly: false,
},
{
Name: "var-foo-b-foo",
HostPath: "/var/lib/a.foo",
MountPath: "/var/foo/b.foo",
ReadOnly: false,
},
}, apiServerCfg.ExtraVolumes,
)
}

View File

@ -1252,9 +1252,11 @@ func (v VolumeMountConfig) MountPath() string {
return v.VolumeMountPath
}
var volumeNameSanitizer = strings.NewReplacer("/", "-", "_", "-", ".", "-")
// Name implements the config.VolumeMount interface.
func (v VolumeMountConfig) Name() string {
return strings.Trim(strings.ReplaceAll(strings.ReplaceAll(v.VolumeMountPath, "/", "-"), "_", "-"), "-")
return strings.Trim(volumeNameSanitizer.Replace(v.VolumeMountPath), "-")
}
// ReadOnly implements the config.VolumeMount interface.