Improved internal naming from 'pd' to 'ebs' to match the volume

This commit is contained in:
markturansky 2015-06-29 13:00:33 -04:00
parent d63e35247f
commit 98ec116f3f

View File

@ -122,9 +122,9 @@ func (plugin *awsElasticBlockStorePlugin) newCleanerInternal(volName string, pod
// Abstract interface to PD operations. // Abstract interface to PD operations.
type pdManager interface { type pdManager interface {
// Attaches the disk to the kubelet's host machine. // Attaches the disk to the kubelet's host machine.
AttachAndMountDisk(pd *awsElasticBlockStore, globalPDPath string) error AttachAndMountDisk(ebs *awsElasticBlockStore, globalPDPath string) error
// Detaches the disk from the kubelet's host machine. // Detaches the disk from the kubelet's host machine.
DetachDisk(pd *awsElasticBlockStore) error DetachDisk(ebs *awsElasticBlockStore) error
} }
// awsElasticBlockStore volumes are disk resources provided by Google Compute Engine // awsElasticBlockStore volumes are disk resources provided by Google Compute Engine
@ -149,15 +149,15 @@ type awsElasticBlockStore struct {
plugin *awsElasticBlockStorePlugin plugin *awsElasticBlockStorePlugin
} }
func detachDiskLogError(pd *awsElasticBlockStore) { func detachDiskLogError(ebs *awsElasticBlockStore) {
err := pd.manager.DetachDisk(pd) err := ebs.manager.DetachDisk(ebs)
if err != nil { if err != nil {
glog.Warningf("Failed to detach disk: %v (%v)", pd, err) glog.Warningf("Failed to detach disk: %v (%v)", ebs, err)
} }
} }
// getVolumeProvider returns the AWS Volumes interface // getVolumeProvider returns the AWS Volumes interface
func (pd *awsElasticBlockStore) getVolumeProvider() (aws_cloud.Volumes, error) { func (ebs *awsElasticBlockStore) getVolumeProvider() (aws_cloud.Volumes, error) {
name := "aws" name := "aws"
cloud, err := cloudprovider.GetCloudProvider(name, nil) cloud, err := cloudprovider.GetCloudProvider(name, nil)
if err != nil { if err != nil {
@ -171,14 +171,14 @@ func (pd *awsElasticBlockStore) getVolumeProvider() (aws_cloud.Volumes, error) {
} }
// SetUp attaches the disk and bind mounts to the volume path. // SetUp attaches the disk and bind mounts to the volume path.
func (pd *awsElasticBlockStore) SetUp() error { func (ebs *awsElasticBlockStore) SetUp() error {
return pd.SetUpAt(pd.GetPath()) return ebs.SetUpAt(ebs.GetPath())
} }
// SetUpAt attaches the disk and bind mounts to the volume path. // SetUpAt attaches the disk and bind mounts to the volume path.
func (pd *awsElasticBlockStore) SetUpAt(dir string) error { func (ebs *awsElasticBlockStore) SetUpAt(dir string) error {
// TODO: handle failed mounts here. // TODO: handle failed mounts here.
mountpoint, err := pd.mounter.IsMountPoint(dir) mountpoint, err := ebs.mounter.IsMountPoint(dir)
glog.V(4).Infof("PersistentDisk set up: %s %v %v", dir, mountpoint, err) glog.V(4).Infof("PersistentDisk set up: %s %v %v", dir, mountpoint, err)
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
return err return err
@ -187,35 +187,35 @@ func (pd *awsElasticBlockStore) SetUpAt(dir string) error {
return nil return nil
} }
globalPDPath := makeGlobalPDPath(pd.plugin.host, pd.volumeID) globalPDPath := makeGlobalPDPath(ebs.plugin.host, ebs.volumeID)
if err := pd.manager.AttachAndMountDisk(pd, globalPDPath); err != nil { if err := ebs.manager.AttachAndMountDisk(ebs, globalPDPath); err != nil {
return err return err
} }
if err := os.MkdirAll(dir, 0750); err != nil { if err := os.MkdirAll(dir, 0750); err != nil {
// TODO: we should really eject the attach/detach out into its own control loop. // TODO: we should really eject the attach/detach out into its own control loop.
detachDiskLogError(pd) detachDiskLogError(ebs)
return err return err
} }
// Perform a bind mount to the full path to allow duplicate mounts of the same PD. // Perform a bind mount to the full path to allow duplicate mounts of the same PD.
options := []string{"bind"} options := []string{"bind"}
if pd.readOnly { if ebs.readOnly {
options = append(options, "ro") options = append(options, "ro")
} }
err = pd.mounter.Mount(globalPDPath, dir, "", options) err = ebs.mounter.Mount(globalPDPath, dir, "", options)
if err != nil { if err != nil {
mountpoint, mntErr := pd.mounter.IsMountPoint(dir) mountpoint, mntErr := ebs.mounter.IsMountPoint(dir)
if mntErr != nil { if mntErr != nil {
glog.Errorf("isMountpoint check failed: %v", mntErr) glog.Errorf("isMountpoint check failed: %v", mntErr)
return err return err
} }
if mountpoint { if mountpoint {
if mntErr = pd.mounter.Unmount(dir); mntErr != nil { if mntErr = ebs.mounter.Unmount(dir); mntErr != nil {
glog.Errorf("Failed to unmount: %v", mntErr) glog.Errorf("Failed to unmount: %v", mntErr)
return err return err
} }
mountpoint, mntErr := pd.mounter.IsMountPoint(dir) mountpoint, mntErr := ebs.mounter.IsMountPoint(dir)
if mntErr != nil { if mntErr != nil {
glog.Errorf("isMountpoint check failed: %v", mntErr) glog.Errorf("isMountpoint check failed: %v", mntErr)
return err return err
@ -228,7 +228,7 @@ func (pd *awsElasticBlockStore) SetUpAt(dir string) error {
} }
os.Remove(dir) os.Remove(dir)
// TODO: we should really eject the attach/detach out into its own control loop. // TODO: we should really eject the attach/detach out into its own control loop.
detachDiskLogError(pd) detachDiskLogError(ebs)
return err return err
} }
@ -260,21 +260,21 @@ func getVolumeIDFromGlobalMount(host volume.VolumeHost, globalPath string) (stri
return volumeID, nil return volumeID, nil
} }
func (pd *awsElasticBlockStore) GetPath() string { func (ebs *awsElasticBlockStore) GetPath() string {
name := awsElasticBlockStorePluginName name := awsElasticBlockStorePluginName
return pd.plugin.host.GetPodVolumeDir(pd.podUID, util.EscapeQualifiedNameForDisk(name), pd.volName) return ebs.plugin.host.GetPodVolumeDir(ebs.podUID, util.EscapeQualifiedNameForDisk(name), ebs.volName)
} }
// Unmounts the bind mount, and detaches the disk only if the PD // Unmounts the bind mount, and detaches the disk only if the PD
// resource was the last reference to that disk on the kubelet. // resource was the last reference to that disk on the kubelet.
func (pd *awsElasticBlockStore) TearDown() error { func (ebs *awsElasticBlockStore) TearDown() error {
return pd.TearDownAt(pd.GetPath()) return ebs.TearDownAt(ebs.GetPath())
} }
// Unmounts the bind mount, and detaches the disk only if the PD // Unmounts the bind mount, and detaches the disk only if the PD
// resource was the last reference to that disk on the kubelet. // resource was the last reference to that disk on the kubelet.
func (pd *awsElasticBlockStore) TearDownAt(dir string) error { func (ebs *awsElasticBlockStore) TearDownAt(dir string) error {
mountpoint, err := pd.mounter.IsMountPoint(dir) mountpoint, err := ebs.mounter.IsMountPoint(dir)
if err != nil { if err != nil {
glog.V(2).Info("Error checking if mountpoint ", dir, ": ", err) glog.V(2).Info("Error checking if mountpoint ", dir, ": ", err)
return err return err
@ -284,7 +284,7 @@ func (pd *awsElasticBlockStore) TearDownAt(dir string) error {
return os.Remove(dir) return os.Remove(dir)
} }
refs, err := mount.GetMountRefs(pd.mounter, dir) refs, err := mount.GetMountRefs(ebs.mounter, dir)
if err != nil { if err != nil {
glog.V(2).Info("Error getting mountrefs for ", dir, ": ", err) glog.V(2).Info("Error getting mountrefs for ", dir, ": ", err)
return err return err
@ -293,27 +293,27 @@ func (pd *awsElasticBlockStore) TearDownAt(dir string) error {
glog.Warning("Did not find pod-mount for ", dir, " during tear-down") glog.Warning("Did not find pod-mount for ", dir, " during tear-down")
} }
// Unmount the bind-mount inside this pod // Unmount the bind-mount inside this pod
if err := pd.mounter.Unmount(dir); err != nil { if err := ebs.mounter.Unmount(dir); err != nil {
glog.V(2).Info("Error unmounting dir ", dir, ": ", err) glog.V(2).Info("Error unmounting dir ", dir, ": ", err)
return err return err
} }
// If len(refs) is 1, then all bind mounts have been removed, and the // If len(refs) is 1, then all bind mounts have been removed, and the
// remaining reference is the global mount. It is safe to detach. // remaining reference is the global mount. It is safe to detach.
if len(refs) == 1 { if len(refs) == 1 {
// pd.volumeID is not initially set for volume-cleaners, so set it here. // ebs.volumeID is not initially set for volume-cleaners, so set it here.
pd.volumeID, err = getVolumeIDFromGlobalMount(pd.plugin.host, refs[0]) ebs.volumeID, err = getVolumeIDFromGlobalMount(ebs.plugin.host, refs[0])
if err != nil { if err != nil {
glog.V(2).Info("Could not determine volumeID from mountpoint ", refs[0], ": ", err) glog.V(2).Info("Could not determine volumeID from mountpoint ", refs[0], ": ", err)
return err return err
} }
if err := pd.manager.DetachDisk(pd); err != nil { if err := ebs.manager.DetachDisk(ebs); err != nil {
glog.V(2).Info("Error detaching disk ", pd.volumeID, ": ", err) glog.V(2).Info("Error detaching disk ", ebs.volumeID, ": ", err)
return err return err
} }
} else { } else {
glog.V(2).Infof("Found multiple refs; won't detach EBS volume: %v", refs) glog.V(2).Infof("Found multiple refs; won't detach EBS volume: %v", refs)
} }
mountpoint, mntErr := pd.mounter.IsMountPoint(dir) mountpoint, mntErr := ebs.mounter.IsMountPoint(dir)
if mntErr != nil { if mntErr != nil {
glog.Errorf("isMountpoint check failed: %v", mntErr) glog.Errorf("isMountpoint check failed: %v", mntErr)
return err return err