Skip to content

Commit

Permalink
fix(CSI-275): version of NFS is only set to V4 during NFS permission …
Browse files Browse the repository at this point in the history
…creation (#354)

### TL;DR

Enhanced NFS permission handling and version matching in the WekaFS API client.

### What changed?

- Implemented a `Matches` method for `NfsPermission` to compare permissions.
- Modified `FindNfsPermissionsByFilter` to use the new `Matches` method.
- Updated `EnsureNfsPermission` to support both NFSv3 and NFSv4 by default.

### How to test?

1. Create NFS permission having both versions V3 and V4 set on WEKA Cluster. 

2. Attempt to provision a PVC via NFS transport

3. Ensure that provisioning succeeds

### Why make this change?

This change improves the flexibility and accuracy of NFS permission handling. If a permission exists that allows access via both NFSv3 and NFSv4 (and it matches by all the rest of parameters), the CSI plugin will recognize it and not try to create a duplicate permission
  • Loading branch information
sergeyberezansky authored Oct 8, 2024
2 parents 932a7d8 + 00e37ba commit 1c19ef1
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions pkg/wekafs/apiclient/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type NfsPermissionType string
type NfsPermissionSquashMode string
type NfsClientGroupRuleType string
type NfsVersionString string
type NfsVersionStrings []NfsVersionString

func (n NfsVersionString) String() string {
return string(n)
Expand All @@ -32,6 +33,15 @@ func (n NfsVersionString) AsWeka() NfsVersionString {
return NfsVersionString(strings.Split(n.String(), ".")[0])
}

func (s NfsVersionStrings) Matches(other []NfsVersionString) bool {
for _, v := range s {
if !slices.Contains(other, v) {
return false
}
}
return true
}

type NfsAuthType string

//goland:noinspection GoUnusedConst
Expand All @@ -54,7 +64,7 @@ const (
type NfsPermission struct {
GroupId string `json:"group_id,omitempty" url:"-"`
PrivilegedPort bool `json:"privileged_port,omitempty" url:"-"`
SupportedVersions []NfsVersionString `json:"supported_versions,omitempty" url:"-"`
SupportedVersions NfsVersionStrings `json:"supported_versions,omitempty" url:"-"`
Id string `json:"id,omitempty" url:"-"`
ObsDirect bool `json:"obs_direct,omitempty" url:"-"`
AnonUid string `json:"anon_uid,omitempty" url:"-"`
Expand Down Expand Up @@ -94,6 +104,18 @@ func (n *NfsPermission) EQ(other ApiObject) bool {
return ObjectsAreEqual(n, other)
}

func (n *NfsPermission) Matches(o NfsPermission) bool {
if n.SquashMode == o.SquashMode &&
n.Filesystem == o.Filesystem &&
n.Group == o.Group &&
n.Path == o.Path &&
n.PermissionType == o.PermissionType &&
n.SupportedVersions.Matches(o.SupportedVersions) {
return true
}
return false
}

func (n *NfsPermission) getImmutableFields() []string {
return []string{"Group", "Filesystem", "SupportedVersions", "PermissionType", "Path", "SquashMode"}
}
Expand All @@ -120,7 +142,7 @@ func (a *ApiClient) FindNfsPermissionsByFilter(ctx context.Context, query *NfsPe
return err
}
for _, r := range *ret {
if r.EQ(query) {
if r.EQ(query) || query.Matches(r) {
*resultSet = append(*resultSet, r)
}
}
Expand Down Expand Up @@ -232,7 +254,7 @@ func (a *ApiClient) CreateNfsPermission(ctx context.Context, r *NfsPermissionCre

func EnsureNfsPermission(ctx context.Context, fsName string, group string, version NfsVersionString, apiClient *ApiClient) error {
perm := &NfsPermission{
SupportedVersions: []NfsVersionString{version.AsWeka()},
SupportedVersions: NfsVersionStrings{version.AsWeka()},
AnonUid: strconv.Itoa(65534),
AnonGid: strconv.Itoa(65534),
Filesystem: fsName,
Expand All @@ -252,7 +274,7 @@ func EnsureNfsPermission(ctx context.Context, fsName string, group string, versi
SquashMode: NfsPermissionSquashModeNone,
AnonGid: 65534,
AnonUid: 65534,
SupportedVersions: &[]string{string(NfsVersionV4)},
SupportedVersions: &[]string{NfsVersionV3.String(), NfsVersionV4.String()},
}
if err := apiClient.CreateNfsPermission(ctx, req, perm); err != nil {
return err
Expand Down

0 comments on commit 1c19ef1

Please sign in to comment.