mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 13:55:41 +00:00
Fix: dynamic provisioning for vSphere
This commit is contained in:
parent
46176dbe66
commit
551cea9600
@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/vmware/govmomi/object"
|
"github.com/vmware/govmomi/object"
|
||||||
"github.com/vmware/govmomi/property"
|
"github.com/vmware/govmomi/property"
|
||||||
"github.com/vmware/govmomi/vim25/mo"
|
"github.com/vmware/govmomi/vim25/mo"
|
||||||
|
"github.com/vmware/govmomi/vim25/soap"
|
||||||
"github.com/vmware/govmomi/vim25/types"
|
"github.com/vmware/govmomi/vim25/types"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
@ -46,14 +47,16 @@ const (
|
|||||||
ProviderName = "vsphere"
|
ProviderName = "vsphere"
|
||||||
ActivePowerState = "poweredOn"
|
ActivePowerState = "poweredOn"
|
||||||
SCSIControllerType = "scsi"
|
SCSIControllerType = "scsi"
|
||||||
LSILogicControllerType = "lsilogic"
|
LSILogicControllerType = "lsiLogic"
|
||||||
BusLogicControllerType = "buslogic"
|
BusLogicControllerType = "busLogic"
|
||||||
PVSCSIControllerType = "pvscsi"
|
PVSCSIControllerType = "pvscsi"
|
||||||
LSILogicSASControllerType = "lsilogic-sas"
|
LSILogicSASControllerType = "lsiLogic-sas"
|
||||||
SCSIControllerLimit = 4
|
SCSIControllerLimit = 4
|
||||||
SCSIControllerDeviceLimit = 15
|
SCSIControllerDeviceLimit = 15
|
||||||
SCSIDeviceSlots = 16
|
SCSIDeviceSlots = 16
|
||||||
SCSIReservedSlot = 7
|
SCSIReservedSlot = 7
|
||||||
|
ThinDiskType = "thin"
|
||||||
|
VolDir = "kubevols"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Controller types that are currently supported for hot attach of disks
|
// Controller types that are currently supported for hot attach of disks
|
||||||
@ -61,12 +64,13 @@ const (
|
|||||||
// it fails to remove the device from the /dev path (which should be manually done)
|
// it fails to remove the device from the /dev path (which should be manually done)
|
||||||
// making the subsequent attaches to the node to fail.
|
// making the subsequent attaches to the node to fail.
|
||||||
// TODO: Add support for lsilogic driver type
|
// TODO: Add support for lsilogic driver type
|
||||||
var supportedSCSIControllerType = []string{"lsilogic-sas", "pvscsi"}
|
var supportedSCSIControllerType = []string{strings.ToLower(LSILogicSASControllerType), PVSCSIControllerType}
|
||||||
|
|
||||||
var ErrNoDiskUUIDFound = errors.New("No disk UUID found")
|
var ErrNoDiskUUIDFound = errors.New("No disk UUID found")
|
||||||
var ErrNoDiskIDFound = errors.New("No vSphere disk ID found")
|
var ErrNoDiskIDFound = errors.New("No vSphere disk ID found")
|
||||||
var ErrNoDevicesFound = errors.New("No devices found")
|
var ErrNoDevicesFound = errors.New("No devices found")
|
||||||
var ErrNonSupportedControllerType = errors.New("Disk is attached to non-supported controller type")
|
var ErrNonSupportedControllerType = errors.New("Disk is attached to non-supported controller type")
|
||||||
|
var ErrFileAlreadyExist = errors.New("File requested already exist")
|
||||||
|
|
||||||
// VSphere is an implementation of cloud provider Interface for VSphere.
|
// VSphere is an implementation of cloud provider Interface for VSphere.
|
||||||
type VSphere struct {
|
type VSphere struct {
|
||||||
@ -778,7 +782,7 @@ func getSCSIControllers(vmDevices object.VirtualDeviceList) []*types.VirtualCont
|
|||||||
for _, device := range vmDevices {
|
for _, device := range vmDevices {
|
||||||
devType := vmDevices.Type(device)
|
devType := vmDevices.Type(device)
|
||||||
switch devType {
|
switch devType {
|
||||||
case SCSIControllerType, LSILogicControllerType, BusLogicControllerType, PVSCSIControllerType, LSILogicSASControllerType:
|
case SCSIControllerType, strings.ToLower(LSILogicControllerType), strings.ToLower(BusLogicControllerType), PVSCSIControllerType, strings.ToLower(LSILogicSASControllerType):
|
||||||
if c, ok := device.(types.BaseVirtualController); ok {
|
if c, ok := device.(types.BaseVirtualController); ok {
|
||||||
scsiControllers = append(scsiControllers, c.GetVirtualController())
|
scsiControllers = append(scsiControllers, c.GetVirtualController())
|
||||||
}
|
}
|
||||||
@ -1050,8 +1054,29 @@ func (vs *VSphere) CreateVolume(name string, size int, tags *map[string]string)
|
|||||||
dc, err := f.Datacenter(ctx, vs.cfg.Global.Datacenter)
|
dc, err := f.Datacenter(ctx, vs.cfg.Global.Datacenter)
|
||||||
f.SetDatacenter(dc)
|
f.SetDatacenter(dc)
|
||||||
|
|
||||||
|
ds, err := f.Datastore(ctx, vs.cfg.Global.Datastore)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("Failed while searching for datastore %+q. err %s", vs.cfg.Global.Datastore, err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*tags)["adapterType"] == "" {
|
||||||
|
(*tags)["adapterType"] = LSILogicControllerType
|
||||||
|
}
|
||||||
|
if (*tags)["diskType"] == "" {
|
||||||
|
(*tags)["diskType"] = ThinDiskType
|
||||||
|
}
|
||||||
|
|
||||||
|
// vmdks will be created inside kubevols directory
|
||||||
|
kubeVolsPath := filepath.Clean(ds.Path(VolDir)) + "/"
|
||||||
|
err = makeDirectoryInDatastore(c, dc, kubeVolsPath, false)
|
||||||
|
if err != nil && err != ErrFileAlreadyExist {
|
||||||
|
glog.Errorf("Cannot create dir %#v. err %s", kubeVolsPath, err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
vmDiskPath := kubeVolsPath + name + ".vmdk"
|
||||||
// Create a virtual disk manager
|
// Create a virtual disk manager
|
||||||
vmDiskPath := "[" + vs.cfg.Global.Datastore + "] " + name + ".vmdk"
|
|
||||||
virtualDiskManager := object.NewVirtualDiskManager(c.Client)
|
virtualDiskManager := object.NewVirtualDiskManager(c.Client)
|
||||||
|
|
||||||
// Create specification for new virtual disk
|
// Create specification for new virtual disk
|
||||||
@ -1147,3 +1172,26 @@ func (vs *VSphere) NodeExists(c *govmomi.Client, nodeName string) (bool, error)
|
|||||||
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creates a folder using the specified name.
|
||||||
|
// If the intermediate level folders do not exist,
|
||||||
|
// and the parameter createParents is true,
|
||||||
|
// all the non-existent folders are created.
|
||||||
|
func makeDirectoryInDatastore(c *govmomi.Client, dc *object.Datacenter, path string, createParents bool) error {
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
fileManager := object.NewFileManager(c.Client)
|
||||||
|
err := fileManager.MakeDirectory(ctx, path, dc, createParents)
|
||||||
|
if err != nil {
|
||||||
|
if soap.IsSoapFault(err) {
|
||||||
|
soapFault := soap.ToSoapFault(err)
|
||||||
|
if _, ok := soapFault.VimFault().(types.FileAlreadyExists); ok {
|
||||||
|
return ErrFileAlreadyExist
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user