Skip to content

Commit

Permalink
TRID-10602: Add SMB volume type Storage Class parameter (#971)
Browse files Browse the repository at this point in the history
Implementation to allow trident to accept nasType as Storage Class parameter which can have values as SMB or NFS.
  • Loading branch information
arnavs7 authored Jun 29, 2022
1 parent cba4100 commit 59f1d6e
Show file tree
Hide file tree
Showing 6 changed files with 462 additions and 2 deletions.
6 changes: 6 additions & 0 deletions storage_attribute/common_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
Media = "media"
Region = "region"
Zone = "zone"
NASType = "nasType"

// Constants for label attributes
Labels = "labels"
Expand All @@ -38,6 +39,10 @@ const (
Thick = "thick"
Thin = "thin"

// Values for NAS protocol
NFS = "nfs"
SMB = "smb"

RequiredStorage = "requiredStorage" // deprecated, use additionalStoragePools
StoragePools = "storagePools"
AdditionalStoragePools = "additionalStoragePools"
Expand All @@ -61,4 +66,5 @@ var attrTypes = map[string]Type{
TestingAttribute: boolType,
NonexistentBool: boolType,
Replication: boolType,
NASType: stringType,
}
50 changes: 49 additions & 1 deletion storage_class/storage_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ func (s *StorageClass) GetAdditionalStoragePools() map[string][]string {
return s.config.AdditionalPools
}

func (s *StorageClass) GetStoragePoolsForProtocol(ctx context.Context, p config.Protocol, accessMode config.AccessMode,
func (s *StorageClass) GetStoragePoolsForProtocol(
ctx context.Context, p config.Protocol, accessMode config.AccessMode,
) []storage.Pool {
ret := make([]storage.Pool, 0, len(s.pools))
// TODO: Change this to work with indices of backends?
Expand Down Expand Up @@ -357,6 +358,47 @@ func FilterPoolsOnTopology(
return filteredPools
}

// FilterPoolsOnNasType returns pools filtered over nasType SMB. If not found returns the provided pool list as it is.
func FilterPoolsOnNasType(
ctx context.Context, pools []storage.Pool, scAttributes map[string]storageattribute.Request,
) []storage.Pool {
filteredPools := make([]storage.Pool, 0)
req := scAttributes[storageattribute.NASType]

// Return all pools if NAS type is not specified on the storage class
if req == nil {
Logc(ctx).Debug("nasType request is not present")
return pools
}
nasType, _ := req.Value().(string)
if nasType == "" {
Logc(ctx).Debug("nasType not found, hence no filtering done")
return pools
}

// Return no pools if we got an unsupported NAS type
nasType = strings.ToLower(nasType)
if nasType != storageattribute.SMB && nasType != storageattribute.NFS {
Logc(ctx).Debug("nasType does not have a valid input value, hence no pools found")
return filteredPools
}

// Filter out pools with non-matching NAS types
for _, pool := range pools {
nasTypeOffer := pool.Attributes()[storageattribute.NASType]
if nasTypeOffer == nil {
Logc(ctx).Debug("nasType offer is not present")
continue
}
if strings.ToLower(nasTypeOffer.ToString()) == nasType {
filteredPools = append(filteredPools, pool)
}
}

Logc(ctx).Debugf("Got %d pools filtered for nasType=%s", len(filteredPools), nasType)
return filteredPools
}

// SortPoolsByPreferredTopologies returns a list of pools ordered by the pools supportedTopologies field against
// the provided list of preferredTopologies. If 2 or more pools can support a given preferredTopology, they are shuffled
// randomly within that segment of the list, in order to prevent hotspots.
Expand Down Expand Up @@ -419,8 +461,14 @@ func (s *StorageClass) GetStoragePoolsForProtocolByBackend(
if len(pools) == 0 {
Logc(ctx).Info("no backend pools support any requisite topologies")
}
pools = FilterPoolsOnNasType(ctx, pools, s.GetAttributes())
if len(pools) == 0 {
Logc(ctx).Info("no backend pools found for given NASType")
}
pools = SortPoolsByPreferredTopologies(ctx, pools, preferredTopologies)

Logc(ctx).Debugf("Finally got %d storage pools", len(pools))

return pools
}

Expand Down
Loading

0 comments on commit 59f1d6e

Please sign in to comment.