mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-10-05 01:55:42 +00:00
Fix wrapped volume race
This fixes race conditions in configmap, secret, downwardapi & git_repo volume plugins. wrappedVolumeSpec vars used by volume mounters and unmounters contained a pointer to api.Volume structs which were being patched by NewWrapperMounter/NewWrapperUnmounter, causing race condition during volume mounts.
This commit is contained in:
@@ -41,8 +41,10 @@ type gitRepoPlugin struct {
|
||||
|
||||
var _ volume.VolumePlugin = &gitRepoPlugin{}
|
||||
|
||||
var wrappedVolumeSpec = volume.Spec{
|
||||
Volume: &api.Volume{VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
|
||||
func wrappedVolumeSpec() volume.Spec {
|
||||
return volume.Spec{
|
||||
Volume: &api.Volume{VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -155,7 +157,7 @@ func (b *gitRepoVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
|
||||
}
|
||||
|
||||
// Wrap EmptyDir, let it do the setup.
|
||||
wrapped, err := b.plugin.host.NewWrapperMounter(b.volName, wrappedVolumeSpec, &b.pod, b.opts)
|
||||
wrapped, err := b.plugin.host.NewWrapperMounter(b.volName, wrappedVolumeSpec(), &b.pod, b.opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -237,7 +239,7 @@ func (c *gitRepoVolumeUnmounter) TearDown() error {
|
||||
func (c *gitRepoVolumeUnmounter) TearDownAt(dir string) error {
|
||||
|
||||
// Wrap EmptyDir, let it do the teardown.
|
||||
wrapped, err := c.plugin.host.NewWrapperUnmounter(c.volName, wrappedVolumeSpec, c.podUID)
|
||||
wrapped, err := c.plugin.host.NewWrapperUnmounter(c.volName, wrappedVolumeSpec(), c.podUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user