mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #8133 from markturansky/iscsi_pv2
added ISCSI volume plugin to PersistentVolumeSource
This commit is contained in:
		@@ -228,6 +228,9 @@ type PersistentVolumeSource struct {
 | 
				
			|||||||
	NFS *NFSVolumeSource `json:"nfs"`
 | 
						NFS *NFSVolumeSource `json:"nfs"`
 | 
				
			||||||
	// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime
 | 
						// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime
 | 
				
			||||||
	RBD *RBDVolumeSource `json:"rbd"`
 | 
						RBD *RBDVolumeSource `json:"rbd"`
 | 
				
			||||||
 | 
						// ISCSIVolumeSource represents an ISCSI resource that is attached to a
 | 
				
			||||||
 | 
						// kubelet's host machine and then exposed to the pod.
 | 
				
			||||||
 | 
						ISCSI *ISCSIVolumeSource `json:"iscsi"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type PersistentVolumeClaimVolumeSource struct {
 | 
					type PersistentVolumeClaimVolumeSource struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1311,6 +1311,14 @@ func convert_api_PersistentVolumeSource_To_v1_PersistentVolumeSource(in *api.Per
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		out.RBD = nil
 | 
							out.RBD = nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if in.ISCSI != nil {
 | 
				
			||||||
 | 
							out.ISCSI = new(ISCSIVolumeSource)
 | 
				
			||||||
 | 
							if err := convert_api_ISCSIVolumeSource_To_v1_ISCSIVolumeSource(in.ISCSI, out.ISCSI, s); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							out.ISCSI = nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -3567,6 +3575,14 @@ func convert_v1_PersistentVolumeSource_To_api_PersistentVolumeSource(in *Persist
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		out.RBD = nil
 | 
							out.RBD = nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if in.ISCSI != nil {
 | 
				
			||||||
 | 
							out.ISCSI = new(api.ISCSIVolumeSource)
 | 
				
			||||||
 | 
							if err := convert_v1_ISCSIVolumeSource_To_api_ISCSIVolumeSource(in.ISCSI, out.ISCSI, s); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							out.ISCSI = nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -253,6 +253,9 @@ type PersistentVolumeSource struct {
 | 
				
			|||||||
	NFS *NFSVolumeSource `json:"nfs,omitempty" description:"NFS volume resource provisioned by an admin"`
 | 
						NFS *NFSVolumeSource `json:"nfs,omitempty" description:"NFS volume resource provisioned by an admin"`
 | 
				
			||||||
	// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime
 | 
						// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime
 | 
				
			||||||
	RBD *RBDVolumeSource `json:"rbd" description:"rados block volume that will be mounted on the host machine"`
 | 
						RBD *RBDVolumeSource `json:"rbd" description:"rados block volume that will be mounted on the host machine"`
 | 
				
			||||||
 | 
						// ISCSI represents an ISCSI Disk resource that is attached to a
 | 
				
			||||||
 | 
						// kubelet's host machine and then exposed to the pod.
 | 
				
			||||||
 | 
						ISCSI *ISCSIVolumeSource `json:"iscsi" description:"an iSCSI disk resource provisioned by an admin"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type PersistentVolume struct {
 | 
					type PersistentVolume struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -156,6 +156,9 @@ type PersistentVolumeSource struct {
 | 
				
			|||||||
	NFS *NFSVolumeSource `json:"nfs" description:"NFS volume resource provisioned by an admin"`
 | 
						NFS *NFSVolumeSource `json:"nfs" description:"NFS volume resource provisioned by an admin"`
 | 
				
			||||||
	// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime
 | 
						// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime
 | 
				
			||||||
	RBD *RBDVolumeSource `json:"rbd" description:"rados block volume that will be mounted on the host machine"`
 | 
						RBD *RBDVolumeSource `json:"rbd" description:"rados block volume that will be mounted on the host machine"`
 | 
				
			||||||
 | 
						// ISCSI represents an ISCSI Disk resource that is attached to a
 | 
				
			||||||
 | 
						// kubelet's host machine and then exposed to the pod.
 | 
				
			||||||
 | 
						ISCSI *ISCSIVolumeSource `json:"iscsi" description:"an iSCSI disk resource provisioned by an admin"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type PersistentVolumeClaimVolumeSource struct {
 | 
					type PersistentVolumeClaimVolumeSource struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -113,6 +113,9 @@ type PersistentVolumeSource struct {
 | 
				
			|||||||
	NFS *NFSVolumeSource `json:"nfs" description:"NFS volume resource provisioned by an admin"`
 | 
						NFS *NFSVolumeSource `json:"nfs" description:"NFS volume resource provisioned by an admin"`
 | 
				
			||||||
	// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime
 | 
						// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime
 | 
				
			||||||
	RBD *RBDVolumeSource `json:"rbd" description:"rados block volume that will be mounted on the host machine"`
 | 
						RBD *RBDVolumeSource `json:"rbd" description:"rados block volume that will be mounted on the host machine"`
 | 
				
			||||||
 | 
						// ISCSI represents an ISCSI Disk resource that is attached to a
 | 
				
			||||||
 | 
						// kubelet's host machine and then exposed to the pod.
 | 
				
			||||||
 | 
						ISCSI *ISCSIVolumeSource `json:"iscsi" description:"an iSCSI disk resource provisioned by an admin"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type PersistentVolumeClaimVolumeSource struct {
 | 
					type PersistentVolumeClaimVolumeSource struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1218,6 +1218,14 @@ func convert_api_PersistentVolumeSource_To_v1beta3_PersistentVolumeSource(in *ap
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		out.RBD = nil
 | 
							out.RBD = nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if in.ISCSI != nil {
 | 
				
			||||||
 | 
							out.ISCSI = new(ISCSIVolumeSource)
 | 
				
			||||||
 | 
							if err := convert_api_ISCSIVolumeSource_To_v1beta3_ISCSIVolumeSource(in.ISCSI, out.ISCSI, s); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							out.ISCSI = nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -3407,6 +3415,14 @@ func convert_v1beta3_PersistentVolumeSource_To_api_PersistentVolumeSource(in *Pe
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		out.RBD = nil
 | 
							out.RBD = nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if in.ISCSI != nil {
 | 
				
			||||||
 | 
							out.ISCSI = new(api.ISCSIVolumeSource)
 | 
				
			||||||
 | 
							if err := convert_v1beta3_ISCSIVolumeSource_To_api_ISCSIVolumeSource(in.ISCSI, out.ISCSI, s); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							out.ISCSI = nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -253,6 +253,9 @@ type PersistentVolumeSource struct {
 | 
				
			|||||||
	NFS *NFSVolumeSource `json:"nfs,omitempty" description:"NFS volume resource provisioned by an admin"`
 | 
						NFS *NFSVolumeSource `json:"nfs,omitempty" description:"NFS volume resource provisioned by an admin"`
 | 
				
			||||||
	// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime
 | 
						// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime
 | 
				
			||||||
	RBD *RBDVolumeSource `json:"rbd" description:"rados block volume that will be mounted on the host machine"`
 | 
						RBD *RBDVolumeSource `json:"rbd" description:"rados block volume that will be mounted on the host machine"`
 | 
				
			||||||
 | 
						// ISCSI represents an ISCSI Disk resource that is attached to a
 | 
				
			||||||
 | 
						// kubelet's host machine and then exposed to the pod.
 | 
				
			||||||
 | 
						ISCSI *ISCSIVolumeSource `json:"iscsi" description:"an iSCSI disk resource provisioned by an admin"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type PersistentVolume struct {
 | 
					type PersistentVolume struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -518,6 +518,10 @@ func ValidatePersistentVolume(pv *api.PersistentVolume) errs.ValidationErrorList
 | 
				
			|||||||
		numVolumes++
 | 
							numVolumes++
 | 
				
			||||||
		allErrs = append(allErrs, validateRBD(pv.Spec.RBD).Prefix("rbd")...)
 | 
							allErrs = append(allErrs, validateRBD(pv.Spec.RBD).Prefix("rbd")...)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if pv.Spec.ISCSI != nil {
 | 
				
			||||||
 | 
							numVolumes++
 | 
				
			||||||
 | 
							allErrs = append(allErrs, validateISCSIVolumeSource(pv.Spec.ISCSI).Prefix("iscsi")...)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if numVolumes != 1 {
 | 
						if numVolumes != 1 {
 | 
				
			||||||
		allErrs = append(allErrs, errs.NewFieldInvalid("", pv.Spec.PersistentVolumeSource, "exactly 1 volume type is required"))
 | 
							allErrs = append(allErrs, errs.NewFieldInvalid("", pv.Spec.PersistentVolumeSource, "exactly 1 volume type is required"))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,9 +53,11 @@ func (plugin *ISCSIPlugin) Name() string {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (plugin *ISCSIPlugin) CanSupport(spec *volume.Spec) bool {
 | 
					func (plugin *ISCSIPlugin) CanSupport(spec *volume.Spec) bool {
 | 
				
			||||||
	if spec.VolumeSource.ISCSI == nil {
 | 
						if spec.VolumeSource.ISCSI == nil && spec.PersistentVolumeSource.ISCSI == nil {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// TODO:  turn this into a func so CanSupport can be unit tested without
 | 
				
			||||||
 | 
						// having to make system calls
 | 
				
			||||||
	// see if iscsiadm is there
 | 
						// see if iscsiadm is there
 | 
				
			||||||
	_, err := plugin.execCommand("iscsiadm", []string{"-h"})
 | 
						_, err := plugin.execCommand("iscsiadm", []string{"-h"})
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,6 +39,28 @@ func TestCanSupport(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestGetAccessModes(t *testing.T) {
 | 
				
			||||||
 | 
						plugMgr := volume.VolumePluginMgr{}
 | 
				
			||||||
 | 
						plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						plug, err := plugMgr.FindPersistentPluginByName("kubernetes.io/iscsi")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Can't find the plugin by name")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !contains(plug.GetAccessModes(), api.ReadWriteOnce) || !contains(plug.GetAccessModes(), api.ReadOnlyMany) {
 | 
				
			||||||
 | 
							t.Errorf("Expected two AccessModeTypes:  %s and %s", api.ReadWriteOnce, api.ReadOnlyMany)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeAccessMode) bool {
 | 
				
			||||||
 | 
						for _, m := range modes {
 | 
				
			||||||
 | 
							if m == mode {
 | 
				
			||||||
 | 
								return true
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type fakeDiskManager struct {
 | 
					type fakeDiskManager struct {
 | 
				
			||||||
	attachCalled bool
 | 
						attachCalled bool
 | 
				
			||||||
	detachCalled bool
 | 
						detachCalled bool
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user