Skip to content

Commit 91f58d3

Browse files
authored
PWX-30093: OCP bring up issue with vSphere (#141)
vSphere client is being used in some paths which were being ignored thinking it's not needed. Reenabling them Signed-off-by: Naveen Revanna <nrevanna@purestorage.com>
1 parent 87b65c0 commit 91f58d3

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

vsphere/vsphere.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package vsphere
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"path"
87
"path/filepath"
@@ -43,7 +42,6 @@ type vsphereOps struct {
4342
}
4443

4544
var (
46-
ErrInvalidParam = errors.New("invalid param")
4745
exponentialBackoff = wait.Backoff{
4846
Duration: 2 * time.Second, // the base duration
4947
Factor: 1.2, // Duration is multiplied by factor each iteration
@@ -52,7 +50,6 @@ var (
5250
}
5351

5452
vmdkMatcherRegex = regexp.MustCompile("\\[(.+)\\](.+)") // e.g [px-datastore-02] osd-provisioned-disks/PX-DO-NOT-DELETE-122be943-485f-4a66-b665-b592f685a3de.vmdk"
55-
5653
)
5754

5855
// VirtualDisk encapsulates the existing virtual disk object to add a managed object
@@ -65,9 +62,6 @@ type VirtualDisk struct {
6562

6663
// NewClient creates a new vsphere cloudops instance
6764
func NewClient(cfg *VSphereConfig, storeParams *store.Params) (cloudops.Ops, error) {
68-
if storeParams == nil {
69-
return nil, ErrInvalidParam
70-
}
7165
vSphereConn := &vclib.VSphereConnection{
7266
Username: cfg.User,
7367
Password: cfg.Password,
@@ -89,16 +83,19 @@ func NewClient(cfg *VSphereConfig, storeParams *store.Params) (cloudops.Ops, err
8983
logrus.Debugf(" Datacenter: %s", vmObj.Datacenter.Name())
9084
logrus.Debugf(" VMUUID: %s", cfg.VMUUID)
9185

92-
storeInstance, err := store.GetStoreWithParams(
93-
storeParams.Kv,
94-
storeParams.SchedulerType,
95-
storeParams.InternalKvdb,
96-
vSphereDataStoreLock,
97-
420*time.Second,
98-
100*time.Second)
99-
if err != nil {
100-
logrus.Errorf(err.Error())
101-
return nil, err
86+
var storeInstance store.Store
87+
if storeParams != nil {
88+
storeInstance, err = store.GetStoreWithParams(
89+
storeParams.Kv,
90+
storeParams.SchedulerType,
91+
storeParams.InternalKvdb,
92+
vSphereDataStoreLock,
93+
420*time.Second,
94+
100*time.Second)
95+
if err != nil {
96+
logrus.Errorf(err.Error())
97+
return nil, err
98+
}
10299
}
103100

104101
return backoff.NewExponentialBackoffOps(
@@ -767,10 +764,16 @@ func (ops *vsphereOps) getDatastoreToUseInStoragePod(
767764
}
768765

769766
spec.DeviceChange = deviceChange
770-
// It's best effort locking. If we didn't get a lock no harm done.
771-
storeLock, lockErr := ops.dsLock.LockWithKey(ops.cfg.VMUUID, storagePod.Name())
767+
var (
768+
storeLock *store.Lock
769+
lockErr error
770+
)
771+
if ops.dsLock != nil {
772+
// It's best effort locking. If we didn't get a lock no harm done.
773+
storeLock, lockErr = ops.dsLock.LockWithKey(ops.cfg.VMUUID, storagePod.Name())
774+
}
772775
recommendedDatastore, err := recommendDatastore(ctx, vmObj, storagePod, spec)
773-
if lockErr == nil {
776+
if lockErr == nil && ops.dsLock != nil {
774777
ops.dsLock.Unlock(storeLock)
775778
}
776779

0 commit comments

Comments
 (0)