Skip to content

Commit

Permalink
fix: correctly escape '.' in volume names
Browse files Browse the repository at this point in the history
Volume name is derived from the mount path.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Mar 28, 2022
1 parent 108fd03 commit 0fd2aa0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ func (suite *K8sControlPlaneSuite) TestReconcileExtraVolumes() {
VolumeHostPath: "/var/lib",
VolumeMountPath: "/var/foo/",
},
{
VolumeHostPath: "/var/lib/a.foo",
VolumeMountPath: "/var/foo/b.foo",
},
},
},
},
Expand All @@ -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,
)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/machinery/config/types/v1alpha1/v1alpha1_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0fd2aa0

Please sign in to comment.