Rename pdName -> volumeId for AWS persistent volumes

This commit is contained in:
Justin Santa Barbara 2015-04-07 13:23:12 -07:00
parent aa6051026e
commit 95b68ae0b0
11 changed files with 43 additions and 46 deletions

View File

@ -401,20 +401,17 @@ type ISCSIVolumeSource struct {
// The disk must also be in the same AWS zone as the kubelet. // 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. // A AWS EBS disk can only be mounted as read/write once.
type AWSPersistentDiskVolumeSource struct { type AWSPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in AWS // Unique id of the persistent disk resource. Used to identify the disk in AWS
PDName string `json:"pdName"` VolumeId string `json:"volumeId"`
// Required: Filesystem type to mount. // Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system. // Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs" // Ex. "ext4", "xfs", "ntfs"
// TODO: how do we prevent errors in the filesystem from compromising the machine // TODO: how do we prevent errors in the filesystem from compromising the machine
FSType string `json:"fsType,omitempty"` FSType string `json:"fsType,omitempty"`
// Optional: Partition on the disk to mount. // Optional: Partition on the disk to mount.
// If omitted, kubelet will attempt to mount the device name. // If omitted, kubelet will attempt to mount the device name.
// Ex. For /dev/sda1, this field is "1", for /dev/sda, this field is 0 or empty. // Ex. For /dev/sda1, this field is "1", for /dev/sda, this field is 0 or empty.
Partition int `json:"partition,omitempty"` Partition int `json:"partition,omitempty"`
// Optional: Defaults to false (read/write). ReadOnly here will force // Optional: Defaults to false (read/write). ReadOnly here will force
// the ReadOnly setting in VolumeMounts. // the ReadOnly setting in VolumeMounts.
ReadOnly bool `json:"readOnly,omitempty"` ReadOnly bool `json:"readOnly,omitempty"`

View File

@ -314,8 +314,8 @@ type ISCSIVolumeSource struct {
// The disk must also be in the same AWS zone as the kubelet. // The disk must also be in the same AWS zone as the kubelet.
// A AWS PD can only be mounted on a single machine. // A AWS PD can only be mounted on a single machine.
type AWSPersistentDiskVolumeSource struct { type AWSPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in AWS // Unique id of the PD resource. Used to identify the disk in AWS
PDName string `json:"pdName" description:"unique id of the PD resource in AWS"` VolumeId string `json:"volumeId" description:"unique id of the PD resource in AWS"`
// Required: Filesystem type to mount. // Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system. // Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs" // Ex. "ext4", "xfs", "ntfs"

View File

@ -296,8 +296,8 @@ type GCEPersistentDiskVolumeSource struct {
// The disk must also be in the same AWS zone as the kubelet. // The disk must also be in the same AWS zone as the kubelet.
// A AWS PD can only be mounted on a single machine. // A AWS PD can only be mounted on a single machine.
type AWSPersistentDiskVolumeSource struct { type AWSPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in AWS // Unique id of the PD resource. Used to identify the disk in AWS
PDName string `json:"pdName" description:"unique id of the PD resource in AWS"` VolumeId string `json:"volumeId" description:"unique id of the PD resource in AWS"`
// Required: Filesystem type to mount. // Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system. // Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs" // Ex. "ext4", "xfs", "ntfs"

View File

@ -412,8 +412,8 @@ type GCEPersistentDiskVolumeSource struct {
// The disk must also be in the same AWS zone as the kubelet. // The disk must also be in the same AWS zone as the kubelet.
// A AWS PD can only be mounted on a single machine. // A AWS PD can only be mounted on a single machine.
type AWSPersistentDiskVolumeSource struct { type AWSPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in AWS // Unique id of the PD resource. Used to identify the disk in AWS
PDName string `json:"pdName" description:"unique id of the PD resource in AWS"` VolumeId string `json:"volumeId" description:"unique id of the PD resource in AWS"`
// Required: Filesystem type to mount. // Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system. // Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs" // Ex. "ext4", "xfs", "ntfs"

View File

@ -374,8 +374,8 @@ func validateGCEPersistentDiskVolumeSource(PD *api.GCEPersistentDiskVolumeSource
func validateAWSPersistentDiskVolumeSource(PD *api.AWSPersistentDiskVolumeSource) errs.ValidationErrorList { func validateAWSPersistentDiskVolumeSource(PD *api.AWSPersistentDiskVolumeSource) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{} allErrs := errs.ValidationErrorList{}
if PD.PDName == "" { if PD.VolumeId == "" {
allErrs = append(allErrs, errs.NewFieldRequired("pdName")) allErrs = append(allErrs, errs.NewFieldRequired("volumeId"))
} }
if PD.FSType == "" { if PD.FSType == "" {
allErrs = append(allErrs, errs.NewFieldRequired("fsType")) allErrs = append(allErrs, errs.NewFieldRequired("fsType"))

View File

@ -62,12 +62,12 @@ func isVolumeConflict(volume api.Volume, pod *api.Pod) bool {
} }
} }
if volume.AWSPersistentDisk != nil { if volume.AWSPersistentDisk != nil {
pdName := volume.AWSPersistentDisk.PDName volumeId := volume.AWSPersistentDisk.VolumeId
manifest := &(pod.Spec) manifest := &(pod.Spec)
for ix := range manifest.Volumes { for ix := range manifest.Volumes {
if manifest.Volumes[ix].AWSPersistentDisk != nil && if manifest.Volumes[ix].AWSPersistentDisk != nil &&
manifest.Volumes[ix].AWSPersistentDisk.PDName == pdName { manifest.Volumes[ix].AWSPersistentDisk.VolumeId == volumeId {
return true return true
} }
} }

View File

@ -327,7 +327,7 @@ func TestAWSDiskConflicts(t *testing.T) {
{ {
VolumeSource: api.VolumeSource{ VolumeSource: api.VolumeSource{
AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{ AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{
PDName: "foo", VolumeId: "foo",
}, },
}, },
}, },
@ -338,7 +338,7 @@ func TestAWSDiskConflicts(t *testing.T) {
{ {
VolumeSource: api.VolumeSource{ VolumeSource: api.VolumeSource{
AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{ AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{
PDName: "bar", VolumeId: "bar",
}, },
}, },
}, },

View File

@ -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) { 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 fsType := spec.AWSPersistentDisk.FSType
partition := "" partition := ""
if spec.AWSPersistentDisk.Partition != 0 { if spec.AWSPersistentDisk.Partition != 0 {
@ -88,7 +88,7 @@ func (plugin *awsPersistentDiskPlugin) newBuilderInternal(spec *api.Volume, podU
return &awsPersistentDisk{ return &awsPersistentDisk{
podUID: podUID, podUID: podUID,
volName: spec.Name, volName: spec.Name,
pdName: pdName, volumeId: volumeId,
fsType: fsType, fsType: fsType,
partition: partition, partition: partition,
readOnly: readOnly, readOnly: readOnly,
@ -128,8 +128,8 @@ type pdManager interface {
type awsPersistentDisk struct { type awsPersistentDisk struct {
volName string volName string
podUID types.UID podUID types.UID
// Unique name of the PD, used to find the disk resource in the provider. // Unique id of the PD, used to find the disk resource in the provider.
pdName string volumeId string
// Filesystem type, optional. // Filesystem type, optional.
fsType string fsType string
// Specifies the partition to mount // Specifies the partition to mount
@ -183,7 +183,7 @@ func (pd *awsPersistentDisk) SetUpAt(dir string) error {
return nil 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 { if err := pd.manager.AttachAndMountDisk(pd, globalPDPath); err != nil {
return err return err
} }
@ -232,14 +232,14 @@ func (pd *awsPersistentDisk) SetUpAt(dir string) error {
return nil 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 // Clean up the URI to be more fs-friendly
name := devName name := volumeId
name = strings.Replace(name, "://", "/", -1) name = strings.Replace(name, "://", "/", -1)
return path.Join(host.GetPluginDir(awsPersistentDiskPluginName), "mounts", name) 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") basePath := path.Join(host.GetPluginDir(awsPersistentDiskPluginName), "mounts")
rel, err := filepath.Rel(basePath, globalPath) rel, err := filepath.Rel(basePath, globalPath)
if err != nil { if err != nil {
@ -248,13 +248,13 @@ func getPdNameFromGlobalMount(host volume.VolumeHost, globalPath string) (string
if strings.Contains(rel, "../") { if strings.Contains(rel, "../") {
return "", fmt.Errorf("Unexpected mount path: " + globalPath) return "", fmt.Errorf("Unexpected mount path: " + globalPath)
} }
// Reverse the :// replacement done in makeGlobalPDName // Reverse the :// replacement done in makeGlobalPDPath
pdName := rel volumeId := rel
if strings.HasPrefix(pdName, "aws/") { if strings.HasPrefix(volumeId, "aws/") {
pdName = strings.Replace(pdName, "aws/", "aws://", 1) volumeId = strings.Replace(volumeId, "aws/", "aws://", 1)
} }
glog.V(2).Info("Mapping mount dir ", globalPath, " to pdName ", pdName) glog.V(2).Info("Mapping mount dir ", globalPath, " to volumeId ", volumeId)
return pdName, nil return volumeId, nil
} }
func (pd *awsPersistentDisk) GetPath() string { 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 // 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.pdName is not initially set for volume-cleaners, so set it here. // pd.volumeId is not initially set for volume-cleaners, so set it here.
pd.pdName, err = getPdNameFromGlobalMount(pd.plugin.host, refs[0]) pd.volumeId, err = getVolumeIdFromGlobalMount(pd.plugin.host, refs[0])
if err != nil { 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 return err
} }
if err := pd.manager.DetachDisk(pd); err != nil { 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 return err
} }
} }

View File

@ -72,7 +72,7 @@ type fakePDManager struct{}
// TODO(jonesdl) To fully test this, we could create a loopback device // TODO(jonesdl) To fully test this, we could create a loopback device
// and mount that instead. // and mount that instead.
func (fake *fakePDManager) AttachAndMountDisk(pd *awsPersistentDisk, globalPDPath string) error { 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) err := os.MkdirAll(globalPath, 0750)
if err != nil { if err != nil {
return err return err
@ -81,7 +81,7 @@ func (fake *fakePDManager) AttachAndMountDisk(pd *awsPersistentDisk, globalPDPat
} }
func (fake *fakePDManager) DetachDisk(pd *awsPersistentDisk) error { 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) err := os.RemoveAll(globalPath)
if err != nil { if err != nil {
return err return err
@ -101,7 +101,7 @@ func TestPlugin(t *testing.T) {
Name: "vol1", Name: "vol1",
VolumeSource: api.VolumeSource{ VolumeSource: api.VolumeSource{
AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{ AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{
PDName: "pd", VolumeId: "pd",
FSType: "ext4", FSType: "ext4",
}, },
}, },

View File

@ -40,7 +40,7 @@ func (util *AWSDiskUtil) AttachAndMountDisk(pd *awsPersistentDisk, globalPDPath
if pd.readOnly { if pd.readOnly {
flags = mount.FlagReadOnly flags = mount.FlagReadOnly
} }
devicePath, err := volumes.AttachDisk("", pd.pdName, pd.readOnly) devicePath, err := volumes.AttachDisk("", pd.volumeId, pd.readOnly)
if err != nil { if err != nil {
return err 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. // Unmounts the device and detaches the disk from the kubelet's host machine.
func (util *AWSDiskUtil) DetachDisk(pd *awsPersistentDisk) error { func (util *AWSDiskUtil) DetachDisk(pd *awsPersistentDisk) error {
// Unmount the global PD mount, which should be the only one. // 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 { if err := pd.mounter.Unmount(globalPDPath, 0); err != nil {
glog.V(2).Info("Error unmount dir ", globalPDPath, ": ", err) glog.V(2).Info("Error unmount dir ", globalPDPath, ": ", err)
return err return err
@ -101,11 +101,11 @@ func (util *AWSDiskUtil) DetachDisk(pd *awsPersistentDisk) error {
// Detach the disk // Detach the disk
volumes, err := pd.getVolumeProvider() volumes, err := pd.getVolumeProvider()
if err != nil { 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 return err
} }
if err := volumes.DetachDisk("", pd.pdName); err != nil { if err := volumes.DetachDisk("", pd.volumeId); err != nil {
glog.V(2).Info("Error detaching disk ", pd.pdName, ": ", err) glog.V(2).Info("Error detaching disk ", pd.volumeId, ": ", err)
return err return err
} }
return nil 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 // safe_format_and_mount is a utility script on AWS VMs that probes a persistent disk, and if
// necessary formats it before mounting it. // 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 // TODO: port this script into Go and use it for all Linux platforms
type awsSafeFormatAndMount struct { type awsSafeFormatAndMount struct {
mount.Interface mount.Interface

View File

@ -274,7 +274,7 @@ func testPDPod(diskName, targetHost string, readOnly bool) *api.Pod {
Name: "testpd", Name: "testpd",
VolumeSource: api.VolumeSource{ VolumeSource: api.VolumeSource{
AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{ AWSPersistentDisk: &api.AWSPersistentDiskVolumeSource{
PDName: diskName, VolumeId: diskName,
FSType: "ext4", FSType: "ext4",
ReadOnly: readOnly, ReadOnly: readOnly,
}, },