diff --git a/pkg/csi/manila/shareadapters/cephfs.go b/pkg/csi/manila/shareadapters/cephfs.go index 1741d82aed..4c729c3f34 100644 --- a/pkg/csi/manila/shareadapters/cephfs.go +++ b/pkg/csi/manila/shareadapters/cephfs.go @@ -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 @@ -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 { diff --git a/pkg/csi/manila/shareadapters/nfs.go b/pkg/csi/manila/shareadapters/nfs.go index 3eb3b97146..75accda33b 100644 --- a/pkg/csi/manila/shareadapters/nfs.go +++ b/pkg/csi/manila/shareadapters/nfs.go @@ -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 @@ -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 {