Skip to content

Commit 5a8406d

Browse files
committed
[linstor-csi-plugin] add params nil check
Signed-off-by: Slava V <[email protected]>
1 parent 345e7eb commit 5a8406d

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

images/linstor-csi/src/pkg/linstor/highlevelclient/high_level_client.go

+14-17
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,36 @@ func NewHighLevelClient(options ...lapi.Option) (*HighLevelClient, error) {
6262
// GenericAccessibleTopologies returns topologies based on linstor storage pools
6363
// and whether a resource is allowed to be accessed over the network.
6464
func (c *HighLevelClient) GenericAccessibleTopologies(ctx context.Context, volId string, remoteAccessPolicy volume.RemoteAccessPolicy, params *volume.AccessibleTopologiesParams) ([]*csi.Topology, error) {
65-
var zones, nodeNames []string
66-
var volumeAccess, topology string
67-
68-
if params != nil {
69-
zones = params.SCZones
70-
volumeAccess = params.SCVolumeAccess
71-
topology = params.SCTopology
65+
if params == nil {
66+
return nil, fmt.Errorf("params must not be nil")
7267
}
7368

7469
r, err := c.Resources.GetAll(ctx, volId)
7570
if err != nil {
7671
return nil, fmt.Errorf("unable to determine AccessibleTopologies: %v", err)
7772
}
78-
79-
switch volumeAccess {
73+
74+
var nodeNames []string
75+
switch params.SCVolumeAccess {
8076
case "PreferablyLocal", "EventuallyLocal", "Any":
81-
if topology == "TransZonal" {
82-
res := make([]*csi.Topology, len(zones))
83-
for i, zone := range zones {
77+
switch params.SCTopology {
78+
case "TransZonal":
79+
res := make([]*csi.Topology, len(params.SCZones))
80+
for i, zone := range params.SCZones {
8481
res[i] = &csi.Topology{Segments: map[string]string{"topology.kubernetes.io/zone": zone}}
8582
}
8683
return res, nil
87-
}
88-
if topology == "Zonal" {
84+
case "Zonal":
8985
nodeNames = util.DeployedDiskfullyNodes(r)
90-
}
91-
if topology == "Ignored" {
86+
case "Ignored":
9287
return []*csi.Topology{}, nil
88+
default:
89+
return nil, fmt.Errorf("invalid topology: %s", params.SCTopology)
9390
}
9491
case "Local":
9592
nodeNames = util.DeployedDiskfullyNodes(r)
9693
default:
97-
return nil, fmt.Errorf("invalid volume access policy: %s", volumeAccess)
94+
return nil, fmt.Errorf("invalid volume access policy: %s", params.SCVolumeAccess)
9895
}
9996

10097
nodes, err := c.Nodes.GetAll(ctx, &lapi.ListOpts{Node: nodeNames})

0 commit comments

Comments
 (0)