fix: sanitize volume name better in static pod extra volumes

Volume name should be DNS name, so make sure we don't have any leading
or trailing dashes in the generated volume name.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
This commit is contained in:
Andrey Smirnov 2021-02-22 18:15:39 +03:00 committed by talos-bot
parent 5aa75e020e
commit 1a491ee85e
2 changed files with 4 additions and 4 deletions

View File

@ -144,7 +144,7 @@ func (suite *K8sControlPlaneSuite) TestReconcileExtraVolumes() {
ExtraVolumesConfig: []v1alpha1.VolumeMountConfig{
{
VolumeHostPath: "/var/lib",
VolumeMountPath: "/var/foo",
VolumeMountPath: "/var/foo/",
},
},
},
@ -175,9 +175,9 @@ func (suite *K8sControlPlaneSuite) TestReconcileExtraVolumes() {
suite.Assert().Equal([]config.K8sExtraVolume{
{
Name: "-var-foo",
Name: "var-foo",
HostPath: "/var/lib",
MountPath: "/var/foo",
MountPath: "/var/foo/",
ReadOnly: false,
},
}, apiServerCfg.ExtraVolumes)

View File

@ -1312,7 +1312,7 @@ func (v VolumeMountConfig) MountPath() string {
// Name implements the config.VolumeMount interface.
func (v VolumeMountConfig) Name() string {
return strings.ReplaceAll(v.VolumeMountPath, "/", "-")
return strings.Trim(strings.ReplaceAll(strings.ReplaceAll(v.VolumeMountPath, "/", "-"), "_", "-"), "-")
}
// ReadOnly implements the config.VolumeMount interface.