-
Notifications
You must be signed in to change notification settings - Fork 31
vSphere Refactoring code - datastore object #158
Conversation
} | ||
|
||
// IsVSANDatastore checks the Datastore object is of the type VSAN | ||
func (ds Datastore) IsVSANDatastore(ctx context.Context) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, instead of having IsVSANDatastore lets change it to GetType and consumers can use it like
if (Datastore.GetTyoe() == VSANDatastore) {
.
.
.
}
In future I am sure Datastore. GetType() will be required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed it to
// GetType returns the type of datastore
func (ds *Datastore) GetType(ctx context.Context) (string, error) {
} | ||
|
||
// Disk defines interfaces for creating disk | ||
type Disk interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, Disk APIs needs to be in Disk file and not in datastore.
Datastore should be a parameter to create.
For delete VolumeID / Path is sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created new Object VirtualDisk and moved methods there
type VirtualDisk struct {
DiskPath string
VolumeOptions VolumeOptions
VMOptions VMOptions
}
func (disk *VirtualDisk) CreateVirtualDisk(ctx context.Context, datastore *Datastore) (err error) {
func (disk *VirtualDisk) DeleteVolume(ctx context.Context, datastore *Datastore) error {
@rohitjogvmw Addressed review comments. |
} | ||
|
||
// GetDiskManager returns vmDiskManager or vdmDiskManager based on given volumeoptions | ||
func GetDiskManager(disk *VirtualDisk) Disk { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you pass operation along with virtualDisk then for delete also you can make use of the factory.
IMHO below parameters in factory with dummy implementation will be extensible..
func GetDiskManager(disk *VirtualDisk, op VirtualDiskOperation) Disk {
if op == "create" {
// your current code
} else if op == "delete" {
// currently just return VDM but very soon VStorageObjectManager needs to be returned based on disk.diskId
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated as below
// GetDiskManager returns vmDiskManager or vdmDiskManager based on given volumeoptions
func GetDiskManager(disk *VirtualDisk, diskOperation string) Disk {
var diskManager Disk
switch diskOperation {
case VirtualDeleteOperation:
diskManager = vdmDiskManager{disk.DiskPath, disk.VolumeOptions}
case VirtualDiskCreateOperation:
if disk.VolumeOptions.StoragePolicyName != "" || disk.VolumeOptions.VSANStorageProfileData != "" || disk.VolumeOptions.StoragePolicyID != "" {
diskManager = vmDiskManager{disk.DiskPath, disk.VolumeOptions, disk.VMOptions}
} else {
diskManager = vdmDiskManager{disk.DiskPath, disk.VolumeOptions}
}
}
return diskManager
}
// DeleteVolume deletes a disk at given disk path. | ||
func (disk *VirtualDisk) DeleteVolume(ctx context.Context, datastore *Datastore) error { | ||
// Create a virtual disk manager | ||
virtualDiskManager := object.NewVirtualDiskManager(datastore.Client()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will suggest the diskManager from the factory and implement delete only in vdm.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to vdm.go
"github.com/vmware/govmomi/vim25/types" | ||
) | ||
|
||
type vdmDiskManager struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vdm itself stands for VirtualDiskManager.
Can I suggest 2 things:
- Put all disk managers in vclib/diskManagers
- Define one interface for diskManager havig APIs like create, delete etc. and vdm and vmDiskManager will implement them or throw exception if operation is not supported. e.g delete is not supported in vmDiskManager
- rename vdmDiskManager.go to vdm.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created diskmanagers package under vclib and moved files there.
divyenp-m01:diskmanagers divyenp$ ls
vdm.go virtualdisk.go vmdm.go
ExtensionKey: "com.vmware.vim.sps", | ||
ObjectData: vmdisk.volumeOptions.VSANStorageProfileData, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please return err in else.
if storagePolicyId != "" {
} else if VSANStorageProfileData != "" {
} else {
return err;
}
VM based disk creation need to be used if no policy / vsan policy data is not provided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
@rohitjogvmw addressed 2nd round of review comments. |
) | ||
|
||
// Disk defines interfaces for creating disk | ||
type Disk interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be VirtualDiskProvider and not Disk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed Disk to VirtualDiskProvider
"k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere/vclib" | ||
) | ||
|
||
type vdmDiskManager struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think VirtualDiskManager is better than vdmDiskManager.
vdm itself stands for VirtualDiskManager. so vdmDiskManager will be read as "VirtualDiskManagerDiskManager" isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. let me change it to virtualDiskManager.
will be read as diskManager virtualDiskManager
|
||
// GetType returns the type of datastore | ||
func (ds *Datastore) GetType(ctx context.Context) (string, error) { | ||
var mds mo.Datastore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is mds?
Is there any particular convention being followed for MOs?
IMHO mds is not good for reading instead "dsMo" tells exactly what it holds.
But are we using Mo suffix for all MOs in code? I don't think so. We need to stick to some convention.
At other places I see name of that object with no "Mo" suffix (e.g. VirtualDiskManager).
If so please change input parameter of this function from "ds" to "dsRef" and use ds instead of mds.
Other alternatives are welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is mds?
Is there any particular convention being followed for MOs?
Govmomi follows this to create instance of Datastore struct declared under package mo.
Used this to differentiate variable from object.Datastore and mo.Datastore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated:
General feedback is, I am not sure if we should use this VirtualDiskProvider interface for vdm and vmdm... Maybe my following understanding is wrong but still want to raise the concern.
The whole point of using interface is generalization. We create this interface X and there are two instances A and B. At some point, we initialize A or B and return it back as an instance of interface X. Later the upper layer just need to call X.something and it will land in the desired functions A.something or B.something automatically.
However in our case, for EVERY disk operation, we need to call GetDiskManager to create an instance of VirtualDiskProvider. And after this, it goes into vdm or vmdm's function, and it's done... The instances are never reused... This seems lost the whole point of using interface. If anyway we need to do this check every time, why not just make a check inside a Create function, and then add two sub functions? Using interface here is just a overkill (or not the right use case...)
"github.com/vmware/govmomi/object" | ||
) | ||
|
||
// VMOptions provides helper objects for provisioning volume with SPBM Policy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we plan to add more functions to it?
If not, why not directly put the following three fields directly into vmDiskManager and VirtualDisk?
|
||
type virtualDiskManager struct { | ||
diskPath string | ||
volumeOptions vclib.VolumeOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalizing? DiskPath, VolumeOptions...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since virtualDiskManager and vmDiskManager are private and just implementing VirtualDiskProvider, so kept it private.
Data can be accessed using
VirtualDisk.DiskPath
VirtualDisk.VolumeOptions
VirtualDisk.VMOptions
"k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere/vclib" | ||
) | ||
|
||
type vmDiskManager struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalizing again. DiskPath, VolumeOptions, VmOptions...
"github.com/vmware/govmomi/vim25/types" | ||
"k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere/vclib" | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is vdm and vmdm. Maybe add one line description about them at the beginning to help ppl understand what's the difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added one line description for each.
// virtualDiskManager implements VirtualDiskProvider Interface for creating and deleting volume using VirtualDiskManager
// vmDiskManager implements VirtualDiskProvider interface for creating volume using Virtual Machine Reconfigure approach
Addressing @luomiao 's review comments. and VirtualDisk will now internally get DiskManager, instead of exposing to the cloud provider.
|
@luomiao Addressed review comments. |
LGTM |
* adding VCLib package - Datastore object * adding vmoptions.go * addressed Rohit's review comments * addressed rohit's review comments * addressed 3rd round of review comments * addressed Miao's review comments
* adding VCLib package - Datastore object * adding vmoptions.go * addressed Rohit's review comments * addressed rohit's review comments * addressed 3rd round of review comments * addressed Miao's review comments
* adding VCLib package - Datastore object * adding vmoptions.go * addressed Rohit's review comments * addressed rohit's review comments * addressed 3rd round of review comments * addressed Miao's review comments
This PR is part of refactoring changes for datastore object.
It includes volume creation and volume deletion methods. Implemented factory pattern and kept the code for each approach in separate files.
@luomiao @rohitjogvmw @tusharnt @BaluDontu