Skip to content

Commit

Permalink
[manila-csi-plugin] support muilple share rules
Browse files Browse the repository at this point in the history
Signed-off-by: moonek <[email protected]>
  • Loading branch information
moonek committed Nov 20, 2024
1 parent b5965eb commit a435b1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
35 changes: 14 additions & 21 deletions pkg/csi/manila/shareadapters/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ func (Cephfs) GetOrGrantAccesses(args *GrantAccessArgs) ([]shares.AccessRight, e
}
}

var accessToList []string
if args.Options.CephfsClientID == "" {
accessToList = []string{args.Share.Name}
} else {
accessToList := []string{args.Share.Name}
if args.Options.CephfsClientID != "" {
accessToList = strings.Split(args.Options.CephfsClientID, ",")
}

modified := false
created := false
for _, at := range accessToList {
// Try to find the access right
found := false
Expand Down Expand Up @@ -81,31 +79,26 @@ func (Cephfs) GetOrGrantAccesses(args *GrantAccessArgs) ([]shares.AccessRight, e
wait.ExponentialBackoff(backoff, func() (bool, error) {
rights, err := args.ManilaClient.GetAccessRights(args.Share.ID)
if err != nil {
return false, err
return false, fmt.Errorf("error get access rights for share %s: %v", args.Share.ID, err)
}

var accessRight *shares.AccessRight

for i := range rights {
if rights[i].AccessTo == at {
accessRight = &rights[i]
break
}
}

if accessRight == nil {
if len(rights) == 0 {
return false, fmt.Errorf("cannot find the access right we've just created")
}

return accessRight.AccessKey != "", nil
for _, r := range rights {
if r.AccessTo == at && r.AccessKey != "" {
return true, nil
}
}
klog.V(4).Infof("Access key for %s is not set yet, retrying...", at)
return false, nil
})
}
modified = true
created = true
}
}

// Search again because access rights have changed
if modified {
if created {
rights, err = args.ManilaClient.GetAccessRights(args.Share.ID)
if err != nil {
if _, ok := err.(gophercloud.ErrResourceNotFound); !ok {
Expand Down
6 changes: 3 additions & 3 deletions pkg/csi/manila/shareadapters/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (NFS) GetOrGrantAccesses(args *GrantAccessArgs) ([]shares.AccessRight, erro

accessToList := strings.Split(args.Options.NFSShareClient, ",")

modified := false
created := false
for _, at := range accessToList {
// Try to find the access right
found := false
Expand All @@ -65,12 +65,12 @@ func (NFS) GetOrGrantAccesses(args *GrantAccessArgs) ([]shares.AccessRight, erro
if err != nil {
return nil, fmt.Errorf("failed to grant access right: %v", err)
}
modified = true
created = true
}
}

// Search again because access rights have changed
if modified {
if created {
rights, err = args.ManilaClient.GetAccessRights(args.Share.ID)
if err != nil {
if _, ok := err.(gophercloud.ErrResourceNotFound); !ok {
Expand Down

0 comments on commit a435b1b

Please sign in to comment.