Skip to content

Commit

Permalink
Introduced a config indicator for a VMware paravirtualized environmen…
Browse files Browse the repository at this point in the history
…t. (#1273)

Fail VolumeCreateFromSnapshot in such a case.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
carlbraganza and mergify[bot] authored Mar 9, 2022
1 parent 67ecd2a commit 2b05ece
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 9 deletions.
46 changes: 37 additions & 9 deletions pkg/blockstorage/vmware/vmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vmware

import (
"context"
stderrors "errors"
"fmt"
"net/url"
"os"
Expand Down Expand Up @@ -42,6 +43,12 @@ const (
// VSpherePasswordKey represents key for the password.
VSpherePasswordKey = "VSpherePasswordKey"

// VSphereIsParaVirtualizedKey is the key for the para-virtualized indicator.
// A value of "true" or "1" implies use of a para-virtualized CSI driver in the
// cluster. When this is true then some operations will fail.
// Note: it is up to the creator of the provider to determine if a para-virtualized environment exists.
VSphereIsParaVirtualizedKey = "VSphereIsParaVirtualizedKey"

noDescription = ""
defaultWaitTime = 60 * time.Minute
defaultRetryLimit = 30 * time.Minute
Expand All @@ -51,15 +58,18 @@ const (

var (
vmWareTimeout = time.Duration(getEnvAsIntOrDefault(vmWareTimeoutMinEnv, int(defaultWaitTime/time.Minute))) * time.Minute

ErrNotSupportedWithParaVirtualizedVolumes = stderrors.New("operation not supported with para-virtualized volumes")
)

// FcdProvider provides blockstorage.Provider
type FcdProvider struct {
Gom *vslm.GlobalObjectManager
Cns *cns.Client
TagsSvc *vapitags.Manager
tagManager tagManager
categoryID string
Gom *vslm.GlobalObjectManager
Cns *cns.Client
TagsSvc *vapitags.Manager
tagManager tagManager
categoryID string
isParaVirtualized bool
}

// NewProvider creates new VMWare FCD provider with the config.
Expand Down Expand Up @@ -113,13 +123,28 @@ func NewProvider(config map[string]string) (blockstorage.Provider, error) {
}
gom := vslm.NewGlobalObjectManager(vslmCli)
return &FcdProvider{
Cns: cnsCli,
Gom: gom,
TagsSvc: tm,
tagManager: tm,
Cns: cnsCli,
Gom: gom,
TagsSvc: tm,
tagManager: tm,
isParaVirtualized: configIsParaVirtualized(config),
}, nil
}

func configIsParaVirtualized(config map[string]string) bool {
if isParaVirtualizedVal, ok := config[VSphereIsParaVirtualizedKey]; ok {
if strings.ToLower(isParaVirtualizedVal) == "true" || isParaVirtualizedVal == "1" {
return true
}
}
return false
}

// IsParaVirtualized is not part of blockstorage.Provider.
func (p *FcdProvider) IsParaVirtualized() bool {
return p.isParaVirtualized
}

// Type is part of blockstorage.Provider
func (p *FcdProvider) Type() blockstorage.Type {
return blockstorage.TypeFCD
Expand All @@ -137,6 +162,9 @@ func (p *FcdProvider) VolumeCreate(ctx context.Context, volume blockstorage.Volu

// VolumeCreateFromSnapshot is part of blockstorage.Provider
func (p *FcdProvider) VolumeCreateFromSnapshot(ctx context.Context, snapshot blockstorage.Snapshot, tags map[string]string) (*blockstorage.Volume, error) {
if p.IsParaVirtualized() {
return nil, errors.WithStack(ErrNotSupportedWithParaVirtualizedVolumes)
}
volID, snapshotID, err := SplitSnapshotFullID(snapshot.ID)
if err != nil {
return nil, errors.Wrap(err, "Failed to split snapshot full ID")
Expand Down
25 changes: 25 additions & 0 deletions pkg/blockstorage/vmware/vmware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@ func (s *VMWareSuite) TestURLParse(c *C) {
}
}

func (s *VMWareSuite) TestIsParaVirtualized(c *C) {
// the constructor needs VIM so just check the parsing of the config map.

config := map[string]string{}
c.Assert(false, Equals, configIsParaVirtualized(config))
config[VSphereIsParaVirtualizedKey] = "false"
c.Assert(false, Equals, configIsParaVirtualized(config))
config[VSphereIsParaVirtualizedKey] = "true"
c.Assert(true, Equals, configIsParaVirtualized(config))
config[VSphereIsParaVirtualizedKey] = "TRUE"
c.Assert(true, Equals, configIsParaVirtualized(config))
config[VSphereIsParaVirtualizedKey] = "1"
c.Assert(true, Equals, configIsParaVirtualized(config))

fcd := &FcdProvider{}
c.Assert(false, Equals, fcd.IsParaVirtualized())
fcd.isParaVirtualized = true
c.Assert(true, Equals, fcd.IsParaVirtualized())

// failed operations
v, err := fcd.VolumeCreateFromSnapshot(context.Background(), blockstorage.Snapshot{}, nil)
c.Assert(true, Equals, errors.Is(err, ErrNotSupportedWithParaVirtualizedVolumes))
c.Assert(v, IsNil)
}

func (s *VMWareSuite) TestTimeoutEnvSetting(c *C) {
tempEnv := os.Getenv(vmWareTimeoutMinEnv)
os.Unsetenv(vmWareTimeoutMinEnv)
Expand Down

0 comments on commit 2b05ece

Please sign in to comment.