diff --git a/pkg/kubelet/volumes.go b/pkg/kubelet/volumes.go index a8ee4107a28..e3e81183883 100644 --- a/pkg/kubelet/volumes.go +++ b/pkg/kubelet/volumes.go @@ -24,6 +24,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/types" + "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume" "github.com/davecgh/go-spew/spew" "github.com/golang/glog" @@ -174,7 +175,7 @@ func (kl *Kubelet) getPodVolumesFromDisk() map[string]volume.Cleaner { } func (kl *Kubelet) newVolumeCleanerFromPlugins(kind string, name string, podUID types.UID) (volume.Cleaner, error) { - plugName := volume.UnescapePluginName(kind) + plugName := util.UnescapeQualifiedNameForDisk(kind) plugin, err := kl.volumePluginMgr.FindPluginByName(plugName) if err != nil { // TODO: Maybe we should launch a cleanup of this dir? diff --git a/pkg/util/escape.go b/pkg/util/escape.go new file mode 100644 index 00000000000..049ad3c837e --- /dev/null +++ b/pkg/util/escape.go @@ -0,0 +1,36 @@ +/* +Copyright 2014 Google Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "strings" +) + +// EscapeQualifiedNameForDisk converts a plugin name, which might contain a / into a +// string that is safe to use on-disk. This assumes that the input has already +// been validates as a qualified name. we use "~" rather than ":" here in case +// we ever use a filesystem that doesn't allow ":". +func EscapeQualifiedNameForDisk(in string) string { + return strings.Replace(in, "/", "~", -1) +} + +// UnescapeQualifiedNameForDisk converts an escaped plugin name (as per EscapeQualifiedNameForDisk) +// back to its normal form. This assumes that the input has already been +// validates as a qualified name. +func UnescapeQualifiedNameForDisk(in string) string { + return strings.Replace(in, "~", "/", -1) +} diff --git a/pkg/volume/empty_dir/empty_dir.go b/pkg/volume/empty_dir/empty_dir.go index 4517e45c460..68b15a8bbe3 100644 --- a/pkg/volume/empty_dir/empty_dir.go +++ b/pkg/volume/empty_dir/empty_dir.go @@ -203,7 +203,7 @@ func (ed *emptyDir) GetPath() string { if ed.legacyMode { name = emptyDirPluginLegacyName } - return ed.plugin.host.GetPodVolumeDir(ed.podUID, volume.EscapePluginName(name), ed.volName) + return ed.plugin.host.GetPodVolumeDir(ed.podUID, util.EscapeQualifiedNameForDisk(name), ed.volName) } // TearDown simply discards everything in the directory. diff --git a/pkg/volume/gce_pd/gce_pd.go b/pkg/volume/gce_pd/gce_pd.go index 66c7b28b5a2..cb1f6ccc996 100644 --- a/pkg/volume/gce_pd/gce_pd.go +++ b/pkg/volume/gce_pd/gce_pd.go @@ -24,6 +24,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/types" + "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume" @@ -242,7 +243,7 @@ func (pd *gcePersistentDisk) GetPath() string { if pd.legacyMode { name = gcePersistentDiskPluginLegacyName } - return pd.plugin.host.GetPodVolumeDir(pd.podUID, volume.EscapePluginName(name), pd.volName) + return pd.plugin.host.GetPodVolumeDir(pd.podUID, util.EscapeQualifiedNameForDisk(name), pd.volName) } // Unmounts the bind mount, and detaches the disk only if the PD diff --git a/pkg/volume/git_repo/git_repo.go b/pkg/volume/git_repo/git_repo.go index 995edc0eedc..6265d047b88 100644 --- a/pkg/volume/git_repo/git_repo.go +++ b/pkg/volume/git_repo/git_repo.go @@ -24,6 +24,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/types" + "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume" "github.com/golang/glog" @@ -169,7 +170,7 @@ func (gr *gitRepo) SetUpAt(dir string) error { } func (gr *gitRepo) getMetaDir() string { - return path.Join(gr.plugin.host.GetPodPluginDir(gr.podRef.UID, volume.EscapePluginName(gitRepoPluginName)), gr.volName) + return path.Join(gr.plugin.host.GetPodPluginDir(gr.podRef.UID, util.EscapeQualifiedNameForDisk(gitRepoPluginName)), gr.volName) } func (gr *gitRepo) isReady() bool { @@ -212,7 +213,7 @@ func (gr *gitRepo) GetPath() string { if gr.legacyMode { name = gitRepoPluginLegacyName } - return gr.plugin.host.GetPodVolumeDir(gr.podRef.UID, volume.EscapePluginName(name), gr.volName) + return gr.plugin.host.GetPodVolumeDir(gr.podRef.UID, util.EscapeQualifiedNameForDisk(name), gr.volName) } // TearDown simply deletes everything in the directory. diff --git a/pkg/volume/nfs/nfs.go b/pkg/volume/nfs/nfs.go index 5d0e7205663..612b4d34a4e 100644 --- a/pkg/volume/nfs/nfs.go +++ b/pkg/volume/nfs/nfs.go @@ -21,6 +21,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/types" + "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume" "github.com/golang/glog" ) @@ -146,7 +147,7 @@ func (nfsVolume *nfs) SetUpAt(dir string) error { func (nfsVolume *nfs) GetPath() string { name := nfsPluginName - return nfsVolume.plugin.host.GetPodVolumeDir(nfsVolume.podRef.UID, volume.EscapePluginName(name), nfsVolume.volName) + return nfsVolume.plugin.host.GetPodVolumeDir(nfsVolume.podRef.UID, util.EscapeQualifiedNameForDisk(name), nfsVolume.volName) } func (nfsVolume *nfs) TearDown() error { diff --git a/pkg/volume/plugins.go b/pkg/volume/plugins.go index ecedd4ec6d4..acbfbd8710c 100644 --- a/pkg/volume/plugins.go +++ b/pkg/volume/plugins.go @@ -173,18 +173,3 @@ func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) { } return pm.plugins[matches[0]], nil } - -// EscapePluginName converts a plugin name, which might contain a / into a -// string that is safe to use on-disk. This assumes that the input has already -// been validates as a qualified name. we use "~" rather than ":" here in case -// we ever use a filesystem that doesn't allow ":". -func EscapePluginName(in string) string { - return strings.Replace(in, "/", "~", -1) -} - -// UnescapePluginName converts an escaped plugin name (as per EscapePluginName) -// back to its normal form. This assumes that the input has already been -// validates as a qualified name. -func UnescapePluginName(in string) string { - return strings.Replace(in, "~", "/", -1) -} diff --git a/pkg/volume/secret/secret.go b/pkg/volume/secret/secret.go index 2d176605264..f983e742f6e 100644 --- a/pkg/volume/secret/secret.go +++ b/pkg/volume/secret/secret.go @@ -23,6 +23,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/types" + "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume" "github.com/golang/glog" ) @@ -128,7 +129,7 @@ func (sv *secretVolume) SetUpAt(dir string) error { } func (sv *secretVolume) GetPath() string { - return sv.plugin.host.GetPodVolumeDir(sv.podRef.UID, volume.EscapePluginName(secretPluginName), sv.volName) + return sv.plugin.host.GetPodVolumeDir(sv.podRef.UID, util.EscapeQualifiedNameForDisk(secretPluginName), sv.volName) } func (sv *secretVolume) TearDown() error { diff --git a/pkg/volume/testing.go b/pkg/volume/testing.go index 6a800f2a784..6df40451432 100644 --- a/pkg/volume/testing.go +++ b/pkg/volume/testing.go @@ -23,6 +23,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/types" + "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) // fakeVolumeHost is useful for testing volume plugins. @@ -117,7 +118,7 @@ func (fv *FakeVolume) SetUpAt(dir string) error { } func (fv *FakeVolume) GetPath() string { - return path.Join(fv.Plugin.Host.GetPodVolumeDir(fv.PodUID, EscapePluginName(fv.Plugin.PluginName), fv.VolName)) + return path.Join(fv.Plugin.Host.GetPodVolumeDir(fv.PodUID, util.EscapeQualifiedNameForDisk(fv.Plugin.PluginName), fv.VolName)) } func (fv *FakeVolume) TearDown() error {