Skip to content

Commit

Permalink
Driver Node should only ping arrays within the zone on which the pod …
Browse files Browse the repository at this point in the history
…is scheduled (#378)

* configure driver node service to only ping arrays in the same zone as the service.

Co-authored-by: Fernando Alfaro Campos <[email protected]>
Co-authored-by: Trevor Dawe <[email protected]>
  • Loading branch information
3 people committed Dec 18, 2024
1 parent 3495595 commit fc70ca9
Show file tree
Hide file tree
Showing 10 changed files with 858 additions and 154 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module github.com/dell/csi-vxflexos/v2
go 1.23

require (
github.com/akutz/memconn v0.1.0
github.com/apparentlymart/go-cidr v1.1.0
github.com/container-storage-interface/spec v1.6.0
github.com/cucumber/godog v0.15.0
Expand All @@ -16,7 +15,7 @@ require (
github.com/dell/dell-csi-extensions/volumeGroupSnapshot v1.7.0
github.com/dell/gocsi v1.12.0
github.com/dell/gofsutil v1.17.0
github.com/dell/goscaleio v1.17.1
github.com/dell/goscaleio v1.17.2-0.20241218182509-936b677c46d5
github.com/fsnotify/fsnotify v1.8.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
Expand Down
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/akutz/gosync v0.1.0 h1:naxPT/aDYDh79PMwM3XmencmNQeYmpNFSZy4ZE9zIW0=
github.com/akutz/gosync v0.1.0/go.mod h1:I8I4aiqJI1nqaeYOOB1WS+CgRJVVPqhct9Y4njywM84=
github.com/akutz/memconn v0.1.0 h1:NawI0TORU4hcOMsMr11g7vwlCdkYeLKXBcxWu2W/P8A=
github.com/akutz/memconn v0.1.0/go.mod h1:Jo8rI7m0NieZyLI5e2CDlRdRqRRB4S7Xp77ukDjH+Fw=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down Expand Up @@ -108,8 +106,16 @@ github.com/dell/gocsi v1.12.0 h1:Dn/8f2BLovo57T/aC5pP/4Eqz4h6WX8SbX+hxT5NlvQ=
github.com/dell/gocsi v1.12.0/go.mod h1:hJURrmDrXDGW4xVtgi5Kx6zUsU3ht9l+nlreNx33rf0=
github.com/dell/gofsutil v1.17.0 h1:QA6gUb1mz8kXNEN4eEx47OHCz8nSqZrrCnaDUYmV5EY=
github.com/dell/gofsutil v1.17.0/go.mod h1:PN2hWl/pVLQiTsFR0X1x+GfhfOrfW8pGgH5xGcGMeFs=
github.com/dell/goscaleio v1.17.1 h1:0gwR1c55ij3xVu/ARDWQNxBKCRlxMmg61n+5gKBX3v8=
github.com/dell/goscaleio v1.17.1/go.mod h1:7bX3rL8JWMmdifGr/UeD/Ju9wbkHUqvKDrbdu7XyGm8=
github.com/dell/goscaleio v1.17.2-0.20241209165307-dcbadc33ab2e h1:Y+F8YP3ceH6XRz0phFV5VpS2Pmoi8f0Vtg261/C2pZo=
github.com/dell/goscaleio v1.17.2-0.20241209165307-dcbadc33ab2e/go.mod h1:7bX3rL8JWMmdifGr/UeD/Ju9wbkHUqvKDrbdu7XyGm8=
github.com/dell/goscaleio v1.17.2-0.20241213145027-141cfe292cfa h1:9honWWT9xEcI0OWyLtiWIDCaMAEpBAeyyzW+KPRVh10=
github.com/dell/goscaleio v1.17.2-0.20241213145027-141cfe292cfa/go.mod h1:7bX3rL8JWMmdifGr/UeD/Ju9wbkHUqvKDrbdu7XyGm8=
github.com/dell/goscaleio v1.17.2-0.20241213204026-19006b56eb26 h1:Kg6MSwBmAlmUDWRKiG0YJRv1xd8qi9+mW7vAVNnghj4=
github.com/dell/goscaleio v1.17.2-0.20241213204026-19006b56eb26/go.mod h1:7bX3rL8JWMmdifGr/UeD/Ju9wbkHUqvKDrbdu7XyGm8=
github.com/dell/goscaleio v1.17.2-0.20241213215244-2164caaef4ab h1:DYWY7fs8v1VbmzF2pAx7peZtKhkppW5NCIyHCJN1fS4=
github.com/dell/goscaleio v1.17.2-0.20241213215244-2164caaef4ab/go.mod h1:7bX3rL8JWMmdifGr/UeD/Ju9wbkHUqvKDrbdu7XyGm8=
github.com/dell/goscaleio v1.17.2-0.20241218182509-936b677c46d5 h1:d7DwHvp7/hESR742f4iurtH3nHHSGPvnMadujZA2hsU=
github.com/dell/goscaleio v1.17.2-0.20241218182509-936b677c46d5/go.mod h1:2BsR92dYYnSmbZ34ixYdsucfyoQBDlbhbUUKnv6WalQ=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
Expand Down
94 changes: 83 additions & 11 deletions service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2270,13 +2270,16 @@ func (s *service) getSystemCapacity(ctx context.Context, systemID, protectionDom

adminClient := s.adminClients[systemID]
system := s.systems[systemID]
if adminClient == nil || system == nil {
return 0, fmt.Errorf("can't find adminClient or system by id %s", systemID)
}

var statsFunc func() (*siotypes.Statistics, error)

// Default to get Capacity of system
statsFunc = system.GetStatistics

if len(spName) > 0 {
if len(spName) > 0 && spName[0] != "" {
// if storage pool is given, get capacity of storage pool
pdID, err := s.getProtectionDomainIDFromName(systemID, protectionDomain)
if err != nil {
Expand Down Expand Up @@ -2369,6 +2372,15 @@ func (s *service) GetCapacity(
}
}

// If using availability zones, get capacity for the system in the zone
// using accessible topology parameter from k8s.
if s.opts.zoneLabelKey != "" {
systemID, err = s.getSystemIDFromZoneLabelKey(req)
if err != nil {
return nil, status.Errorf(codes.Internal, "%s", err.Error())
}
}

if systemID == "" {
// Get capacity of storage pool spname in all systems, return total capacity
capacity, err = s.getCapacityForAllSystems(ctx, "", spname)
Expand Down Expand Up @@ -2411,6 +2423,28 @@ func (s *service) GetCapacity(
}, nil
}

// getSystemIDFromZoneLabelKey returns the system ID associated with the zoneLabelKey if zoneLabelKey is set and
// contains an associated zone name. Returns an empty string otherwise.
func (s *service) getSystemIDFromZoneLabelKey(req *csi.GetCapacityRequest) (systemID string, err error) {
zoneName, ok := req.AccessibleTopology.Segments[s.opts.zoneLabelKey]
if !ok {
Log.Infof("could not get availability zone from accessible topology. Getting capacity for all systems")
return "", nil
}

// find the systemID with the matching zone name
for _, array := range s.opts.arrays {
if zoneName == string(array.AvailabilityZone.Name) {
systemID = array.SystemID
break
}
}
if systemID == "" {
return "", fmt.Errorf("could not find an array assigned to zone '%s'", zoneName)
}
return systemID, nil
}

func (s *service) getMaximumVolumeSize(systemID string) (int64, error) {
valueInCache, found := getCachedMaximumVolumeSize(systemID)
if !found || valueInCache < 0 {
Expand Down Expand Up @@ -2558,15 +2592,51 @@ func (s *service) ControllerGetCapabilities(
}, nil
}

func (s *service) getZoneFromZoneLabelKey(ctx context.Context, zoneLabelKey string) (zone string, err error) {
// get labels for this service, s
labels, err := GetNodeLabels(ctx, s)
if err != nil {
return "", err
}

Log.Infof("Listing labels: %v", labels)

// get the zone name from the labels
if val, ok := labels[zoneLabelKey]; ok {
return val, nil
}

return "", fmt.Errorf("label %s not found", zoneLabelKey)
}

// systemProbeAll will iterate through all arrays in service.opts.arrays and probe them. If failed, it logs
// the failed system name
func (s *service) systemProbeAll(ctx context.Context) error {
// probe all arrays
Log.Infof("Probing all arrays. Number of arrays: %d", len(s.opts.arrays))
Log.Infoln("Probing all associated arrays")
allArrayFail := true
errMap := make(map[string]error)
zoneName := ""
usingZones := s.opts.zoneLabelKey != "" && s.isNodeMode()

if usingZones {
var err error
zoneName, err = s.getZoneFromZoneLabelKey(ctx, s.opts.zoneLabelKey)
if err != nil {
return err
}
Log.Infof("probing zoneLabel '%s', zone value: '%s'", s.opts.zoneLabelKey, zoneName)
}

for _, array := range s.opts.arrays {
// If zone information is available, use it to probe the array
if usingZones && !array.isInZone(zoneName) {
// Driver node containers should not probe arrays that exist outside their assigned zone
// Driver controller container should probe all arrays
Log.Infof("array %s zone %s does not match %s, not pinging this array\n", array.SystemID, array.AvailabilityZone.Name, zoneName)
continue
}

err := s.systemProbe(ctx, array)
systemID := array.SystemID
if err == nil {
Expand All @@ -2587,23 +2657,23 @@ func (s *service) systemProbeAll(ctx context.Context) error {
}

// systemProbe will probe the given array
func (s *service) systemProbe(_ context.Context, array *ArrayConnectionData) error {
func (s *service) systemProbe(ctx context.Context, array *ArrayConnectionData) error {
// Check that we have the details needed to login to the Gateway
if array.Endpoint == "" {
return status.Error(codes.FailedPrecondition,
"missing VxFlexOS Gateway endpoint")
"missing PowerFlex Gateway endpoint")
}
if array.Username == "" {
return status.Error(codes.FailedPrecondition,
"missing VxFlexOS MDM user")
"missing PowerFlex MDM user")
}
if array.Password == "" {
return status.Error(codes.FailedPrecondition,
"missing VxFlexOS MDM password")
"missing PowerFlex MDM password")
}
if array.SystemID == "" {
return status.Error(codes.FailedPrecondition,
"missing VxFlexOS system name")
"missing PowerFlex system name")
}
var altSystemNames []string
if array.AllSystemNames != "" {
Expand All @@ -2626,25 +2696,27 @@ func (s *service) systemProbe(_ context.Context, array *ArrayConnectionData) err
}
}

Log.Printf("Login to PowerFlex Gateway, system=%s, endpoint=%s, user=%s\n", systemID, array.Endpoint, array.Username)

if s.adminClients[systemID].GetToken() == "" {
_, err := s.adminClients[systemID].Authenticate(&goscaleio.ConfigConnect{
_, err := s.adminClients[systemID].WithContext(ctx).Authenticate(&goscaleio.ConfigConnect{
Endpoint: array.Endpoint,
Username: array.Username,
Password: array.Password,
})
if err != nil {
return status.Errorf(codes.FailedPrecondition,
"unable to login to VxFlexOS Gateway: %s", err.Error())
"unable to login to PowerFlex Gateway: %s", err.Error())
}
}

// initialize system if needed
if s.systems[systemID] == nil {
system, err := s.adminClients[systemID].FindSystem(
system, err := s.adminClients[systemID].WithContext(ctx).FindSystem(
array.SystemID, array.SystemID, "")
if err != nil {
return status.Errorf(codes.FailedPrecondition,
"unable to find matching VxFlexOS system name: %s",
"unable to find matching PowerFlex system name: %s",
err.Error())
}
s.systems[systemID] = system
Expand Down
Loading

0 comments on commit fc70ca9

Please sign in to comment.