Rename pdName -> volumeId for AWS persistent volumes
This commit is contained in:
@@ -77,7 +77,7 @@ func (plugin *awsPersistentDiskPlugin) NewBuilder(spec *api.Volume, podRef *api.
|
||||
}
|
||||
|
||||
func (plugin *awsPersistentDiskPlugin) newBuilderInternal(spec *api.Volume, podUID types.UID, manager pdManager, mounter mount.Interface) (volume.Builder, error) {
|
||||
pdName := spec.AWSPersistentDisk.PDName
|
||||
volumeId := spec.AWSPersistentDisk.VolumeId
|
||||
fsType := spec.AWSPersistentDisk.FSType
|
||||
partition := ""
|
||||
if spec.AWSPersistentDisk.Partition != 0 {
|
||||
@@ -88,7 +88,7 @@ func (plugin *awsPersistentDiskPlugin) newBuilderInternal(spec *api.Volume, podU
|
||||
return &awsPersistentDisk{
|
||||
podUID: podUID,
|
||||
volName: spec.Name,
|
||||
pdName: pdName,
|
||||
volumeId: volumeId,
|
||||
fsType: fsType,
|
||||
partition: partition,
|
||||
readOnly: readOnly,
|
||||
@@ -128,8 +128,8 @@ type pdManager interface {
|
||||
type awsPersistentDisk struct {
|
||||
volName string
|
||||
podUID types.UID
|
||||
// Unique name of the PD, used to find the disk resource in the provider.
|
||||
pdName string
|
||||
// Unique id of the PD, used to find the disk resource in the provider.
|
||||
volumeId string
|
||||
// Filesystem type, optional.
|
||||
fsType string
|
||||
// Specifies the partition to mount
|
||||
@@ -183,7 +183,7 @@ func (pd *awsPersistentDisk) SetUpAt(dir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
globalPDPath := makeGlobalPDName(pd.plugin.host, pd.pdName)
|
||||
globalPDPath := makeGlobalPDPath(pd.plugin.host, pd.volumeId)
|
||||
if err := pd.manager.AttachAndMountDisk(pd, globalPDPath); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -232,14 +232,14 @@ func (pd *awsPersistentDisk) SetUpAt(dir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func makeGlobalPDName(host volume.VolumeHost, devName string) string {
|
||||
func makeGlobalPDPath(host volume.VolumeHost, volumeId string) string {
|
||||
// Clean up the URI to be more fs-friendly
|
||||
name := devName
|
||||
name := volumeId
|
||||
name = strings.Replace(name, "://", "/", -1)
|
||||
return path.Join(host.GetPluginDir(awsPersistentDiskPluginName), "mounts", name)
|
||||
}
|
||||
|
||||
func getPdNameFromGlobalMount(host volume.VolumeHost, globalPath string) (string, error) {
|
||||
func getVolumeIdFromGlobalMount(host volume.VolumeHost, globalPath string) (string, error) {
|
||||
basePath := path.Join(host.GetPluginDir(awsPersistentDiskPluginName), "mounts")
|
||||
rel, err := filepath.Rel(basePath, globalPath)
|
||||
if err != nil {
|
||||
@@ -248,13 +248,13 @@ func getPdNameFromGlobalMount(host volume.VolumeHost, globalPath string) (string
|
||||
if strings.Contains(rel, "../") {
|
||||
return "", fmt.Errorf("Unexpected mount path: " + globalPath)
|
||||
}
|
||||
// Reverse the :// replacement done in makeGlobalPDName
|
||||
pdName := rel
|
||||
if strings.HasPrefix(pdName, "aws/") {
|
||||
pdName = strings.Replace(pdName, "aws/", "aws://", 1)
|
||||
// Reverse the :// replacement done in makeGlobalPDPath
|
||||
volumeId := rel
|
||||
if strings.HasPrefix(volumeId, "aws/") {
|
||||
volumeId = strings.Replace(volumeId, "aws/", "aws://", 1)
|
||||
}
|
||||
glog.V(2).Info("Mapping mount dir ", globalPath, " to pdName ", pdName)
|
||||
return pdName, nil
|
||||
glog.V(2).Info("Mapping mount dir ", globalPath, " to volumeId ", volumeId)
|
||||
return volumeId, nil
|
||||
}
|
||||
|
||||
func (pd *awsPersistentDisk) GetPath() string {
|
||||
@@ -294,14 +294,14 @@ func (pd *awsPersistentDisk) TearDownAt(dir string) error {
|
||||
// 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.
|
||||
if len(refs) == 1 {
|
||||
// pd.pdName is not initially set for volume-cleaners, so set it here.
|
||||
pd.pdName, err = getPdNameFromGlobalMount(pd.plugin.host, refs[0])
|
||||
// pd.volumeId is not initially set for volume-cleaners, so set it here.
|
||||
pd.volumeId, err = getVolumeIdFromGlobalMount(pd.plugin.host, refs[0])
|
||||
if err != nil {
|
||||
glog.V(2).Info("Could not determine pdName from mountpoint ", refs[0], ": ", err)
|
||||
glog.V(2).Info("Could not determine volumeId from mountpoint ", refs[0], ": ", err)
|
||||
return err
|
||||
}
|
||||
if err := pd.manager.DetachDisk(pd); err != nil {
|
||||
glog.V(2).Info("Error detaching disk ", pd.pdName, ": ", err)
|
||||
glog.V(2).Info("Error detaching disk ", pd.volumeId, ": ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@@ -72,7 +72,7 @@ type fakePDManager struct{}
|
||||
// TODO(jonesdl) To fully test this, we could create a loopback device
|
||||
// and mount that instead.
|
||||
func (fake *fakePDManager) AttachAndMountDisk(pd *awsPersistentDisk, globalPDPath string) error {
|
||||
globalPath := makeGlobalPDName(pd.plugin.host, pd.pdName)
|
||||
globalPath := makeGlobalPDPath(pd.plugin.host, pd.volumeId)
|
||||
err := os.MkdirAll(globalPath, 0750)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -81,7 +81,7 @@ func (fake *fakePDManager) AttachAndMountDisk(pd *awsPersistentDisk, globalPDPat
|
||||
}
|
||||
|
||||
func (fake *fakePDManager) DetachDisk(pd *awsPersistentDisk) error {
|
||||
globalPath := makeGlobalPDName(pd.plugin.host, pd.pdName)
|
||||
globalPath := makeGlobalPDPath(pd.plugin.host, pd.volumeId)
|
||||
err := os.RemoveAll(globalPath)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -101,8 +101,8 @@ func TestPlugin(t *testing.T) {
|
||||
Name: "vol1",
|
||||
VolumeSource: api.VolumeSource{
|
||||
AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{
|
||||
PDName: "pd",
|
||||
FSType: "ext4",
|
||||
VolumeId: "pd",
|
||||
FSType: "ext4",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ func (util *AWSDiskUtil) AttachAndMountDisk(pd *awsPersistentDisk, globalPDPath
|
||||
if pd.readOnly {
|
||||
flags = mount.FlagReadOnly
|
||||
}
|
||||
devicePath, err := volumes.AttachDisk("", pd.pdName, pd.readOnly)
|
||||
devicePath, err := volumes.AttachDisk("", pd.volumeId, pd.readOnly)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func (util *AWSDiskUtil) AttachAndMountDisk(pd *awsPersistentDisk, globalPDPath
|
||||
// Unmounts the device and detaches the disk from the kubelet's host machine.
|
||||
func (util *AWSDiskUtil) DetachDisk(pd *awsPersistentDisk) error {
|
||||
// Unmount the global PD mount, which should be the only one.
|
||||
globalPDPath := makeGlobalPDName(pd.plugin.host, pd.pdName)
|
||||
globalPDPath := makeGlobalPDPath(pd.plugin.host, pd.volumeId)
|
||||
if err := pd.mounter.Unmount(globalPDPath, 0); err != nil {
|
||||
glog.V(2).Info("Error unmount dir ", globalPDPath, ": ", err)
|
||||
return err
|
||||
@@ -101,11 +101,11 @@ func (util *AWSDiskUtil) DetachDisk(pd *awsPersistentDisk) error {
|
||||
// Detach the disk
|
||||
volumes, err := pd.getVolumeProvider()
|
||||
if err != nil {
|
||||
glog.V(2).Info("Error getting volume provider for pd ", pd.pdName, ": ", err)
|
||||
glog.V(2).Info("Error getting volume provider for volumeId ", pd.volumeId, ": ", err)
|
||||
return err
|
||||
}
|
||||
if err := volumes.DetachDisk("", pd.pdName); err != nil {
|
||||
glog.V(2).Info("Error detaching disk ", pd.pdName, ": ", err)
|
||||
if err := volumes.DetachDisk("", pd.volumeId); err != nil {
|
||||
glog.V(2).Info("Error detaching disk ", pd.volumeId, ": ", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -113,7 +113,7 @@ func (util *AWSDiskUtil) DetachDisk(pd *awsPersistentDisk) error {
|
||||
|
||||
// safe_format_and_mount is a utility script on AWS VMs that probes a persistent disk, and if
|
||||
// necessary formats it before mounting it.
|
||||
// This eliminates the necesisty to format a PD before it is used with a Pod on AWS.
|
||||
// This eliminates the necessity to format a PD before it is used with a Pod on AWS.
|
||||
// TODO: port this script into Go and use it for all Linux platforms
|
||||
type awsSafeFormatAndMount struct {
|
||||
mount.Interface
|
||||
|
Reference in New Issue
Block a user