diff --git a/api/swagger-spec/v1.json b/api/swagger-spec/v1.json
index a09b10ff663..8a98acd64e5 100644
--- a/api/swagger-spec/v1.json
+++ b/api/swagger-spec/v1.json
@@ -16765,9 +16765,9 @@
"volumesInUse": {
"type": "array",
"items": {
- "$ref": "v1.UniqueDeviceName"
+ "$ref": "v1.UniqueVolumeName"
},
- "description": "List of volumes in use (mounted) by the node."
+ "description": "List of attachable volume devices in use (mounted) by the node."
}
}
},
@@ -16926,8 +16926,8 @@
}
}
},
- "v1.UniqueDeviceName": {
- "id": "v1.UniqueDeviceName",
+ "v1.UniqueVolumeName": {
+ "id": "v1.UniqueVolumeName",
"properties": {}
},
"v1.PersistentVolumeClaimList": {
diff --git a/docs/api-reference/v1/definitions.html b/docs/api-reference/v1/definitions.html
index e365f9c2ac8..aedc6fda077 100755
--- a/docs/api-reference/v1/definitions.html
+++ b/docs/api-reference/v1/definitions.html
@@ -594,10 +594,6 @@ span.icon > [class^="icon-"], span.icon > [class*=" icon-"] { cursor: default; }
-
-
v1.EndpointSubset
@@ -4757,9 +4755,9 @@ The resulting set of endpoints can be viewed as:
volumesInUse |
-List of volumes in use (mounted) by the node. |
+List of attachable volume devices in use (mounted) by the node. |
false |
-v1.UniqueDeviceName array |
+v1.UniqueVolumeName array |
|
diff --git a/pkg/api/deep_copy_generated.go b/pkg/api/deep_copy_generated.go
index 8501160ecf7..69754ee3e71 100644
--- a/pkg/api/deep_copy_generated.go
+++ b/pkg/api/deep_copy_generated.go
@@ -1603,7 +1603,7 @@ func DeepCopy_api_NodeStatus(in NodeStatus, out *NodeStatus, c *conversion.Clone
}
if in.VolumesInUse != nil {
in, out := in.VolumesInUse, &out.VolumesInUse
- *out = make([]UniqueDeviceName, len(in))
+ *out = make([]UniqueVolumeName, len(in))
for i := range in {
(*out)[i] = in[i]
}
diff --git a/pkg/api/types.generated.go b/pkg/api/types.generated.go
index 6abe187dbf2..507d92e8464 100644
--- a/pkg/api/types.generated.go
+++ b/pkg/api/types.generated.go
@@ -36754,7 +36754,7 @@ func (x *NodeStatus) CodecEncodeSelf(e *codec1978.Encoder) {
_ = yym32
if false {
} else {
- h.encSliceUniqueDeviceName(([]UniqueDeviceName)(x.VolumesInUse), e)
+ h.encSliceUniqueVolumeName(([]UniqueVolumeName)(x.VolumesInUse), e)
}
}
} else {
@@ -36772,7 +36772,7 @@ func (x *NodeStatus) CodecEncodeSelf(e *codec1978.Encoder) {
_ = yym33
if false {
} else {
- h.encSliceUniqueDeviceName(([]UniqueDeviceName)(x.VolumesInUse), e)
+ h.encSliceUniqueVolumeName(([]UniqueVolumeName)(x.VolumesInUse), e)
}
}
}
@@ -36917,7 +36917,7 @@ func (x *NodeStatus) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
_ = yym16
if false {
} else {
- h.decSliceUniqueDeviceName((*[]UniqueDeviceName)(yyv15), d)
+ h.decSliceUniqueVolumeName((*[]UniqueVolumeName)(yyv15), d)
}
}
default:
@@ -37103,7 +37103,7 @@ func (x *NodeStatus) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
_ = yym30
if false {
} else {
- h.decSliceUniqueDeviceName((*[]UniqueDeviceName)(yyv29), d)
+ h.decSliceUniqueVolumeName((*[]UniqueVolumeName)(yyv29), d)
}
}
for {
@@ -37122,7 +37122,7 @@ func (x *NodeStatus) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
}
-func (x UniqueDeviceName) CodecEncodeSelf(e *codec1978.Encoder) {
+func (x UniqueVolumeName) CodecEncodeSelf(e *codec1978.Encoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperEncoder(e)
_, _, _ = h, z, r
@@ -37135,7 +37135,7 @@ func (x UniqueDeviceName) CodecEncodeSelf(e *codec1978.Encoder) {
}
}
-func (x *UniqueDeviceName) CodecDecodeSelf(d *codec1978.Decoder) {
+func (x *UniqueVolumeName) CodecDecodeSelf(d *codec1978.Decoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r
@@ -57367,7 +57367,7 @@ func (x codecSelfer1234) decSliceContainerImage(v *[]ContainerImage, d *codec197
}
}
-func (x codecSelfer1234) encSliceUniqueDeviceName(v []UniqueDeviceName, e *codec1978.Encoder) {
+func (x codecSelfer1234) encSliceUniqueVolumeName(v []UniqueVolumeName, e *codec1978.Encoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperEncoder(e)
_, _, _ = h, z, r
@@ -57379,7 +57379,7 @@ func (x codecSelfer1234) encSliceUniqueDeviceName(v []UniqueDeviceName, e *codec
z.EncSendContainerState(codecSelfer_containerArrayEnd1234)
}
-func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *codec1978.Decoder) {
+func (x codecSelfer1234) decSliceUniqueVolumeName(v *[]UniqueVolumeName, d *codec1978.Decoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r
@@ -57390,7 +57390,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
_ = yyc1
if yyl1 == 0 {
if yyv1 == nil {
- yyv1 = []UniqueDeviceName{}
+ yyv1 = []UniqueVolumeName{}
yyc1 = true
} else if len(yyv1) != 0 {
yyv1 = yyv1[:0]
@@ -57408,10 +57408,10 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
if yyrl1 <= cap(yyv1) {
yyv1 = yyv1[:yyrl1]
} else {
- yyv1 = make([]UniqueDeviceName, yyrl1)
+ yyv1 = make([]UniqueVolumeName, yyrl1)
}
} else {
- yyv1 = make([]UniqueDeviceName, yyrl1)
+ yyv1 = make([]UniqueVolumeName, yyrl1)
}
yyc1 = true
yyrr1 = len(yyv1)
@@ -57425,7 +57425,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
if r.TryDecodeAsNil() {
yyv1[yyj1] = ""
} else {
- yyv1[yyj1] = UniqueDeviceName(r.DecodeString())
+ yyv1[yyj1] = UniqueVolumeName(r.DecodeString())
}
}
@@ -57436,7 +57436,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
if r.TryDecodeAsNil() {
yyv1[yyj1] = ""
} else {
- yyv1[yyj1] = UniqueDeviceName(r.DecodeString())
+ yyv1[yyj1] = UniqueVolumeName(r.DecodeString())
}
}
@@ -57447,7 +57447,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
for ; !r.CheckBreak(); yyj1++ {
if yyj1 >= len(yyv1) {
- yyv1 = append(yyv1, "") // var yyz1 UniqueDeviceName
+ yyv1 = append(yyv1, "") // var yyz1 UniqueVolumeName
yyc1 = true
}
yyh1.ElemContainerState(yyj1)
@@ -57455,7 +57455,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
if r.TryDecodeAsNil() {
yyv1[yyj1] = ""
} else {
- yyv1[yyj1] = UniqueDeviceName(r.DecodeString())
+ yyv1[yyj1] = UniqueVolumeName(r.DecodeString())
}
} else {
@@ -57467,7 +57467,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
yyv1 = yyv1[:yyj1]
yyc1 = true
} else if yyj1 == 0 && yyv1 == nil {
- yyv1 = []UniqueDeviceName{}
+ yyv1 = []UniqueVolumeName{}
yyc1 = true
}
}
diff --git a/pkg/api/types.go b/pkg/api/types.go
index 5304760ee2f..8fa7aa3ddcc 100644
--- a/pkg/api/types.go
+++ b/pkg/api/types.go
@@ -1987,11 +1987,11 @@ type NodeStatus struct {
NodeInfo NodeSystemInfo `json:"nodeInfo,omitempty"`
// List of container images on this node
Images []ContainerImage `json:"images,omitempty"`
- // List of attachable volume devices in use (mounted) by the node.
- VolumesInUse []UniqueDeviceName `json:"volumesInUse,omitempty"`
+ // List of attachable volumes in use (mounted) by the node.
+ VolumesInUse []UniqueVolumeName `json:"volumesInUse,omitempty"`
}
-type UniqueDeviceName string
+type UniqueVolumeName string
// Describe a container image
type ContainerImage struct {
diff --git a/pkg/api/v1/conversion_generated.go b/pkg/api/v1/conversion_generated.go
index d2f9548a5a7..46ee53b4b73 100644
--- a/pkg/api/v1/conversion_generated.go
+++ b/pkg/api/v1/conversion_generated.go
@@ -3390,9 +3390,9 @@ func autoConvert_v1_NodeStatus_To_api_NodeStatus(in *NodeStatus, out *api.NodeSt
}
if in.VolumesInUse != nil {
in, out := &in.VolumesInUse, &out.VolumesInUse
- *out = make([]api.UniqueDeviceName, len(*in))
+ *out = make([]api.UniqueVolumeName, len(*in))
for i := range *in {
- (*out)[i] = api.UniqueDeviceName((*in)[i])
+ (*out)[i] = api.UniqueVolumeName((*in)[i])
}
} else {
out.VolumesInUse = nil
@@ -3473,9 +3473,9 @@ func autoConvert_api_NodeStatus_To_v1_NodeStatus(in *api.NodeStatus, out *NodeSt
}
if in.VolumesInUse != nil {
in, out := &in.VolumesInUse, &out.VolumesInUse
- *out = make([]UniqueDeviceName, len(*in))
+ *out = make([]UniqueVolumeName, len(*in))
for i := range *in {
- (*out)[i] = UniqueDeviceName((*in)[i])
+ (*out)[i] = UniqueVolumeName((*in)[i])
}
} else {
out.VolumesInUse = nil
diff --git a/pkg/api/v1/deep_copy_generated.go b/pkg/api/v1/deep_copy_generated.go
index a4cb2c8fd3b..b0d4ce07f19 100644
--- a/pkg/api/v1/deep_copy_generated.go
+++ b/pkg/api/v1/deep_copy_generated.go
@@ -1550,7 +1550,7 @@ func DeepCopy_v1_NodeStatus(in NodeStatus, out *NodeStatus, c *conversion.Cloner
}
if in.VolumesInUse != nil {
in, out := in.VolumesInUse, &out.VolumesInUse
- *out = make([]UniqueDeviceName, len(in))
+ *out = make([]UniqueVolumeName, len(in))
for i := range in {
(*out)[i] = in[i]
}
diff --git a/pkg/api/v1/generated.pb.go b/pkg/api/v1/generated.pb.go
index 87eba24d4ed..460db2e15b5 100644
--- a/pkg/api/v1/generated.pb.go
+++ b/pkg/api/v1/generated.pb.go
@@ -21633,7 +21633,7 @@ func (m *NodeStatus) Unmarshal(data []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
- m.VolumesInUse = append(m.VolumesInUse, UniqueDeviceName(data[iNdEx:postIndex]))
+ m.VolumesInUse = append(m.VolumesInUse, UniqueVolumeName(data[iNdEx:postIndex]))
iNdEx = postIndex
default:
iNdEx = preIndex
diff --git a/pkg/api/v1/generated.proto b/pkg/api/v1/generated.proto
index f8b1fe247e6..b126e085ad7 100644
--- a/pkg/api/v1/generated.proto
+++ b/pkg/api/v1/generated.proto
@@ -1304,7 +1304,7 @@ message NodeStatus {
// List of container images on this node
repeated ContainerImage images = 8;
- // List of volumes in use (mounted) by the node.
+ // List of attachable volume devices in use (mounted) by the node.
repeated string volumesInUse = 9;
}
diff --git a/pkg/api/v1/types.generated.go b/pkg/api/v1/types.generated.go
index b381d52b44e..ad877e98e47 100644
--- a/pkg/api/v1/types.generated.go
+++ b/pkg/api/v1/types.generated.go
@@ -36559,7 +36559,7 @@ func (x *NodeStatus) CodecEncodeSelf(e *codec1978.Encoder) {
_ = yym32
if false {
} else {
- h.encSliceUniqueDeviceName(([]UniqueDeviceName)(x.VolumesInUse), e)
+ h.encSliceUniqueVolumeName(([]UniqueVolumeName)(x.VolumesInUse), e)
}
}
} else {
@@ -36577,7 +36577,7 @@ func (x *NodeStatus) CodecEncodeSelf(e *codec1978.Encoder) {
_ = yym33
if false {
} else {
- h.encSliceUniqueDeviceName(([]UniqueDeviceName)(x.VolumesInUse), e)
+ h.encSliceUniqueVolumeName(([]UniqueVolumeName)(x.VolumesInUse), e)
}
}
}
@@ -36722,7 +36722,7 @@ func (x *NodeStatus) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
_ = yym16
if false {
} else {
- h.decSliceUniqueDeviceName((*[]UniqueDeviceName)(yyv15), d)
+ h.decSliceUniqueVolumeName((*[]UniqueVolumeName)(yyv15), d)
}
}
default:
@@ -36908,7 +36908,7 @@ func (x *NodeStatus) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
_ = yym30
if false {
} else {
- h.decSliceUniqueDeviceName((*[]UniqueDeviceName)(yyv29), d)
+ h.decSliceUniqueVolumeName((*[]UniqueVolumeName)(yyv29), d)
}
}
for {
@@ -36927,7 +36927,7 @@ func (x *NodeStatus) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
}
-func (x UniqueDeviceName) CodecEncodeSelf(e *codec1978.Encoder) {
+func (x UniqueVolumeName) CodecEncodeSelf(e *codec1978.Encoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperEncoder(e)
_, _, _ = h, z, r
@@ -36940,7 +36940,7 @@ func (x UniqueDeviceName) CodecEncodeSelf(e *codec1978.Encoder) {
}
}
-func (x *UniqueDeviceName) CodecDecodeSelf(d *codec1978.Decoder) {
+func (x *UniqueVolumeName) CodecDecodeSelf(d *codec1978.Decoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r
@@ -57420,7 +57420,7 @@ func (x codecSelfer1234) decSliceContainerImage(v *[]ContainerImage, d *codec197
}
}
-func (x codecSelfer1234) encSliceUniqueDeviceName(v []UniqueDeviceName, e *codec1978.Encoder) {
+func (x codecSelfer1234) encSliceUniqueVolumeName(v []UniqueVolumeName, e *codec1978.Encoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperEncoder(e)
_, _, _ = h, z, r
@@ -57432,7 +57432,7 @@ func (x codecSelfer1234) encSliceUniqueDeviceName(v []UniqueDeviceName, e *codec
z.EncSendContainerState(codecSelfer_containerArrayEnd1234)
}
-func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *codec1978.Decoder) {
+func (x codecSelfer1234) decSliceUniqueVolumeName(v *[]UniqueVolumeName, d *codec1978.Decoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r
@@ -57443,7 +57443,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
_ = yyc1
if yyl1 == 0 {
if yyv1 == nil {
- yyv1 = []UniqueDeviceName{}
+ yyv1 = []UniqueVolumeName{}
yyc1 = true
} else if len(yyv1) != 0 {
yyv1 = yyv1[:0]
@@ -57461,10 +57461,10 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
if yyrl1 <= cap(yyv1) {
yyv1 = yyv1[:yyrl1]
} else {
- yyv1 = make([]UniqueDeviceName, yyrl1)
+ yyv1 = make([]UniqueVolumeName, yyrl1)
}
} else {
- yyv1 = make([]UniqueDeviceName, yyrl1)
+ yyv1 = make([]UniqueVolumeName, yyrl1)
}
yyc1 = true
yyrr1 = len(yyv1)
@@ -57478,7 +57478,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
if r.TryDecodeAsNil() {
yyv1[yyj1] = ""
} else {
- yyv1[yyj1] = UniqueDeviceName(r.DecodeString())
+ yyv1[yyj1] = UniqueVolumeName(r.DecodeString())
}
}
@@ -57489,7 +57489,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
if r.TryDecodeAsNil() {
yyv1[yyj1] = ""
} else {
- yyv1[yyj1] = UniqueDeviceName(r.DecodeString())
+ yyv1[yyj1] = UniqueVolumeName(r.DecodeString())
}
}
@@ -57500,7 +57500,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
for ; !r.CheckBreak(); yyj1++ {
if yyj1 >= len(yyv1) {
- yyv1 = append(yyv1, "") // var yyz1 UniqueDeviceName
+ yyv1 = append(yyv1, "") // var yyz1 UniqueVolumeName
yyc1 = true
}
yyh1.ElemContainerState(yyj1)
@@ -57508,7 +57508,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
if r.TryDecodeAsNil() {
yyv1[yyj1] = ""
} else {
- yyv1[yyj1] = UniqueDeviceName(r.DecodeString())
+ yyv1[yyj1] = UniqueVolumeName(r.DecodeString())
}
} else {
@@ -57520,7 +57520,7 @@ func (x codecSelfer1234) decSliceUniqueDeviceName(v *[]UniqueDeviceName, d *code
yyv1 = yyv1[:yyj1]
yyc1 = true
} else if yyj1 == 0 && yyv1 == nil {
- yyv1 = []UniqueDeviceName{}
+ yyv1 = []UniqueVolumeName{}
yyc1 = true
}
}
diff --git a/pkg/api/v1/types.go b/pkg/api/v1/types.go
index 3942099e83c..dfff57d5b08 100644
--- a/pkg/api/v1/types.go
+++ b/pkg/api/v1/types.go
@@ -2386,11 +2386,11 @@ type NodeStatus struct {
NodeInfo NodeSystemInfo `json:"nodeInfo,omitempty" protobuf:"bytes,7,opt,name=nodeInfo"`
// List of container images on this node
Images []ContainerImage `json:"images,omitempty" protobuf:"bytes,8,rep,name=images"`
- // List of volumes in use (mounted) by the node.
- VolumesInUse []UniqueDeviceName `json:"volumesInUse,omitempty" protobuf:"bytes,9,rep,name=volumesInUse"`
+ // List of attachable volume devices in use (mounted) by the node.
+ VolumesInUse []UniqueVolumeName `json:"volumesInUse,omitempty" protobuf:"bytes,9,rep,name=volumesInUse"`
}
-type UniqueDeviceName string
+type UniqueVolumeName string
// Describe a container image
type ContainerImage struct {
diff --git a/pkg/api/v1/types_swagger_doc_generated.go b/pkg/api/v1/types_swagger_doc_generated.go
index cb85f338d7c..10a6ddcb3f2 100644
--- a/pkg/api/v1/types_swagger_doc_generated.go
+++ b/pkg/api/v1/types_swagger_doc_generated.go
@@ -880,7 +880,7 @@ var map_NodeStatus = map[string]string{
"daemonEndpoints": "Endpoints of daemons running on the Node.",
"nodeInfo": "Set of ids/uuids to uniquely identify the node. More info: http://releases.k8s.io/HEAD/docs/admin/node.md#node-info",
"images": "List of container images on this node",
- "volumesInUse": "List of volumes in use (mounted) by the node.",
+ "volumesInUse": "List of attachable volume devices in use (mounted) by the node.",
}
func (NodeStatus) SwaggerDoc() map[string]string {
diff --git a/pkg/controller/persistentvolume/controller.go b/pkg/controller/persistentvolume/controller.go
index bef158fb281..d17f35cb235 100644
--- a/pkg/controller/persistentvolume/controller.go
+++ b/pkg/controller/persistentvolume/controller.go
@@ -1154,7 +1154,7 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(claimObj interfa
// Add annBoundByController (used in deleting the volume)
setAnnotation(&volume.ObjectMeta, annBoundByController, "yes")
- setAnnotation(&volume.ObjectMeta, annDynamicallyProvisioned, plugin.Name())
+ setAnnotation(&volume.ObjectMeta, annDynamicallyProvisioned, plugin.GetPluginName())
// Try to create the PV object several times
for i := 0; i < ctrl.createProvisionedPVRetryCount; i++ {
diff --git a/pkg/controller/volume/attach_detach_controller.go b/pkg/controller/volume/attach_detach_controller.go
index ab4fd0a1eb4..44cb25885c7 100644
--- a/pkg/controller/volume/attach_detach_controller.go
+++ b/pkg/controller/volume/attach_detach_controller.go
@@ -35,7 +35,7 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/runtime"
"k8s.io/kubernetes/pkg/volume"
- "k8s.io/kubernetes/pkg/volume/util/attachdetach"
+ "k8s.io/kubernetes/pkg/volume/util/volumehelper"
)
const (
@@ -205,7 +205,7 @@ func (adc *attachDetachController) nodeAdd(obj interface{}) {
}
nodeName := node.Name
- if _, exists := node.Annotations[attachdetach.ControllerManagedAnnotation]; exists {
+ if _, exists := node.Annotations[volumehelper.ControllerManagedAnnotation]; exists {
// Node specifies annotation indicating it should be managed by attach
// detach controller. Add it to desired state of world.
adc.desiredStateOfWorld.AddNode(nodeName)
@@ -284,10 +284,11 @@ func (adc *attachDetachController) processPodVolumes(
continue
}
+ uniquePodName := getUniquePodName(pod)
if addVolumes {
// Add volume to desired state of world
_, err := adc.desiredStateOfWorld.AddPod(
- getUniquePodName(pod), volumeSpec, pod.Spec.NodeName)
+ uniquePodName, volumeSpec, pod.Spec.NodeName)
if err != nil {
glog.V(10).Infof(
"Failed to add volume %q for pod %q/%q to desiredStateOfWorld. %v",
@@ -299,11 +300,11 @@ func (adc *attachDetachController) processPodVolumes(
} else {
// Remove volume from desired state of world
- uniqueVolumeName, err := attachdetach.GetUniqueDeviceNameFromSpec(
+ uniqueVolumeName, err := volumehelper.GetUniqueVolumeNameFromSpec(
attachableVolumePlugin, volumeSpec)
if err != nil {
glog.V(10).Infof(
- "Failed to delete volume %q for pod %q/%q from desiredStateOfWorld. GenerateUniqueDeviceName failed with %v",
+ "Failed to delete volume %q for pod %q/%q from desiredStateOfWorld. GenerateUniqueVolumeName failed with %v",
podVolume.Name,
pod.Namespace,
pod.Name,
@@ -311,7 +312,7 @@ func (adc *attachDetachController) processPodVolumes(
continue
}
adc.desiredStateOfWorld.DeletePod(
- getUniquePodName(pod), uniqueVolumeName, pod.Spec.NodeName)
+ uniquePodName, uniqueVolumeName, pod.Spec.NodeName)
}
}
@@ -482,7 +483,7 @@ func (adc *attachDetachController) getPVSpecFromCache(
// corresponding volume in the actual state of the world to indicate that it is
// mounted.
func (adc *attachDetachController) processVolumesInUse(
- nodeName string, volumesInUse []api.UniqueDeviceName) {
+ nodeName string, volumesInUse []api.UniqueVolumeName) {
for _, attachedVolume := range adc.actualStateOfWorld.GetAttachedVolumesForNode(nodeName) {
mounted := false
for _, volumeInUse := range volumesInUse {
@@ -502,8 +503,8 @@ func (adc *attachDetachController) processVolumesInUse(
}
// getUniquePodName returns a unique name to reference pod by in memory caches
-func getUniquePodName(pod *api.Pod) string {
- return types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}.String()
+func getUniquePodName(pod *api.Pod) types.UniquePodName {
+ return types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}.UniquePodName()
}
// VolumeHost implementation
diff --git a/pkg/controller/volume/attacherdetacher/attacher_detacher.go b/pkg/controller/volume/attacherdetacher/attacher_detacher.go
index b6b19cf0a67..a8bb53c2576 100644
--- a/pkg/controller/volume/attacherdetacher/attacher_detacher.go
+++ b/pkg/controller/volume/attacherdetacher/attacher_detacher.go
@@ -155,7 +155,7 @@ func (ad *attacherDetacher) generateDetachVolumeFunc(
err)
}
- deviceName, err := attachableVolumePlugin.GetDeviceName(volumeToDetach.VolumeSpec)
+ deviceName, err := attachableVolumePlugin.GetVolumeName(volumeToDetach.VolumeSpec)
if err != nil {
return nil, fmt.Errorf(
"failed to GetDeviceName from AttachablePlugin for volumeSpec %q err=%v",
diff --git a/pkg/controller/volume/cache/actual_state_of_world.go b/pkg/controller/volume/cache/actual_state_of_world.go
index 1eff7ae5b71..3639024de55 100644
--- a/pkg/controller/volume/cache/actual_state_of_world.go
+++ b/pkg/controller/volume/cache/actual_state_of_world.go
@@ -28,7 +28,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/volume"
- "k8s.io/kubernetes/pkg/volume/util/attachdetach"
+ "k8s.io/kubernetes/pkg/volume/util/volumehelper"
)
// ActualStateOfWorld defines a set of thread-safe operations supported on
@@ -47,7 +47,7 @@ type ActualStateOfWorld interface {
// added.
// If no node with the name nodeName exists in list of attached nodes for
// the specified volume, the node is added.
- AddVolumeNode(volumeSpec *volume.Spec, nodeName string) (api.UniqueDeviceName, error)
+ AddVolumeNode(volumeSpec *volume.Spec, nodeName string) (api.UniqueVolumeName, error)
// SetVolumeMountedByNode sets the MountedByNode value for the given volume
// and node. When set to true this value indicates the volume is mounted by
@@ -56,7 +56,7 @@ type ActualStateOfWorld interface {
// returned.
// If no node with the name nodeName exists in list of attached nodes for
// the specified volume, an error is returned.
- SetVolumeMountedByNode(volumeName api.UniqueDeviceName, nodeName string, mounted bool) error
+ SetVolumeMountedByNode(volumeName api.UniqueVolumeName, nodeName string, mounted bool) error
// MarkDesireToDetach returns the difference between the current time and
// the DetachRequestedTime for the given volume/node combo. If the
@@ -65,7 +65,7 @@ type ActualStateOfWorld interface {
// returned.
// If no node with the name nodeName exists in list of attached nodes for
// the specified volume, an error is returned.
- MarkDesireToDetach(volumeName api.UniqueDeviceName, nodeName string) (time.Duration, error)
+ MarkDesireToDetach(volumeName api.UniqueVolumeName, nodeName string) (time.Duration, error)
// DeleteVolumeNode removes the given volume and node from the underlying
// store indicating the specified volume is no longer attached to the
@@ -73,12 +73,12 @@ type ActualStateOfWorld interface {
// If the volume/node combo does not exist, this is a no-op.
// If after deleting the node, the specified volume contains no other child
// nodes, the volume is also deleted.
- DeleteVolumeNode(volumeName api.UniqueDeviceName, nodeName string)
+ DeleteVolumeNode(volumeName api.UniqueVolumeName, nodeName string)
// VolumeNodeExists returns true if the specified volume/node combo exists
// in the underlying store indicating the specified volume is attached to
// the specified node.
- VolumeNodeExists(volumeName api.UniqueDeviceName, nodeName string) bool
+ VolumeNodeExists(volumeName api.UniqueVolumeName, nodeName string) bool
// GetAttachedVolumes generates and returns a list of volumes/node pairs
// reflecting which volumes are attached to which nodes based on the
@@ -94,7 +94,7 @@ type ActualStateOfWorld interface {
// AttachedVolume represents a volume that is attached to a node.
type AttachedVolume struct {
// VolumeName is the unique identifier for the volume that is attached.
- VolumeName api.UniqueDeviceName
+ VolumeName api.UniqueVolumeName
// VolumeSpec is the volume spec containing the specification for the
// volume that is attached.
@@ -119,7 +119,7 @@ type AttachedVolume struct {
// NewActualStateOfWorld returns a new instance of ActualStateOfWorld.
func NewActualStateOfWorld(volumePluginMgr *volume.VolumePluginMgr) ActualStateOfWorld {
return &actualStateOfWorld{
- attachedVolumes: make(map[api.UniqueDeviceName]attachedVolume),
+ attachedVolumes: make(map[api.UniqueVolumeName]attachedVolume),
volumePluginMgr: volumePluginMgr,
}
}
@@ -129,7 +129,7 @@ type actualStateOfWorld struct {
// controller believes to be successfully attached to the nodes it is
// managing. The key in this map is the name of the volume and the value is
// an object containing more information about the attached volume.
- attachedVolumes map[api.UniqueDeviceName]attachedVolume
+ attachedVolumes map[api.UniqueVolumeName]attachedVolume
// volumePluginMgr is the volume plugin manager used to create volume
// plugin objects.
volumePluginMgr *volume.VolumePluginMgr
@@ -140,7 +140,7 @@ type actualStateOfWorld struct {
// believes to be succesfully attached to a node it is managing.
type attachedVolume struct {
// volumeName contains the unique identifier for this volume.
- volumeName api.UniqueDeviceName
+ volumeName api.UniqueVolumeName
// spec is the volume spec containing the specification for this volume.
// Used to generate the volume plugin object, and passed to attach/detach
@@ -174,7 +174,7 @@ type nodeAttachedTo struct {
}
func (asw *actualStateOfWorld) AddVolumeNode(
- volumeSpec *volume.Spec, nodeName string) (api.UniqueDeviceName, error) {
+ volumeSpec *volume.Spec, nodeName string) (api.UniqueVolumeName, error) {
asw.Lock()
defer asw.Unlock()
@@ -186,11 +186,11 @@ func (asw *actualStateOfWorld) AddVolumeNode(
err)
}
- volumeName, err := attachdetach.GetUniqueDeviceNameFromSpec(
+ volumeName, err := volumehelper.GetUniqueVolumeNameFromSpec(
attachableVolumePlugin, volumeSpec)
if err != nil {
return "", fmt.Errorf(
- "failed to GetUniqueDeviceNameFromSpec for volumeSpec %q err=%v",
+ "failed to GetUniqueVolumeNameFromSpec for volumeSpec %q err=%v",
volumeSpec.Name(),
err)
}
@@ -224,7 +224,7 @@ func (asw *actualStateOfWorld) AddVolumeNode(
}
func (asw *actualStateOfWorld) SetVolumeMountedByNode(
- volumeName api.UniqueDeviceName, nodeName string, mounted bool) error {
+ volumeName api.UniqueVolumeName, nodeName string, mounted bool) error {
asw.Lock()
defer asw.Unlock()
volumeObj, volumeExists := asw.attachedVolumes[volumeName]
@@ -262,7 +262,7 @@ func (asw *actualStateOfWorld) SetVolumeMountedByNode(
}
func (asw *actualStateOfWorld) MarkDesireToDetach(
- volumeName api.UniqueDeviceName, nodeName string) (time.Duration, error) {
+ volumeName api.UniqueVolumeName, nodeName string) (time.Duration, error) {
asw.Lock()
defer asw.Unlock()
@@ -291,7 +291,7 @@ func (asw *actualStateOfWorld) MarkDesireToDetach(
}
func (asw *actualStateOfWorld) DeleteVolumeNode(
- volumeName api.UniqueDeviceName, nodeName string) {
+ volumeName api.UniqueVolumeName, nodeName string) {
asw.Lock()
defer asw.Unlock()
@@ -311,7 +311,7 @@ func (asw *actualStateOfWorld) DeleteVolumeNode(
}
func (asw *actualStateOfWorld) VolumeNodeExists(
- volumeName api.UniqueDeviceName, nodeName string) bool {
+ volumeName api.UniqueVolumeName, nodeName string) bool {
asw.RLock()
defer asw.RUnlock()
diff --git a/pkg/controller/volume/cache/actual_state_of_world_test.go b/pkg/controller/volume/cache/actual_state_of_world_test.go
index 95f7a135060..dbe698722ef 100644
--- a/pkg/controller/volume/cache/actual_state_of_world_test.go
+++ b/pkg/controller/volume/cache/actual_state_of_world_test.go
@@ -29,7 +29,7 @@ func Test_AddVolumeNode_Positive_NewVolumeNewNode(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
@@ -61,7 +61,7 @@ func Test_AddVolumeNode_Positive_ExistingVolumeNewNode(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
node1Name := "node1-name"
node2Name := "node2-name"
@@ -110,7 +110,7 @@ func Test_AddVolumeNode_Positive_ExistingVolumeExistingNode(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
@@ -153,7 +153,7 @@ func Test_DeleteVolumeNode_Positive_VolumeExistsNodeExists(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -182,7 +182,7 @@ func Test_DeleteVolumeNode_Positive_VolumeDoesntExistNodeDoesntExist(t *testing.
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
nodeName := "node-name"
// Act
@@ -208,7 +208,7 @@ func Test_DeleteVolumeNode_Positive_TwoNodesOneDeleted(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
node1Name := "node1-name"
node2Name := "node2-name"
@@ -256,7 +256,7 @@ func Test_VolumeNodeExists_Positive_VolumeExistsNodeExists(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -287,7 +287,7 @@ func Test_VolumeNodeExists_Positive_VolumeExistsNodeDoesntExist(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
node1Name := "node1-name"
node2Name := "node2-name"
@@ -318,7 +318,7 @@ func Test_VolumeNodeExists_Positive_VolumeAndNodeDontExist(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
nodeName := "node-name"
// Act
@@ -358,7 +358,7 @@ func Test_GetAttachedVolumes_Positive_OneVolumeOneNode(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -384,14 +384,14 @@ func Test_GetAttachedVolumes_Positive_TwoVolumeTwoNodes(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volume1Name := api.UniqueDeviceName("volume1-name")
+ volume1Name := api.UniqueVolumeName("volume1-name")
volume1Spec := controllervolumetesting.GetTestVolumeSpec(string(volume1Name), volume1Name)
node1Name := "node1-name"
generatedVolumeName1, add1Err := asw.AddVolumeNode(volume1Spec, node1Name)
if add1Err != nil {
t.Fatalf("AddVolumeNode failed. Expected:
Actual: <%v>", add1Err)
}
- volume2Name := api.UniqueDeviceName("volume2-name")
+ volume2Name := api.UniqueVolumeName("volume2-name")
volume2Spec := controllervolumetesting.GetTestVolumeSpec(string(volume2Name), volume2Name)
node2Name := "node2-name"
generatedVolumeName2, add2Err := asw.AddVolumeNode(volume2Spec, node2Name)
@@ -418,7 +418,7 @@ func Test_GetAttachedVolumes_Positive_OneVolumeTwoNodes(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
node1Name := "node1-name"
generatedVolumeName1, add1Err := asw.AddVolumeNode(volumeSpec, node1Name)
@@ -456,7 +456,7 @@ func Test_SetVolumeMountedByNode_Positive_Set(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -482,7 +482,7 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithInitialSet(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -517,7 +517,7 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithoutInitialSet(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -549,7 +549,7 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithInitialSetAddVolumeNodeNotRes
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -589,7 +589,7 @@ func Test_SetVolumeMountedByNode_Positive_UnsetWithInitialSetVerifyDetachRequest
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -631,7 +631,7 @@ func Test_MarkDesireToDetach_Positive_Set(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -657,7 +657,7 @@ func Test_MarkDesireToDetach_Positive_Marked(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -690,7 +690,7 @@ func Test_MarkDesireToDetach_Positive_MarkedAddVolumeNodeReset(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -727,7 +727,7 @@ func Test_MarkDesireToDetach_Positive_UnsetWithInitialSetVolumeMountedByNodePres
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
asw := NewActualStateOfWorld(volumePluginMgr)
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
generatedVolumeName, addErr := asw.AddVolumeNode(volumeSpec, nodeName)
@@ -763,7 +763,7 @@ func Test_MarkDesireToDetach_Positive_UnsetWithInitialSetVolumeMountedByNodePres
func verifyAttachedVolume(
t *testing.T,
attachedVolumes []AttachedVolume,
- expectedVolumeName api.UniqueDeviceName,
+ expectedVolumeName api.UniqueVolumeName,
expectedVolumeSpecName string,
expectedNodeName string,
expectedMountedByNode,
diff --git a/pkg/controller/volume/cache/desired_state_of_world.go b/pkg/controller/volume/cache/desired_state_of_world.go
index c9ec2a8e93e..437e0288138 100644
--- a/pkg/controller/volume/cache/desired_state_of_world.go
+++ b/pkg/controller/volume/cache/desired_state_of_world.go
@@ -26,8 +26,9 @@ import (
"sync"
"k8s.io/kubernetes/pkg/api"
+ "k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/volume"
- "k8s.io/kubernetes/pkg/volume/util/attachdetach"
+ "k8s.io/kubernetes/pkg/volume/util/volumehelper"
)
// DesiredStateOfWorld defines a set of thread-safe operations supported on
@@ -52,7 +53,7 @@ type DesiredStateOfWorld interface {
// should be attached to the specified node, the volume is implicitly added.
// If no node with the name nodeName exists in list of nodes managed by the
// attach/detach attached controller, an error is returned.
- AddPod(podName string, volumeSpec *volume.Spec, nodeName string) (api.UniqueDeviceName, error)
+ AddPod(podName types.UniquePodName, volumeSpec *volume.Spec, nodeName string) (api.UniqueVolumeName, error)
// DeleteNode removes the given node from the list of nodes managed by the
// attach/detach controller.
@@ -70,7 +71,7 @@ type DesiredStateOfWorld interface {
// volumes under the specified node, this is a no-op.
// If after deleting the pod, the specified volume contains no other child
// pods, the volume is also deleted.
- DeletePod(podName string, volumeName api.UniqueDeviceName, nodeName string)
+ DeletePod(podName types.UniquePodName, volumeName api.UniqueVolumeName, nodeName string)
// NodeExists returns true if the node with the specified name exists in
// the list of nodes managed by the attach/detach controller.
@@ -79,7 +80,7 @@ type DesiredStateOfWorld interface {
// VolumeExists returns true if the volume with the specified name exists
// in the list of volumes that should be attached to the specified node by
// the attach detach controller.
- VolumeExists(volumeName api.UniqueDeviceName, nodeName string) bool
+ VolumeExists(volumeName api.UniqueVolumeName, nodeName string) bool
// GetVolumesToAttach generates and returns a list of volumes to attach
// and the nodes they should be attached to based on the current desired
@@ -91,7 +92,7 @@ type DesiredStateOfWorld interface {
type VolumeToAttach struct {
// VolumeName is the unique identifier for the volume that should be
// attached.
- VolumeName api.UniqueDeviceName
+ VolumeName api.UniqueVolumeName
// VolumeSpec is a volume spec containing the specification for the volume
// that should be attached.
@@ -130,13 +131,13 @@ type nodeManaged struct {
// volumesToAttach is a map containing the set of volumes that should be
// attached to this node. The key in the map is the name of the volume and
// the value is a pod object containing more information about the volume.
- volumesToAttach map[api.UniqueDeviceName]volumeToAttach
+ volumesToAttach map[api.UniqueVolumeName]volumeToAttach
}
// The volume object represents a volume that should be attached to a node.
type volumeToAttach struct {
// volumeName contains the unique identifier for this volume.
- volumeName api.UniqueDeviceName
+ volumeName api.UniqueVolumeName
// spec is the volume spec containing the specification for this volume.
// Used to generate the volume plugin object, and passed to attach/detach
@@ -147,14 +148,14 @@ type volumeToAttach struct {
// volume and are scheduled to the underlying node. The key in the map is
// the name of the pod and the value is a pod object containing more
// information about the pod.
- scheduledPods map[string]pod
+ scheduledPods map[types.UniquePodName]pod
}
// The pod object represents a pod that references the underlying volume and is
// scheduled to the underlying node.
type pod struct {
// podName contains the name of this pod.
- podName string
+ podName types.UniquePodName
}
func (dsw *desiredStateOfWorld) AddNode(nodeName string) {
@@ -164,15 +165,15 @@ func (dsw *desiredStateOfWorld) AddNode(nodeName string) {
if _, nodeExists := dsw.nodesManaged[nodeName]; !nodeExists {
dsw.nodesManaged[nodeName] = nodeManaged{
nodeName: nodeName,
- volumesToAttach: make(map[api.UniqueDeviceName]volumeToAttach),
+ volumesToAttach: make(map[api.UniqueVolumeName]volumeToAttach),
}
}
}
func (dsw *desiredStateOfWorld) AddPod(
- podName string,
+ podName types.UniquePodName,
volumeSpec *volume.Spec,
- nodeName string) (api.UniqueDeviceName, error) {
+ nodeName string) (api.UniqueVolumeName, error) {
dsw.Lock()
defer dsw.Unlock()
@@ -191,11 +192,11 @@ func (dsw *desiredStateOfWorld) AddPod(
err)
}
- volumeName, err := attachdetach.GetUniqueDeviceNameFromSpec(
+ volumeName, err := volumehelper.GetUniqueVolumeNameFromSpec(
attachableVolumePlugin, volumeSpec)
if err != nil {
return "", fmt.Errorf(
- "failed to GenerateUniqueDeviceName for volumeSpec %q err=%v",
+ "failed to GenerateUniqueVolumeName for volumeSpec %q err=%v",
volumeSpec.Name(),
err)
}
@@ -205,7 +206,7 @@ func (dsw *desiredStateOfWorld) AddPod(
volumeObj = volumeToAttach{
volumeName: volumeName,
spec: volumeSpec,
- scheduledPods: make(map[string]pod),
+ scheduledPods: make(map[types.UniquePodName]pod),
}
dsw.nodesManaged[nodeName].volumesToAttach[volumeName] = volumeObj
}
@@ -243,8 +244,8 @@ func (dsw *desiredStateOfWorld) DeleteNode(nodeName string) error {
}
func (dsw *desiredStateOfWorld) DeletePod(
- podName string,
- volumeName api.UniqueDeviceName,
+ podName types.UniquePodName,
+ volumeName api.UniqueVolumeName,
nodeName string) {
dsw.Lock()
defer dsw.Unlock()
@@ -282,7 +283,7 @@ func (dsw *desiredStateOfWorld) NodeExists(nodeName string) bool {
}
func (dsw *desiredStateOfWorld) VolumeExists(
- volumeName api.UniqueDeviceName, nodeName string) bool {
+ volumeName api.UniqueVolumeName, nodeName string) bool {
dsw.RLock()
defer dsw.RUnlock()
diff --git a/pkg/controller/volume/cache/desired_state_of_world_test.go b/pkg/controller/volume/cache/desired_state_of_world_test.go
index 791aea5f439..645d78246b2 100644
--- a/pkg/controller/volume/cache/desired_state_of_world_test.go
+++ b/pkg/controller/volume/cache/desired_state_of_world_test.go
@@ -21,6 +21,7 @@ import (
"k8s.io/kubernetes/pkg/api"
controllervolumetesting "k8s.io/kubernetes/pkg/controller/volume/testing"
+ "k8s.io/kubernetes/pkg/types"
)
// Calls AddNode() once.
@@ -87,8 +88,8 @@ func Test_AddPod_Positive_NewPodNodeExistsVolumeDoesntExist(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
- podName := "pod-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ podName := types.UniquePodName("pod-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
dsw.AddNode(nodeName)
@@ -134,9 +135,9 @@ func Test_AddPod_Positive_NewPodNodeExistsVolumeExists(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
- pod1Name := "pod1-name"
- pod2Name := "pod2-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ pod1Name := types.UniquePodName("pod1-name")
+ pod2Name := types.UniquePodName("pod2-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
dsw.AddNode(nodeName)
@@ -204,8 +205,8 @@ func Test_AddPod_Positive_PodExistsNodeExistsVolumeExists(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
- podName := "pod-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ podName := types.UniquePodName("pod-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
dsw.AddNode(nodeName)
@@ -270,8 +271,8 @@ func Test_AddPod_Negative_NewPodNodeDoesntExistVolumeDoesntExist(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
- podName := "pod-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ podName := types.UniquePodName("pod-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
volumeExists := dsw.VolumeExists(volumeName, nodeName)
@@ -369,8 +370,8 @@ func Test_DeleteNode_Negative_NodeExistsHasChildVolumes(t *testing.T) {
dsw := NewDesiredStateOfWorld(volumePluginMgr)
nodeName := "node-name"
dsw.AddNode(nodeName)
- podName := "pod-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ podName := types.UniquePodName("pod-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
generatedVolumeName, podAddErr := dsw.AddPod(podName, volumeSpec, nodeName)
if podAddErr != nil {
@@ -408,8 +409,8 @@ func Test_DeletePod_Positive_PodExistsNodeExistsVolumeExists(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
- podName := "pod-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ podName := types.UniquePodName("pod-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
dsw.AddNode(nodeName)
@@ -455,9 +456,9 @@ func Test_DeletePod_Positive_2PodsExistNodeExistsVolumesExist(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
- pod1Name := "pod1-name"
- pod2Name := "pod2-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ pod1Name := types.UniquePodName("pod1-name")
+ pod2Name := types.UniquePodName("pod2-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
dsw.AddNode(nodeName)
@@ -516,9 +517,9 @@ func Test_DeletePod_Positive_PodDoesNotExist(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
- pod1Name := "pod1-name"
- pod2Name := "pod2-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ pod1Name := types.UniquePodName("pod1-name")
+ pod2Name := types.UniquePodName("pod2-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
dsw.AddNode(nodeName)
@@ -565,8 +566,8 @@ func Test_DeletePod_Positive_NodeDoesNotExist(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
- podName := "pod-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ podName := types.UniquePodName("pod-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
node1Name := "node1-name"
dsw.AddNode(node1Name)
@@ -620,8 +621,8 @@ func Test_DeletePod_Positive_VolumeDoesNotExist(t *testing.T) {
// Arrange
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
- podName := "pod-name"
- volume1Name := api.UniqueDeviceName("volume1-name")
+ podName := types.UniquePodName("pod-name")
+ volume1Name := api.UniqueVolumeName("volume1-name")
volume1Spec := controllervolumetesting.GetTestVolumeSpec(string(volume1Name), volume1Name)
nodeName := "node-name"
dsw.AddNode(nodeName)
@@ -640,7 +641,7 @@ func Test_DeletePod_Positive_VolumeDoesNotExist(t *testing.T) {
generatedVolume1Name,
nodeName)
}
- volume2Name := api.UniqueDeviceName("volume2-name")
+ volume2Name := api.UniqueVolumeName("volume2-name")
// Act
dsw.DeletePod(podName, volume2Name, nodeName)
@@ -723,8 +724,8 @@ func Test_VolumeExists_Positive_VolumeExistsNodeExists(t *testing.T) {
dsw := NewDesiredStateOfWorld(volumePluginMgr)
nodeName := "node-name"
dsw.AddNode(nodeName)
- podName := "pod-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ podName := types.UniquePodName("pod-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
generatedVolumeName, _ := dsw.AddPod(podName, volumeSpec, nodeName)
@@ -753,8 +754,8 @@ func Test_VolumeExists_Positive_VolumeDoesntExistNodeExists(t *testing.T) {
dsw := NewDesiredStateOfWorld(volumePluginMgr)
nodeName := "node-name"
dsw.AddNode(nodeName)
- podName := "pod-name"
- volume1Name := api.UniqueDeviceName("volume1-name")
+ podName := types.UniquePodName("pod-name")
+ volume1Name := api.UniqueVolumeName("volume1-name")
volume1Spec := controllervolumetesting.GetTestVolumeSpec(string(volume1Name), volume1Name)
generatedVolume1Name, podAddErr := dsw.AddPod(podName, volume1Spec, nodeName)
if podAddErr != nil {
@@ -763,7 +764,7 @@ func Test_VolumeExists_Positive_VolumeDoesntExistNodeExists(t *testing.T) {
podName,
podAddErr)
}
- volume2Name := api.UniqueDeviceName("volume2-name")
+ volume2Name := api.UniqueVolumeName("volume2-name")
// Act
volumeExists := dsw.VolumeExists(volume2Name, nodeName)
@@ -788,7 +789,7 @@ func Test_VolumeExists_Positive_VolumeDoesntExistNodeDoesntExists(t *testing.T)
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
nodeName := "node-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ volumeName := api.UniqueVolumeName("volume-name")
// Act
volumeExists := dsw.VolumeExists(volumeName, nodeName)
@@ -849,8 +850,8 @@ func Test_GetVolumesToAttach_Positive_TwoNodesOneVolumeEach(t *testing.T) {
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
node1Name := "node1-name"
- pod1Name := "pod1-name"
- volume1Name := api.UniqueDeviceName("volume1-name")
+ pod1Name := types.UniquePodName("pod1-name")
+ volume1Name := api.UniqueVolumeName("volume1-name")
volume1Spec := controllervolumetesting.GetTestVolumeSpec(string(volume1Name), volume1Name)
dsw.AddNode(node1Name)
generatedVolume1Name, podAddErr := dsw.AddPod(pod1Name, volume1Spec, node1Name)
@@ -861,8 +862,8 @@ func Test_GetVolumesToAttach_Positive_TwoNodesOneVolumeEach(t *testing.T) {
podAddErr)
}
node2Name := "node2-name"
- pod2Name := "pod2-name"
- volume2Name := api.UniqueDeviceName("volume2-name")
+ pod2Name := types.UniquePodName("pod2-name")
+ volume2Name := api.UniqueVolumeName("volume2-name")
volume2Spec := controllervolumetesting.GetTestVolumeSpec(string(volume2Name), volume2Name)
dsw.AddNode(node2Name)
generatedVolume2Name, podAddErr := dsw.AddPod(pod2Name, volume2Spec, node2Name)
@@ -894,8 +895,8 @@ func Test_GetVolumesToAttach_Positive_TwoNodesOneVolumeEachExtraPod(t *testing.T
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
node1Name := "node1-name"
- pod1Name := "pod1-name"
- volume1Name := api.UniqueDeviceName("volume1-name")
+ pod1Name := types.UniquePodName("pod1-name")
+ volume1Name := api.UniqueVolumeName("volume1-name")
volume1Spec := controllervolumetesting.GetTestVolumeSpec(string(volume1Name), volume1Name)
dsw.AddNode(node1Name)
generatedVolume1Name, podAddErr := dsw.AddPod(pod1Name, volume1Spec, node1Name)
@@ -906,8 +907,8 @@ func Test_GetVolumesToAttach_Positive_TwoNodesOneVolumeEachExtraPod(t *testing.T
podAddErr)
}
node2Name := "node2-name"
- pod2Name := "pod2-name"
- volume2Name := api.UniqueDeviceName("volume2-name")
+ pod2Name := types.UniquePodName("pod2-name")
+ volume2Name := api.UniqueVolumeName("volume2-name")
volume2Spec := controllervolumetesting.GetTestVolumeSpec(string(volume2Name), volume2Name)
dsw.AddNode(node2Name)
generatedVolume2Name, podAddErr := dsw.AddPod(pod2Name, volume2Spec, node2Name)
@@ -917,7 +918,7 @@ func Test_GetVolumesToAttach_Positive_TwoNodesOneVolumeEachExtraPod(t *testing.T
pod2Name,
podAddErr)
}
- pod3Name := "pod3-name"
+ pod3Name := types.UniquePodName("pod3-name")
dsw.AddPod(pod3Name, volume2Spec, node2Name)
_, podAddErr = dsw.AddPod(pod3Name, volume2Spec, node2Name)
if podAddErr != nil {
@@ -948,8 +949,8 @@ func Test_GetVolumesToAttach_Positive_TwoNodesThreeVolumes(t *testing.T) {
volumePluginMgr, _ := controllervolumetesting.GetTestVolumePluginMgr((t))
dsw := NewDesiredStateOfWorld(volumePluginMgr)
node1Name := "node1-name"
- pod1Name := "pod1-name"
- volume1Name := api.UniqueDeviceName("volume1-name")
+ pod1Name := types.UniquePodName("pod1-name")
+ volume1Name := api.UniqueVolumeName("volume1-name")
volume1Spec := controllervolumetesting.GetTestVolumeSpec(string(volume1Name), volume1Name)
dsw.AddNode(node1Name)
generatedVolume1Name, podAddErr := dsw.AddPod(pod1Name, volume1Spec, node1Name)
@@ -960,8 +961,8 @@ func Test_GetVolumesToAttach_Positive_TwoNodesThreeVolumes(t *testing.T) {
podAddErr)
}
node2Name := "node2-name"
- pod2aName := "pod2a-name"
- volume2Name := api.UniqueDeviceName("volume2-name")
+ pod2aName := types.UniquePodName("pod2a-name")
+ volume2Name := api.UniqueVolumeName("volume2-name")
volume2Spec := controllervolumetesting.GetTestVolumeSpec(string(volume2Name), volume2Name)
dsw.AddNode(node2Name)
generatedVolume2Name1, podAddErr := dsw.AddPod(pod2aName, volume2Spec, node2Name)
@@ -971,7 +972,7 @@ func Test_GetVolumesToAttach_Positive_TwoNodesThreeVolumes(t *testing.T) {
pod2aName,
podAddErr)
}
- pod2bName := "pod2b-name"
+ pod2bName := types.UniquePodName("pod2b-name")
generatedVolume2Name2, podAddErr := dsw.AddPod(pod2bName, volume2Spec, node2Name)
if podAddErr != nil {
t.Fatalf(
@@ -985,8 +986,8 @@ func Test_GetVolumesToAttach_Positive_TwoNodesThreeVolumes(t *testing.T) {
generatedVolume2Name1,
generatedVolume2Name2)
}
- pod3Name := "pod3-name"
- volume3Name := api.UniqueDeviceName("volume3-name")
+ pod3Name := types.UniquePodName("pod3-name")
+ volume3Name := api.UniqueVolumeName("volume3-name")
volume3Spec := controllervolumetesting.GetTestVolumeSpec(string(volume3Name), volume3Name)
generatedVolume3Name, podAddErr := dsw.AddPod(pod3Name, volume3Spec, node1Name)
if podAddErr != nil {
@@ -1013,7 +1014,7 @@ func verifyVolumeToAttach(
t *testing.T,
volumesToAttach []VolumeToAttach,
expectedNodeName string,
- expectedVolumeName api.UniqueDeviceName,
+ expectedVolumeName api.UniqueVolumeName,
expectedVolumeSpecName string) {
for _, volumeToAttach := range volumesToAttach {
if volumeToAttach.NodeName == expectedNodeName &&
diff --git a/pkg/controller/volume/reconciler/reconciler_test.go b/pkg/controller/volume/reconciler/reconciler_test.go
index 942a708ccc0..9d9be7c7704 100644
--- a/pkg/controller/volume/reconciler/reconciler_test.go
+++ b/pkg/controller/volume/reconciler/reconciler_test.go
@@ -24,6 +24,7 @@ import (
"k8s.io/kubernetes/pkg/controller/volume/attacherdetacher"
"k8s.io/kubernetes/pkg/controller/volume/cache"
controllervolumetesting "k8s.io/kubernetes/pkg/controller/volume/testing"
+ "k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util/wait"
volumetesting "k8s.io/kubernetes/pkg/volume/testing"
)
@@ -66,8 +67,8 @@ func Test_Run_Positive_OneDesiredVolumeAttach(t *testing.T) {
ad := attacherdetacher.NewAttacherDetacher(volumePluginMgr)
reconciler := NewReconciler(
reconcilerLoopPeriod, maxWaitForUnmountDuration, dsw, asw, ad)
- podName := "pod-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ podName := types.UniquePodName("pod-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
dsw.AddNode(nodeName)
@@ -107,8 +108,8 @@ func Test_Run_Positive_OneDesiredVolumeAttachThenDetachWithUnmountedVolume(t *te
ad := attacherdetacher.NewAttacherDetacher(volumePluginMgr)
reconciler := NewReconciler(
reconcilerLoopPeriod, maxWaitForUnmountDuration, dsw, asw, ad)
- podName := "pod-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ podName := types.UniquePodName("pod-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
dsw.AddNode(nodeName)
@@ -169,8 +170,8 @@ func Test_Run_Positive_OneDesiredVolumeAttachThenDetachWithMountedVolume(t *test
ad := attacherdetacher.NewAttacherDetacher(volumePluginMgr)
reconciler := NewReconciler(
reconcilerLoopPeriod, maxWaitForUnmountDuration, dsw, asw, ad)
- podName := "pod-name"
- volumeName := api.UniqueDeviceName("volume-name")
+ podName := types.UniquePodName("pod-name")
+ volumeName := api.UniqueVolumeName("volume-name")
volumeSpec := controllervolumetesting.GetTestVolumeSpec(string(volumeName), volumeName)
nodeName := "node-name"
dsw.AddNode(nodeName)
diff --git a/pkg/controller/volume/testing/testvolumespec.go b/pkg/controller/volume/testing/testvolumespec.go
index 3b85f4910a3..a5b5bd8b64a 100644
--- a/pkg/controller/volume/testing/testvolumespec.go
+++ b/pkg/controller/volume/testing/testvolumespec.go
@@ -22,7 +22,7 @@ import (
)
// GetTestVolumeSpec returns a test volume spec
-func GetTestVolumeSpec(volumeName string, diskName api.UniqueDeviceName) *volume.Spec {
+func GetTestVolumeSpec(volumeName string, diskName api.UniqueVolumeName) *volume.Spec {
return &volume.Spec{
Volume: &api.Volume{
Name: volumeName,
diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go
index 8b8e14cd953..3db75353639 100644
--- a/pkg/kubelet/kubelet.go
+++ b/pkg/kubelet/kubelet.go
@@ -92,7 +92,7 @@ import (
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/version"
"k8s.io/kubernetes/pkg/volume"
- attachdetachutil "k8s.io/kubernetes/pkg/volume/util/attachdetach"
+ "k8s.io/kubernetes/pkg/volume/util/volumehelper"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/predicates"
"k8s.io/kubernetes/plugin/pkg/scheduler/schedulercache"
@@ -1043,7 +1043,7 @@ func (kl *Kubelet) initialNodeStatus() (*api.Node, error) {
node.Annotations = make(map[string]string)
}
- node.Annotations[attachdetachutil.ControllerManagedAnnotation] = "true"
+ node.Annotations[volumehelper.ControllerManagedAnnotation] = "true"
}
// @question: should this be place after the call to the cloud provider? which also applies labels
@@ -2145,10 +2145,10 @@ func (kl *Kubelet) cleanupOrphanedVolumes(pods []*api.Pod, runningPods []*kubeco
if kl.enableControllerAttachDetach {
// Attach/Detach controller is enabled and this volume type
// implments a detacher
- uniqueDeviceName := attachdetachutil.GetUniqueDeviceName(
+ uniqueDeviceName := volumehelper.GetUniqueVolumeName(
cleaner.PluginName, pdName)
kl.volumeManager.RemoveVolumeInUse(
- api.UniqueDeviceName(uniqueDeviceName))
+ api.UniqueVolumeName(uniqueDeviceName))
} else {
// Attach/Detach controller is disabled
err = detacher.Detach(pdName, kl.hostname)
diff --git a/pkg/kubelet/volume_manager.go b/pkg/kubelet/volume_manager.go
index 432f1d8ba02..235b81c8b92 100644
--- a/pkg/kubelet/volume_manager.go
+++ b/pkg/kubelet/volume_manager.go
@@ -32,13 +32,13 @@ import (
type volumeManager struct {
lock sync.RWMutex
volumeMaps map[types.UID]kubecontainer.VolumeMap
- volumesInUse []api.UniqueDeviceName
+ volumesInUse []api.UniqueVolumeName
}
func newVolumeManager() *volumeManager {
vm := &volumeManager{
volumeMaps: make(map[types.UID]kubecontainer.VolumeMap),
- volumesInUse: []api.UniqueDeviceName{},
+ volumesInUse: []api.UniqueVolumeName{},
}
return vm
}
@@ -69,7 +69,7 @@ func (vm *volumeManager) DeleteVolumes(podUID types.UID) {
// AddVolumeInUse adds specified volume to volumesInUse list, if it doesn't
// already exist
-func (vm *volumeManager) AddVolumeInUse(uniqueDeviceName api.UniqueDeviceName) {
+func (vm *volumeManager) AddVolumeInUse(uniqueDeviceName api.UniqueVolumeName) {
vm.lock.Lock()
defer vm.lock.Unlock()
for _, volume := range vm.volumesInUse {
@@ -84,7 +84,7 @@ func (vm *volumeManager) AddVolumeInUse(uniqueDeviceName api.UniqueDeviceName) {
// RemoveVolumeInUse removes the specified volume from volumesInUse list, if it
// exists
-func (vm *volumeManager) RemoveVolumeInUse(uniqueDeviceName api.UniqueDeviceName) {
+func (vm *volumeManager) RemoveVolumeInUse(uniqueDeviceName api.UniqueVolumeName) {
vm.lock.Lock()
defer vm.lock.Unlock()
for i := len(vm.volumesInUse) - 1; i >= 0; i-- {
@@ -96,7 +96,7 @@ func (vm *volumeManager) RemoveVolumeInUse(uniqueDeviceName api.UniqueDeviceName
}
// GetVolumesInUse returns the volumesInUse list
-func (vm *volumeManager) GetVolumesInUse() []api.UniqueDeviceName {
+func (vm *volumeManager) GetVolumesInUse() []api.UniqueVolumeName {
vm.lock.RLock()
defer vm.lock.RUnlock()
return vm.volumesInUse
diff --git a/pkg/kubelet/volumes.go b/pkg/kubelet/volumes.go
index 3d0427aa3ae..2c1cd011009 100644
--- a/pkg/kubelet/volumes.go
+++ b/pkg/kubelet/volumes.go
@@ -34,7 +34,7 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/strings"
"k8s.io/kubernetes/pkg/volume"
- "k8s.io/kubernetes/pkg/volume/util/attachdetach"
+ "k8s.io/kubernetes/pkg/volume/util/volumehelper"
)
const (
@@ -185,13 +185,13 @@ func (kl *Kubelet) mountExternalVolumes(pod *api.Pod) (kubecontainer.VolumeMap,
if kl.enableControllerAttachDetach {
// Attach/Detach controller is enabled and this volume type
// implements an attacher
- uniqueDeviceName, err := attachdetach.GetUniqueDeviceNameFromSpec(
+ uniqueDeviceName, err := volumehelper.GetUniqueVolumeNameFromSpec(
attachablePlugin, volSpec)
if err != nil {
return nil, err
}
kl.volumeManager.AddVolumeInUse(
- api.UniqueDeviceName(uniqueDeviceName))
+ api.UniqueVolumeName(uniqueDeviceName))
}
if err = attacher.MountDevice(volSpec, devicePath, deviceMountPath, kl.mounter); err != nil {
@@ -373,9 +373,9 @@ func (kl *Kubelet) newVolumeMounterFromPlugins(spec *volume.Spec, pod *api.Pod,
}
physicalMounter, err := plugin.NewMounter(spec, pod, opts)
if err != nil {
- return nil, fmt.Errorf("failed to instantiate mounter for volume: %s using plugin: %s with a root cause: %v", spec.Name(), plugin.Name(), err)
+ return nil, fmt.Errorf("failed to instantiate mounter for volume: %s using plugin: %s with a root cause: %v", spec.Name(), plugin.GetPluginName(), err)
}
- glog.V(10).Infof("Using volume plugin %q to mount %s", plugin.Name(), spec.Name())
+ glog.V(10).Infof("Using volume plugin %q to mount %s", plugin.GetPluginName(), spec.Name())
return physicalMounter, nil
}
@@ -400,7 +400,7 @@ func (kl *Kubelet) newVolumeAttacherFromPlugins(spec *volume.Spec, pod *api.Pod)
if err != nil {
return nil, nil, fmt.Errorf("failed to instantiate volume attacher for %s: %v", spec.Name(), err)
}
- glog.V(3).Infof("Using volume plugin %q to attach %s/%s", plugin.Name(), spec.Name())
+ glog.V(3).Infof("Using volume plugin %q to attach %s/%s", plugin.GetPluginName(), spec.Name())
return attacher, plugin, nil
}
@@ -419,8 +419,8 @@ func (kl *Kubelet) newVolumeUnmounterFromPlugins(kind string, name string, podUI
if err != nil {
return nil, "", fmt.Errorf("failed to instantiate volume plugin for %s/%s: %v", podUID, kind, err)
}
- glog.V(5).Infof("Using volume plugin %q to unmount %s/%s", plugin.Name(), podUID, kind)
- return unmounter, plugin.Name(), nil
+ glog.V(5).Infof("Using volume plugin %q to unmount %s/%s", plugin.GetPluginName(), podUID, kind)
+ return unmounter, plugin.GetPluginName(), nil
}
// newVolumeDetacherFromPlugins attempts to find a plugin by a name and then
diff --git a/pkg/types/namespacedname.go b/pkg/types/namespacedname.go
index 895d7c5beb8..3114c7365dc 100644
--- a/pkg/types/namespacedname.go
+++ b/pkg/types/namespacedname.go
@@ -16,6 +16,10 @@ limitations under the License.
package types
+// UniquePodName is an identifier that can be used to uniquely identify a pod
+// within the cluster.
+type UniquePodName string
+
// NamespacedName comprises a resource name, with a mandatory namespace,
// rendered as "/". Being a type captures intent and
// helps make sure that UIDs, namespaced names and non-namespaced names
@@ -33,3 +37,8 @@ type NamespacedName struct {
func (n NamespacedName) String() string {
return n.Namespace + "/" + n.Name
}
+
+// UniquePodName returns the UniquePodName object representation
+func (n NamespacedName) UniquePodName() UniquePodName {
+ return UniquePodName(n.String())
+}
diff --git a/pkg/volume/aws_ebs/aws_ebs.go b/pkg/volume/aws_ebs/aws_ebs.go
index c39aa08d062..3d92d20bbf3 100644
--- a/pkg/volume/aws_ebs/aws_ebs.go
+++ b/pkg/volume/aws_ebs/aws_ebs.go
@@ -61,10 +61,19 @@ func (plugin *awsElasticBlockStorePlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *awsElasticBlockStorePlugin) Name() string {
+func (plugin *awsElasticBlockStorePlugin) GetPluginName() string {
return awsElasticBlockStorePluginName
}
+func (plugin *awsElasticBlockStorePlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference an AWS EBS volume type")
+ }
+
+ return volumeSource.VolumeID, nil
+}
+
func (plugin *awsElasticBlockStorePlugin) CanSupport(spec *volume.Spec) bool {
return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.AWSElasticBlockStore != nil) ||
(spec.Volume != nil && spec.Volume.AWSElasticBlockStore != nil)
@@ -167,6 +176,21 @@ func (plugin *awsElasticBlockStorePlugin) newProvisionerInternal(options volume.
}, nil
}
+func getVolumeSource(spec *volume.Spec) (*api.AWSElasticBlockStoreVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.AWSElasticBlockStoreVolumeSource
+
+ if spec.Volume != nil && spec.Volume.AWSElasticBlockStore != nil {
+ volumeSource = spec.Volume.AWSElasticBlockStore
+ readOnly = volumeSource.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.AWSElasticBlockStore
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
+
// Abstract interface to PD operations.
type ebsManager interface {
CreateVolume(provisioner *awsElasticBlockStoreProvisioner) (volumeID string, volumeSizeGB int, labels map[string]string, err error)
diff --git a/pkg/volume/azure_file/azure_file.go b/pkg/volume/azure_file/azure_file.go
index e474b5ebd57..d95bb07b71d 100644
--- a/pkg/volume/azure_file/azure_file.go
+++ b/pkg/volume/azure_file/azure_file.go
@@ -54,10 +54,19 @@ func (plugin *azureFilePlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *azureFilePlugin) Name() string {
+func (plugin *azureFilePlugin) GetPluginName() string {
return azureFilePluginName
}
+func (plugin *azureFilePlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference an AzureFile volume type")
+ }
+
+ return volumeSource.ShareName, nil
+}
+
func (plugin *azureFilePlugin) CanSupport(spec *volume.Spec) bool {
//TODO: check if mount.cifs is there
return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.AzureFile != nil) ||
@@ -237,3 +246,18 @@ func (c *azureFileUnmounter) TearDownAt(dir string) error {
return nil
}
+
+func getVolumeSource(spec *volume.Spec) (*api.AzureFileVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.AzureFileVolumeSource
+
+ if spec.Volume != nil && spec.Volume.AzureFile != nil {
+ volumeSource = spec.Volume.AzureFile
+ readOnly = volumeSource.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.AzureFile
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/cephfs/cephfs.go b/pkg/volume/cephfs/cephfs.go
index 27710d9012d..53e31f4edda 100644
--- a/pkg/volume/cephfs/cephfs.go
+++ b/pkg/volume/cephfs/cephfs.go
@@ -49,10 +49,19 @@ func (plugin *cephfsPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *cephfsPlugin) Name() string {
+func (plugin *cephfsPlugin) GetPluginName() string {
return cephfsPluginName
}
+func (plugin *cephfsPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a CephFS volume type")
+ }
+
+ return fmt.Sprintf("%v", volumeSource.Monitors), nil
+}
+
func (plugin *cephfsPlugin) CanSupport(spec *volume.Spec) bool {
return (spec.Volume != nil && spec.Volume.CephFS != nil) || (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.CephFS != nil)
}
@@ -279,3 +288,18 @@ func (cephfsVolume *cephfs) execMount(mountpoint string) error {
return nil
}
+
+func getVolumeSource(spec *volume.Spec) (*api.CephFSVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.CephFSVolumeSource
+
+ if spec.Volume != nil && spec.Volume.CephFS != nil {
+ volumeSource = spec.Volume.CephFS
+ readOnly = volumeSource.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.CephFS
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/cinder/cinder.go b/pkg/volume/cinder/cinder.go
index 4881af03be0..c6659bbf49f 100644
--- a/pkg/volume/cinder/cinder.go
+++ b/pkg/volume/cinder/cinder.go
@@ -74,10 +74,19 @@ func (plugin *cinderPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *cinderPlugin) Name() string {
+func (plugin *cinderPlugin) GetPluginName() string {
return cinderVolumePluginName
}
+func (plugin *cinderPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a Cinder volume type")
+ }
+
+ return volumeSource.VolumeID, nil
+}
+
func (plugin *cinderPlugin) CanSupport(spec *volume.Spec) bool {
return (spec.Volume != nil && spec.Volume.Cinder != nil) || (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.Cinder != nil)
}
@@ -458,3 +467,18 @@ func (c *cinderVolumeProvisioner) Provision() (*api.PersistentVolume, error) {
}
return pv, nil
}
+
+func getVolumeSource(spec *volume.Spec) (*api.CinderVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.CinderVolumeSource
+
+ if spec.Volume != nil && spec.Volume.Cinder != nil {
+ volumeSource = spec.Volume.Cinder
+ readOnly = volumeSource.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.Cinder
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/configmap/configmap.go b/pkg/volume/configmap/configmap.go
index e609b9d6f57..0f462649f29 100644
--- a/pkg/volume/configmap/configmap.go
+++ b/pkg/volume/configmap/configmap.go
@@ -50,10 +50,19 @@ func (plugin *configMapPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *configMapPlugin) Name() string {
+func (plugin *configMapPlugin) GetPluginName() string {
return configMapPluginName
}
+func (plugin *configMapPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a ConfigMap volume type")
+ }
+
+ return volumeSource.Name, nil
+}
+
func (plugin *configMapPlugin) CanSupport(spec *volume.Spec) bool {
return spec.Volume != nil && spec.Volume.ConfigMap != nil
}
@@ -226,3 +235,15 @@ func (c *configMapVolumeUnmounter) TearDownAt(dir string) error {
}
return wrapped.TearDownAt(dir)
}
+
+func getVolumeSource(spec *volume.Spec) (*api.ConfigMapVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.ConfigMapVolumeSource
+
+ if spec.Volume != nil && spec.Volume.ConfigMap != nil {
+ volumeSource = spec.Volume.ConfigMap
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/downwardapi/downwardapi.go b/pkg/volume/downwardapi/downwardapi.go
index 61ab64d12f0..1c82eaf5a8c 100644
--- a/pkg/volume/downwardapi/downwardapi.go
+++ b/pkg/volume/downwardapi/downwardapi.go
@@ -58,10 +58,20 @@ func (plugin *downwardAPIPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *downwardAPIPlugin) Name() string {
+func (plugin *downwardAPIPlugin) GetPluginName() string {
return downwardAPIPluginName
}
+func (plugin *downwardAPIPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a DownwardAPI volume type")
+ }
+
+ // Return user defined volume name, since this is an ephemeral volume type
+ return spec.Name(), nil
+}
+
func (plugin *downwardAPIPlugin) CanSupport(spec *volume.Spec) bool {
return spec.Volume != nil && spec.Volume.DownwardAPI != nil
}
@@ -229,3 +239,15 @@ func (c *downwardAPIVolumeUnmounter) TearDownAt(dir string) error {
func (b *downwardAPIVolumeMounter) getMetaDir() string {
return path.Join(b.plugin.host.GetPodPluginDir(b.podUID, utilstrings.EscapeQualifiedNameForDisk(downwardAPIPluginName)), b.volName)
}
+
+func getVolumeSource(spec *volume.Spec) (*api.DownwardAPIVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.DownwardAPIVolumeSource
+
+ if spec.Volume != nil && spec.Volume.DownwardAPI != nil {
+ volumeSource = spec.Volume.DownwardAPI
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/empty_dir/empty_dir.go b/pkg/volume/empty_dir/empty_dir.go
index 9fe9fafc906..1cd9a285f95 100644
--- a/pkg/volume/empty_dir/empty_dir.go
+++ b/pkg/volume/empty_dir/empty_dir.go
@@ -64,10 +64,20 @@ func (plugin *emptyDirPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *emptyDirPlugin) Name() string {
+func (plugin *emptyDirPlugin) GetPluginName() string {
return emptyDirPluginName
}
+func (plugin *emptyDirPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference an EmptyDir volume type")
+ }
+
+ // Return user defined volume name, since this is an ephemeral volume type
+ return spec.Name(), nil
+}
+
func (plugin *emptyDirPlugin) CanSupport(spec *volume.Spec) bool {
if spec.Volume != nil && spec.Volume.EmptyDir != nil {
return true
@@ -326,3 +336,15 @@ func (ed *emptyDir) teardownTmpfs(dir string) error {
func (ed *emptyDir) getMetaDir() string {
return path.Join(ed.plugin.host.GetPodPluginDir(ed.pod.UID, strings.EscapeQualifiedNameForDisk(emptyDirPluginName)), ed.volName)
}
+
+func getVolumeSource(spec *volume.Spec) (*api.EmptyDirVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.EmptyDirVolumeSource
+
+ if spec.Volume != nil && spec.Volume.EmptyDir != nil {
+ volumeSource = spec.Volume.EmptyDir
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/fc/fc.go b/pkg/volume/fc/fc.go
index 9410c0b6eef..1768589d02d 100644
--- a/pkg/volume/fc/fc.go
+++ b/pkg/volume/fc/fc.go
@@ -51,10 +51,19 @@ func (plugin *fcPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *fcPlugin) Name() string {
+func (plugin *fcPlugin) GetPluginName() string {
return fcPluginName
}
+func (plugin *fcPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a FibreChannel volume type")
+ }
+
+ return fmt.Sprintf("%v", volumeSource.TargetWWNs), nil
+}
+
func (plugin *fcPlugin) CanSupport(spec *volume.Spec) bool {
if (spec.Volume != nil && spec.Volume.FC == nil) || (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.FC == nil) {
return false
@@ -197,3 +206,18 @@ func (c *fcDiskUnmounter) TearDown() error {
func (c *fcDiskUnmounter) TearDownAt(dir string) error {
return diskTearDown(c.manager, *c, dir, c.mounter)
}
+
+func getVolumeSource(spec *volume.Spec) (*api.FCVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.FCVolumeSource
+
+ if spec.Volume != nil && spec.Volume.FC != nil {
+ volumeSource = spec.Volume.FC
+ readOnly = volumeSource.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.FC
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/flexvolume/flexvolume.go b/pkg/volume/flexvolume/flexvolume.go
index 3db25470142..0097b165d08 100644
--- a/pkg/volume/flexvolume/flexvolume.go
+++ b/pkg/volume/flexvolume/flexvolume.go
@@ -73,10 +73,19 @@ func (plugin *flexVolumePlugin) getExecutable() string {
return path.Join(plugin.execPath, execName)
}
-func (plugin *flexVolumePlugin) Name() string {
+func (plugin *flexVolumePlugin) GetPluginName() string {
return plugin.driverName
}
+func (plugin *flexVolumePlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a Flex volume type")
+ }
+
+ return volumeSource.Driver, nil
+}
+
// CanSupport checks whether the plugin can support the input volume spec.
func (plugin *flexVolumePlugin) CanSupport(spec *volume.Spec) bool {
source := plugin.getVolumeSource(spec)
@@ -386,3 +395,18 @@ func (f *flexVolumeUnmounter) TearDownAt(dir string) error {
return nil
}
+
+func getVolumeSource(spec *volume.Spec) (*api.FlexVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.FlexVolumeSource
+
+ if spec.Volume != nil && spec.Volume.FlexVolume != nil {
+ volumeSource = spec.Volume.FlexVolume
+ readOnly = volumeSource.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.FlexVolume
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/flocker/plugin.go b/pkg/volume/flocker/plugin.go
index 8eb168933fe..51dd1c410fd 100644
--- a/pkg/volume/flocker/plugin.go
+++ b/pkg/volume/flocker/plugin.go
@@ -66,11 +66,20 @@ func (p *flockerPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (p flockerPlugin) Name() string {
+func (p *flockerPlugin) GetPluginName() string {
return flockerPluginName
}
-func (p flockerPlugin) CanSupport(spec *volume.Spec) bool {
+func (p *flockerPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a Flocker volume type")
+ }
+
+ return volumeSource.DatasetName, nil
+}
+
+func (p *flockerPlugin) CanSupport(spec *volume.Spec) bool {
return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.Flocker != nil) ||
(spec.Volume != nil && spec.Volume.Flocker != nil)
}
@@ -241,3 +250,18 @@ func (b flockerMounter) updateDatasetPrimary(datasetID, primaryUUID string) erro
}
}
+
+func getVolumeSource(spec *volume.Spec) (*api.FlockerVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.FlockerVolumeSource
+
+ if spec.Volume != nil && spec.Volume.Flocker != nil {
+ volumeSource = spec.Volume.Flocker
+ readOnly = spec.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.Flocker
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/gce_pd/attacher.go b/pkg/volume/gce_pd/attacher.go
index 76d57eaa6a4..f41a573e166 100644
--- a/pkg/volume/gce_pd/attacher.go
+++ b/pkg/volume/gce_pd/attacher.go
@@ -53,15 +53,6 @@ func (plugin *gcePersistentDiskPlugin) NewAttacher() (volume.Attacher, error) {
}, nil
}
-func (plugin *gcePersistentDiskPlugin) GetDeviceName(spec *volume.Spec) (string, error) {
- volumeSource, _ := getVolumeSource(spec)
- if volumeSource == nil {
- return "", fmt.Errorf("Spec does not reference a GCE volume type")
- }
-
- return volumeSource.PDName, nil
-}
-
// Attach checks with the GCE cloud provider if the specified volume is already
// attached to the specified node. If the volume is attached, it succeeds
// (returns nil). If it is not, Attach issues a call to the GCE cloud provider
diff --git a/pkg/volume/gce_pd/gce_pd.go b/pkg/volume/gce_pd/gce_pd.go
index cbc89aeed69..0ad023bd7b9 100644
--- a/pkg/volume/gce_pd/gce_pd.go
+++ b/pkg/volume/gce_pd/gce_pd.go
@@ -58,10 +58,19 @@ func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *gcePersistentDiskPlugin) Name() string {
+func (plugin *gcePersistentDiskPlugin) GetPluginName() string {
return gcePersistentDiskPluginName
}
+func (plugin *gcePersistentDiskPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a GCE volume type")
+ }
+
+ return volumeSource.PDName, nil
+}
+
func (plugin *gcePersistentDiskPlugin) CanSupport(spec *volume.Spec) bool {
return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.GCEPersistentDisk != nil) ||
(spec.Volume != nil && spec.Volume.GCEPersistentDisk != nil)
diff --git a/pkg/volume/git_repo/git_repo.go b/pkg/volume/git_repo/git_repo.go
index 33a6bbf2bd0..9dd2a6d7c94 100644
--- a/pkg/volume/git_repo/git_repo.go
+++ b/pkg/volume/git_repo/git_repo.go
@@ -54,10 +54,23 @@ func (plugin *gitRepoPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *gitRepoPlugin) Name() string {
+func (plugin *gitRepoPlugin) GetPluginName() string {
return gitRepoPluginName
}
+func (plugin *gitRepoPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a GCE volume type")
+ }
+
+ return fmt.Sprintf(
+ "%v:%v:%v",
+ volumeSource.Repository,
+ volumeSource.Revision,
+ volumeSource.Directory), nil
+}
+
func (plugin *gitRepoPlugin) CanSupport(spec *volume.Spec) bool {
return spec.Volume != nil && spec.Volume.GitRepo != nil
}
@@ -226,3 +239,15 @@ func (c *gitRepoVolumeUnmounter) TearDownAt(dir string) error {
}
return wrapped.TearDownAt(dir)
}
+
+func getVolumeSource(spec *volume.Spec) (*api.GitRepoVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.GitRepoVolumeSource
+
+ if spec.Volume != nil && spec.Volume.GitRepo != nil {
+ volumeSource = spec.Volume.GitRepo
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/glusterfs/glusterfs.go b/pkg/volume/glusterfs/glusterfs.go
index 2a28490d9a6..a30b2834559 100644
--- a/pkg/volume/glusterfs/glusterfs.go
+++ b/pkg/volume/glusterfs/glusterfs.go
@@ -52,10 +52,22 @@ func (plugin *glusterfsPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *glusterfsPlugin) Name() string {
+func (plugin *glusterfsPlugin) GetPluginName() string {
return glusterfsPluginName
}
+func (plugin *glusterfsPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a Gluster volume type")
+ }
+
+ return fmt.Sprintf(
+ "%v:%v",
+ volumeSource.EndpointsName,
+ volumeSource.Path), nil
+}
+
func (plugin *glusterfsPlugin) CanSupport(spec *volume.Spec) bool {
if (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.Glusterfs == nil) ||
(spec.Volume != nil && spec.Volume.Glusterfs == nil) {
@@ -275,3 +287,18 @@ func (b *glusterfsMounter) setUpAtInternal(dir string) error {
}
return fmt.Errorf("glusterfs: mount failed: %v", errs)
}
+
+func getVolumeSource(spec *volume.Spec) (*api.GlusterfsVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.GlusterfsVolumeSource
+
+ if spec.Volume != nil && spec.Volume.Glusterfs != nil {
+ volumeSource = spec.Volume.Glusterfs
+ readOnly = volumeSource.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.Glusterfs
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/host_path/host_path.go b/pkg/volume/host_path/host_path.go
index 8a6cae457dc..f734d656ca9 100644
--- a/pkg/volume/host_path/host_path.go
+++ b/pkg/volume/host_path/host_path.go
@@ -78,10 +78,19 @@ func (plugin *hostPathPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *hostPathPlugin) Name() string {
+func (plugin *hostPathPlugin) GetPluginName() string {
return hostPathPluginName
}
+func (plugin *hostPathPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference an HostPath volume type")
+ }
+
+ return volumeSource.Path, nil
+}
+
func (plugin *hostPathPlugin) CanSupport(spec *volume.Spec) bool {
return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.HostPath != nil) ||
(spec.Volume != nil && spec.Volume.HostPath != nil)
@@ -303,3 +312,18 @@ func (r *hostPathDeleter) Delete() error {
}
return os.RemoveAll(r.GetPath())
}
+
+func getVolumeSource(spec *volume.Spec) (*api.HostPathVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.HostPathVolumeSource
+
+ if spec.Volume != nil && spec.Volume.HostPath != nil {
+ volumeSource = spec.Volume.HostPath
+ readOnly = spec.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.HostPath
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/iscsi/iscsi.go b/pkg/volume/iscsi/iscsi.go
index d36a43abcba..df88bc05831 100644
--- a/pkg/volume/iscsi/iscsi.go
+++ b/pkg/volume/iscsi/iscsi.go
@@ -17,6 +17,7 @@ limitations under the License.
package iscsi
import (
+ "fmt"
"strconv"
"strings"
@@ -52,10 +53,23 @@ func (plugin *iscsiPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *iscsiPlugin) Name() string {
+func (plugin *iscsiPlugin) GetPluginName() string {
return iscsiPluginName
}
+func (plugin *iscsiPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a ISCSI volume type")
+ }
+
+ return fmt.Sprintf(
+ "%v:%v:%v",
+ volumeSource.TargetPortal,
+ volumeSource.IQN,
+ volumeSource.Lun), nil
+}
+
func (plugin *iscsiPlugin) CanSupport(spec *volume.Spec) bool {
if (spec.Volume != nil && spec.Volume.ISCSI == nil) || (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.ISCSI == nil) {
return false
@@ -206,3 +220,18 @@ func portalMounter(portal string) string {
}
return portal
}
+
+func getVolumeSource(spec *volume.Spec) (*api.ISCSIVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.ISCSIVolumeSource
+
+ if spec.Volume != nil && spec.Volume.ISCSI != nil {
+ volumeSource = spec.Volume.ISCSI
+ readOnly = volumeSource.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.ISCSI
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/nfs/nfs.go b/pkg/volume/nfs/nfs.go
index 6b787c6bc39..91ca5ead7e3 100644
--- a/pkg/volume/nfs/nfs.go
+++ b/pkg/volume/nfs/nfs.go
@@ -63,10 +63,22 @@ func (plugin *nfsPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *nfsPlugin) Name() string {
+func (plugin *nfsPlugin) GetPluginName() string {
return nfsPluginName
}
+func (plugin *nfsPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a NFS volume type")
+ }
+
+ return fmt.Sprintf(
+ "%v/%v",
+ volumeSource.Server,
+ volumeSource.Path), nil
+}
+
func (plugin *nfsPlugin) CanSupport(spec *volume.Spec) bool {
return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.NFS != nil) ||
(spec.Volume != nil && spec.Volume.NFS != nil)
@@ -296,3 +308,18 @@ func (r *nfsRecycler) Recycle() error {
}
return volume.RecycleVolumeByWatchingPodUntilCompletion(r.pvName, pod, r.host.GetKubeClient())
}
+
+func getVolumeSource(spec *volume.Spec) (*api.NFSVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.NFSVolumeSource
+
+ if spec.Volume != nil && spec.Volume.NFS != nil {
+ volumeSource = spec.Volume.NFS
+ readOnly = volumeSource.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.NFS
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/plugins.go b/pkg/volume/plugins.go
index 44f7f227017..0aea8f2f3b6 100644
--- a/pkg/volume/plugins.go
+++ b/pkg/volume/plugins.go
@@ -71,7 +71,15 @@ type VolumePlugin interface {
// Name returns the plugin's name. Plugins should use namespaced names
// such as "example.com/volume". The "kubernetes.io" namespace is
// reserved for plugins which are bundled with kubernetes.
- Name() string
+ GetPluginName() string
+
+ // GetVolumeName returns the name/ID to uniquely identifying the actual
+ // backing device, directory, path, etc. referenced by the specified volume
+ // spec.
+ // For Attachable volumes, this value must be able to be passed back to
+ // volume Detach methods to identify the device to act on.
+ // If the plugin does not support the given spec, this returns an error.
+ GetVolumeName(spec *Spec) (string, error)
// CanSupport tests whether the plugin supports a given volume
// specification from the API. The spec pointer should be considered
@@ -141,11 +149,6 @@ type AttachableVolumePlugin interface {
VolumePlugin
NewAttacher() (Attacher, error)
NewDetacher() (Detacher, error)
-
- // GetDeviceName returns the name or ID of the device referenced in the
- // specified volume spec. This is passed by callers to the Deatch method.
- // If the plugin does not support the given spec, this returns an error.
- GetDeviceName(spec *Spec) (string, error)
}
// VolumeHost is an interface that plugins can use to access the kubelet.
@@ -299,7 +302,7 @@ func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, host VolumeHost)
allErrs := []error{}
for _, plugin := range plugins {
- name := plugin.Name()
+ name := plugin.GetPluginName()
if errs := validation.IsQualifiedName(name); len(errs) != 0 {
allErrs = append(allErrs, fmt.Errorf("volume plugin has invalid name: %q: %s", name, strings.Join(errs, ";")))
continue
@@ -352,7 +355,7 @@ func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) {
// Once we can get rid of legacy names we can reduce this to a map lookup.
matches := []string{}
for k, v := range pm.plugins {
- if v.Name() == name {
+ if v.GetPluginName() == name {
matches = append(matches, k)
}
}
diff --git a/pkg/volume/rbd/rbd.go b/pkg/volume/rbd/rbd.go
index 337a19904bc..e5680f2ae1a 100644
--- a/pkg/volume/rbd/rbd.go
+++ b/pkg/volume/rbd/rbd.go
@@ -50,10 +50,22 @@ func (plugin *rbdPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *rbdPlugin) Name() string {
+func (plugin *rbdPlugin) GetPluginName() string {
return rbdPluginName
}
+func (plugin *rbdPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a RBD volume type")
+ }
+
+ return fmt.Sprintf(
+ "%v:%v",
+ volumeSource.CephMonitors,
+ volumeSource.RBDImage), nil
+}
+
func (plugin *rbdPlugin) CanSupport(spec *volume.Spec) bool {
if (spec.Volume != nil && spec.Volume.RBD == nil) || (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.RBD == nil) {
return false
@@ -221,3 +233,18 @@ func (plugin *rbdPlugin) execCommand(command string, args []string) ([]byte, err
cmd := plugin.exe.Command(command, args...)
return cmd.CombinedOutput()
}
+
+func getVolumeSource(spec *volume.Spec) (*api.RBDVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.RBDVolumeSource
+
+ if spec.Volume != nil && spec.Volume.RBD != nil {
+ volumeSource = spec.Volume.RBD
+ readOnly = volumeSource.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.RBD
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/secret/secret.go b/pkg/volume/secret/secret.go
index 1eccf6c0826..2071ffc7c65 100644
--- a/pkg/volume/secret/secret.go
+++ b/pkg/volume/secret/secret.go
@@ -58,10 +58,19 @@ func (plugin *secretPlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *secretPlugin) Name() string {
+func (plugin *secretPlugin) GetPluginName() string {
return secretPluginName
}
+func (plugin *secretPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a Secret volume type")
+ }
+
+ return volumeSource.SecretName, nil
+}
+
func (plugin *secretPlugin) CanSupport(spec *volume.Spec) bool {
return spec.Volume != nil && spec.Volume.Secret != nil
}
@@ -242,3 +251,15 @@ func (c *secretVolumeUnmounter) TearDownAt(dir string) error {
}
return wrapped.TearDownAt(dir)
}
+
+func getVolumeSource(spec *volume.Spec) (*api.SecretVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.SecretVolumeSource
+
+ if spec.Volume != nil && spec.Volume.Secret != nil {
+ volumeSource = spec.Volume.Secret
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}
diff --git a/pkg/volume/testing/testing.go b/pkg/volume/testing/testing.go
index 1ad7ca24153..df031682298 100644
--- a/pkg/volume/testing/testing.go
+++ b/pkg/volume/testing/testing.go
@@ -166,12 +166,16 @@ func (plugin *FakeVolumePlugin) Init(host VolumeHost) error {
return nil
}
-func (plugin *FakeVolumePlugin) Name() string {
+func (plugin *FakeVolumePlugin) GetPluginName() string {
plugin.RLock()
defer plugin.RUnlock()
return plugin.PluginName
}
+func (plugin *FakeVolumePlugin) GetVolumeName(spec *Spec) (string, error) {
+ return spec.Name(), nil
+}
+
func (plugin *FakeVolumePlugin) CanSupport(spec *Spec) bool {
// TODO: maybe pattern-match on spec.Name() to decide?
return true
@@ -237,10 +241,6 @@ func (plugin *FakeVolumePlugin) GetNewDetacherCallCount() int {
return plugin.NewDetacherCallCount
}
-func (plugin *FakeVolumePlugin) GetDeviceName(spec *Spec) (string, error) {
- return spec.Name(), nil
-}
-
func (plugin *FakeVolumePlugin) NewRecycler(pvName string, spec *Spec) (Recycler, error) {
return &fakeRecycler{"/attributesTransferredFromSpec", MetricsNil{}}, nil
}
diff --git a/pkg/volume/util/volumehelper/volumehelper.go b/pkg/volume/util/volumehelper/volumehelper.go
new file mode 100644
index 00000000000..0366f6ee306
--- /dev/null
+++ b/pkg/volume/util/volumehelper/volumehelper.go
@@ -0,0 +1,72 @@
+/*
+Copyright 2016 The Kubernetes Authors 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 volumehelper contains consts and helper methods used by various
+// volume components (attach/detach controller, kubelet, etc.).
+package volumehelper
+
+import (
+ "fmt"
+
+ "k8s.io/kubernetes/pkg/api"
+ "k8s.io/kubernetes/pkg/volume"
+)
+
+const (
+ // ControllerManagedAnnotation is the key of the annotation on Node objects
+ // that indicates attach/detach operations for the node should be managed
+ // by the attach/detach controller
+ ControllerManagedAnnotation string = "volumes.kubernetes.io/controller-managed-attach-detach"
+)
+
+// GetUniqueVolumeName returns a unique name representing the volume/plugin.
+// Caller should ensure that volumeName is a name/ID uniquely identifying the
+// actual backing device, directory, path, etc. for a particular volume.
+// The returned name can be used to uniquely reference the volume, for example,
+// to prevent operations (attach/detach or mount/unmount) from being triggered
+// on the same volume.
+func GetUniqueVolumeName(
+ pluginName string, volumeName string) api.UniqueVolumeName {
+ return api.UniqueVolumeName(fmt.Sprintf("%s/%s", pluginName, volumeName))
+}
+
+// GetUniqueVolumeNameFromSpec uses the given VolumePlugin to generate a unique
+// name representing the volume defined in the specified volume spec.
+// This returned name can be used to uniquely reference the actual backing
+// device, directory, path, etc. referenced by the given volumeSpec.
+// If the given plugin does not support the volume spec, this returns an error.
+func GetUniqueVolumeNameFromSpec(
+ volumePlugin volume.VolumePlugin,
+ volumeSpec *volume.Spec) (api.UniqueVolumeName, error) {
+ if volumePlugin == nil {
+ return "", fmt.Errorf(
+ "volumePlugin should not be nil. volumeSpec.Name=%q",
+ volumeSpec.Name())
+ }
+
+ volumeName, err := volumePlugin.GetVolumeName(volumeSpec)
+ if err != nil || volumeName == "" {
+ return "", fmt.Errorf(
+ "failed to GetVolumeName from volumePlugin for volumeSpec %q err=%v",
+ volumeSpec.Name(),
+ err)
+ }
+
+ return GetUniqueVolumeName(
+ volumePlugin.GetPluginName(),
+ volumeName),
+ nil
+}
diff --git a/pkg/volume/vsphere_volume/vsphere_volume.go b/pkg/volume/vsphere_volume/vsphere_volume.go
index 9de3fc33f95..f9c75b370c1 100644
--- a/pkg/volume/vsphere_volume/vsphere_volume.go
+++ b/pkg/volume/vsphere_volume/vsphere_volume.go
@@ -57,10 +57,19 @@ func (plugin *vsphereVolumePlugin) Init(host volume.VolumeHost) error {
return nil
}
-func (plugin *vsphereVolumePlugin) Name() string {
+func (plugin *vsphereVolumePlugin) GetPluginName() string {
return vsphereVolumePluginName
}
+func (plugin *vsphereVolumePlugin) GetVolumeName(spec *volume.Spec) (string, error) {
+ volumeSource, _ := getVolumeSource(spec)
+ if volumeSource == nil {
+ return "", fmt.Errorf("Spec does not reference a VSphere volume type")
+ }
+
+ return volumeSource.VolumePath, nil
+}
+
func (plugin *vsphereVolumePlugin) CanSupport(spec *volume.Spec) bool {
return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.VsphereVolume != nil) ||
(spec.Volume != nil && spec.Volume.VsphereVolume != nil)
@@ -417,3 +426,18 @@ func (v *vsphereVolumeProvisioner) Provision() (*api.PersistentVolume, error) {
}
return pv, nil
}
+
+func getVolumeSource(spec *volume.Spec) (*api.VsphereVirtualDiskVolumeSource, bool) {
+ var readOnly bool
+ var volumeSource *api.VsphereVirtualDiskVolumeSource
+
+ if spec.Volume != nil && spec.Volume.VsphereVolume != nil {
+ volumeSource = spec.Volume.VsphereVolume
+ readOnly = spec.ReadOnly
+ } else {
+ volumeSource = spec.PersistentVolume.Spec.VsphereVolume
+ readOnly = spec.ReadOnly
+ }
+
+ return volumeSource, readOnly
+}