Skip to content

Commit

Permalink
Merge pull request #417 from divyenpatel/cherry-pick-409-to-release-2.0
Browse files Browse the repository at this point in the history
[cherry-pick-to-release-2.0] - fix vsphere backward compatibility issue
  • Loading branch information
divyenpatel authored Oct 12, 2020
2 parents 93bd408 + 03e52df commit b53aefe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pkg/common/cns-lib/volume/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ func (m *defaultManager) QueryVolume(ctx context.Context, queryFilter cnstypes.C
log.Errorf("CNS QueryVolume failed from vCenter %q with err: %v", m.virtualCenter.Config.Host, err)
return nil, err
}
res = updateQueryResult(ctx, m, res)
return res, err
}

Expand All @@ -606,5 +607,6 @@ func (m *defaultManager) QueryAllVolume(ctx context.Context, queryFilter cnstype
log.Errorf("CNS QueryAllVolume failed from vCenter %q with err: %v", m.virtualCenter.Config.Host, err)
return nil, err
}
res = updateQueryResult(ctx, m, res)
return res, err
}
24 changes: 24 additions & 0 deletions pkg/common/cns-lib/volume/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"context"
"errors"

"github.com/vmware/govmomi/cns"
cnstypes "github.com/vmware/govmomi/cns/types"

"sigs.k8s.io/vsphere-csi-driver/pkg/csi/service/logger"

vimtypes "github.com/vmware/govmomi/vim25/types"
Expand Down Expand Up @@ -62,3 +65,24 @@ func IsDiskAttached(ctx context.Context, vm *cnsvsphere.VirtualMachine, volumeID
log.Debugf("Volume %s is not attached to VM: %+v", volumeID, vm)
return "", nil
}

// updateQueryResult helps update CnsQueryResult to populate volume.Metadata.EntityMetadata.ClusterID
// with value from volume.Metadata.ContainerCluster.ClusterId
// This is required to make driver code compatible to vSphere 67 release
func updateQueryResult(ctx context.Context, m *defaultManager, res *cnstypes.CnsQueryResult) *cnstypes.CnsQueryResult {
if m.virtualCenter.Client.Version == cns.ReleaseVSAN67u3 {
log := logger.GetLogger(ctx)
for volumeIndex, volume := range res.Volumes {
for metadataIndex, metadata := range volume.Metadata.EntityMetadata {
if cnsK8sMetaEntityMetadata, ok := metadata.(*cnstypes.CnsKubernetesEntityMetadata); ok {
cnsK8sMetaEntityMetadata.ClusterID = volume.Metadata.ContainerCluster.ClusterId
volume.Metadata.EntityMetadata[metadataIndex] = cnsK8sMetaEntityMetadata
} else {
log.Debugf("metadata: %v is not of type CnsKubernetesEntityMetadata", metadata)
}
}
res.Volumes[volumeIndex] = volume
}
}
return res
}
5 changes: 1 addition & 4 deletions pkg/csi/service/vanilla/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,7 @@ func isVsan67u3Release(ctx context.Context, c *controller) (bool, error) {
return false, err
}
log.Debugf("vCenter version is :%q", vc.Client.Version)
if vc.Client.Version == cns.ReleaseVSAN67u3 {
return true, nil
}
return false, nil
return vc.Client.Version == cns.ReleaseVSAN67u3, nil
}

func (c *controller) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (
Expand Down

0 comments on commit b53aefe

Please sign in to comment.