Skip to content

Commit

Permalink
Rename pdName -> volumeId for AWS persistent volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Apr 7, 2015
1 parent 495acbd commit dadf2a1
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions pkg/api/types.go
Expand Up @@ -379,8 +379,8 @@ type GCEPersistentDiskVolumeSource struct {
// The disk must also be in the same AWS zone as the kubelet.
// A AWS EBS disk can only be mounted as read/write once.
type AWSPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in AWS
PDName string `json:"pdName"`
// Unique id of the persistent disk resource. Used to identify the disk in AWS
VolumeId string `json:"volumeId"`
// Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs"
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1beta1/types.go
Expand Up @@ -287,8 +287,8 @@ type GCEPersistentDiskVolumeSource struct {
// The disk must also be in the same AWS zone as the kubelet.
// A AWS PD can only be mounted on a single machine.
type AWSPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in AWS
PDName string `json:"pdName" description:"unique id of the PD resource in AWS"`
// Unique id of the PD resource. Used to identify the disk in AWS
VolumeId string `json:"volumeId" description:"unique id of the PD resource in AWS"`
// Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs"
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1beta2/types.go
Expand Up @@ -288,8 +288,8 @@ type GCEPersistentDiskVolumeSource struct {
// The disk must also be in the same AWS zone as the kubelet.
// A AWS PD can only be mounted on a single machine.
type AWSPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in AWS
PDName string `json:"pdName" description:"unique id of the PD resource in AWS"`
// Unique id of the PD resource. Used to identify the disk in AWS
VolumeId string `json:"volumeId" description:"unique id of the PD resource in AWS"`
// Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs"
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1beta3/types.go
Expand Up @@ -391,8 +391,8 @@ type GCEPersistentDiskVolumeSource struct {
// The disk must also be in the same AWS zone as the kubelet.
// A AWS PD can only be mounted on a single machine.
type AWSPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in AWS
PDName string `json:"pdName" description:"unique id of the PD resource in AWS"`
// Unique id of the PD resource. Used to identify the disk in AWS
VolumeId string `json:"volumeId" description:"unique id of the PD resource in AWS"`
// Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs"
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/validation/validation.go
Expand Up @@ -347,8 +347,8 @@ func validateGCEPersistentDiskVolumeSource(PD *api.GCEPersistentDiskVolumeSource

func validateAWSPersistentDiskVolumeSource(PD *api.AWSPersistentDiskVolumeSource) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
if PD.PDName == "" {
allErrs = append(allErrs, errs.NewFieldRequired("pdName"))
if PD.VolumeId == "" {
allErrs = append(allErrs, errs.NewFieldRequired("volumeId"))
}
if PD.FSType == "" {
allErrs = append(allErrs, errs.NewFieldRequired("fsType"))
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/predicates.go
Expand Up @@ -62,12 +62,12 @@ func isVolumeConflict(volume api.Volume, pod *api.Pod) bool {
}
}
if volume.AWSPersistentDisk != nil {
pdName := volume.AWSPersistentDisk.PDName
volumeId := volume.AWSPersistentDisk.VolumeId

manifest := &(pod.Spec)
for ix := range manifest.Volumes {
if manifest.Volumes[ix].AWSPersistentDisk != nil &&
manifest.Volumes[ix].AWSPersistentDisk.PDName == pdName {
manifest.Volumes[ix].AWSPersistentDisk.VolumeId == volumeId {
return true
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/predicates_test.go
Expand Up @@ -327,7 +327,7 @@ func TestAWSDiskConflicts(t *testing.T) {
{
VolumeSource: api.VolumeSource{
AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{
PDName: "foo",
VolumeId: "foo",
},
},
},
Expand All @@ -338,7 +338,7 @@ func TestAWSDiskConflicts(t *testing.T) {
{
VolumeSource: api.VolumeSource{
AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{
PDName: "bar",
VolumeId: "bar",
},
},
},
Expand Down
36 changes: 18 additions & 18 deletions pkg/volume/aws_pd/aws_pd.go
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/volume/aws_pd/aws_pd_test.go
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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",
},
},
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/volume/aws_pd/aws_util.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -101,19 +101,19 @@ 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
}

// 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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/pd.go
Expand Up @@ -272,7 +272,7 @@ func testPDPod(diskName, targetHost string, readOnly bool) *api.Pod {
Name: "testpd",
VolumeSource: api.VolumeSource{
AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{
PDName: diskName,
VolumeId: diskName,
FSType: "ext4",
ReadOnly: readOnly,
},
Expand Down

0 comments on commit dadf2a1

Please sign in to comment.