mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #74263 from skarthiksrinivas/vsphere_volume_zone_misc
Fix error handling logic in vsphere volume provisioning
This commit is contained in:
commit
30652ad802
@ -1233,6 +1233,10 @@ func (vs *VSphere) CreateVolume(volumeOptions *vclib.VolumeOptions) (canonicalVo
|
||||
// If zone is specified, first get the datastores in the zone.
|
||||
dsList, err = getDatastoresForZone(ctx, dc, vs.nodeManager, volumeOptions.Zone)
|
||||
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to find a shared datastore matching zone %s. err: %+v", volumeOptions.Zone, err)
|
||||
return "", err
|
||||
}
|
||||
// If unable to get any datastore, fail the operation.
|
||||
if len(dsList) == 0 {
|
||||
err := fmt.Errorf("Failed to find a shared datastore matching zone %s", volumeOptions.Zone)
|
||||
@ -1256,6 +1260,10 @@ func (vs *VSphere) CreateVolume(volumeOptions *vclib.VolumeOptions) (canonicalVo
|
||||
klog.V(4).Infof("Specified zone : %s", volumeOptions.Zone)
|
||||
dsList, err = getDatastoresForZone(ctx, dc, vs.nodeManager, volumeOptions.Zone)
|
||||
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to find a shared datastore matching zone %s. err: %+v", volumeOptions.Zone, err)
|
||||
return "", err
|
||||
}
|
||||
// If unable to get any datastore, fail the operation
|
||||
if len(dsList) == 0 {
|
||||
err := fmt.Errorf("Failed to find a shared datastore matching zone %s", volumeOptions.Zone)
|
||||
@ -1263,9 +1271,6 @@ func (vs *VSphere) CreateVolume(volumeOptions *vclib.VolumeOptions) (canonicalVo
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
datastore, err = getMostFreeDatastoreName(ctx, nil, dsList)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to get shared datastore: %+v", err)
|
||||
@ -1290,6 +1295,7 @@ func (vs *VSphere) CreateVolume(volumeOptions *vclib.VolumeOptions) (canonicalVo
|
||||
klog.V(4).Infof("Validating if datastore %s is in zone %s ", datastore, volumeOptions.Zone)
|
||||
sharedDsList, err = getDatastoresForZone(ctx, dc, vs.nodeManager, volumeOptions.Zone)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to find a shared datastore matching zone %s. err: %+v", volumeOptions.Zone, err)
|
||||
return "", err
|
||||
}
|
||||
// Prepare error msg to be used later, if required.
|
||||
|
@ -264,7 +264,11 @@ func getDatastoresForZone(ctx context.Context, dc *vclib.Datacenter, nodeManager
|
||||
|
||||
for _, host := range hosts {
|
||||
var hostSystemMo mo.HostSystem
|
||||
host.Properties(ctx, host.Reference(), []string{"datastore"}, &hostSystemMo)
|
||||
err = host.Properties(ctx, host.Reference(), []string{"datastore"}, &hostSystemMo)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to get datastore property for host %s. err : %+v", host, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
klog.V(4).Infof("Datastores mounted on host %s : %s", host, hostSystemMo.Datastore)
|
||||
var dsRefList []types.ManagedObjectReference
|
||||
@ -278,7 +282,7 @@ func getDatastoresForZone(ctx context.Context, dc *vclib.Datacenter, nodeManager
|
||||
err = pc.Retrieve(ctx, dsRefList, properties, &dsMoList)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to get Datastore managed objects from datastore objects."+
|
||||
" dsObjList: %+v, properties: %+v, err: %v", dsRefList, properties, err)
|
||||
" dsObjList: %+v, properties: %+v, err: %+v", dsRefList, properties, err)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(9).Infof("Datastore mo details: %+v", dsMoList)
|
||||
|
Loading…
Reference in New Issue
Block a user