Skip to content

Commit e1ee1da

Browse files
committed
fix: filter NFS shares by mountpoint in adoption capacity check
QueryAllNFSShares returns all shares unfiltered. handleExistingNFSVolume was blindly taking shares[0], which could be a different volume's share. This caused capacity mismatch errors when adopting multiple volumes of different sizes. Fixes #129
1 parent 9b67511 commit e1ee1da

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pkg/driver/controller_nfs.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,19 @@ func (s *ControllerService) handleExistingNFSVolume(ctx context.Context, params
320320
return nil, false, status.Errorf(codes.Internal, "Failed to query existing NFS shares: %v", err)
321321
}
322322

323-
if len(existingShares) == 0 {
324-
// Dataset exists but no NFS share - continue with share creation
325-
return nil, false, nil
323+
// Find the share matching this dataset's mountpoint
324+
var existingShare *tnsapi.NFSShare
325+
for i := range existingShares {
326+
if existingShares[i].Path == existingDataset.Mountpoint {
327+
existingShare = &existingShares[i]
328+
break
329+
}
326330
}
327331

328-
// Volume already exists with NFS share - check if capacity matches
329-
existingShare := existingShares[0]
332+
if existingShare == nil {
333+
// Dataset exists but no NFS share for this mountpoint - continue with share creation
334+
return nil, false, nil
335+
}
330336
klog.V(4).Infof("NFS volume already exists (share ID: %d), checking capacity compatibility", existingShare.ID)
331337

332338
existingCapacity := parseCapacityFromComment(existingShare.Comment)
@@ -349,7 +355,7 @@ func (s *ControllerService) handleExistingNFSVolume(ctx context.Context, params
349355
capacityToReturn = existingCapacity
350356
}
351357

352-
resp := buildNFSVolumeResponse(params.volumeName, params.server, existingDataset, &existingShare, capacityToReturn)
358+
resp := buildNFSVolumeResponse(params.volumeName, params.server, existingDataset, existingShare, capacityToReturn)
353359

354360
timer.ObserveSuccess()
355361
return resp, true, nil

0 commit comments

Comments
 (0)