Skip to content

Commit

Permalink
Merge pull request #1032 from riteshghorse/nfsv4
Browse files Browse the repository at this point in the history
Filestore NFSv4 support
  • Loading branch information
k8s-ci-robot authored Jan 8, 2025
2 parents a0dd647 + f351011 commit 6c974a4
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 67 deletions.
1 change: 1 addition & 0 deletions pkg/cloud_provider/file/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (manager *fakeServiceManager) CreateInstance(ctx context.Context, obj *Serv
State: "READY",
BackupSource: obj.BackupSource,
NfsExportOptions: obj.NfsExportOptions,
Protocol: obj.Protocol,
}

manager.createdInstances[obj.Name] = instance
Expand Down
26 changes: 17 additions & 9 deletions pkg/cloud_provider/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type MultishareInstance struct {
KmsKeyName string
Description string
MaxShareCount int
Protocol string
}

func (i *MultishareInstance) String() string {
Expand All @@ -109,6 +110,7 @@ type ServiceInstance struct {
KmsKeyName string
BackupSource string
NfsExportOptions []*NfsExportOptions
Protocol string
}

type Volume struct {
Expand All @@ -124,9 +126,10 @@ type Network struct {
}

type Backup struct {
Backup *filev1beta1.Backup
SourceInstance string
SourceShare string
Backup *filev1beta1.Backup
SourceInstance string
SourceShare string
FileSystemProtocl string
}

type BackupInfo struct {
Expand Down Expand Up @@ -291,9 +294,10 @@ func (manager *gcfsServiceManager) CreateInstance(ctx context.Context, obj *Serv
KmsKeyName: obj.KmsKeyName,
Labels: obj.Labels,
State: obj.State,
Protocol: obj.Protocol,
}

klog.V(4).Infof("Creating instance %q: location %v, tier %q, capacity %v, network %q, ipRange %q, connectMode %q, KmsKeyName %q, labels %v backup source %q",
klog.V(4).Infof("Creating instance %q: location %v, tier %q, capacity %v, network %q, ipRange %q, connectMode %q, KmsKeyName %q, labels %v, backup source %q, protocol %v",
obj.Name,
obj.Location,
instance.Tier,
Expand All @@ -303,7 +307,8 @@ func (manager *gcfsServiceManager) CreateInstance(ctx context.Context, obj *Serv
instance.Networks[0].ConnectMode,
instance.KmsKeyName,
instance.Labels,
instance.FileShares[0].SourceBackup)
instance.FileShares[0].SourceBackup,
obj.Protocol)
op, err := manager.instancesService.Create(locationURI(obj.Project, obj.Location), instance).InstanceId(obj.Name).Context(ctx).Do()
if err != nil {
klog.Errorf("CreateInstance operation failed for instance %v: %v", obj.Name, err)
Expand Down Expand Up @@ -370,6 +375,7 @@ func cloudInstanceToServiceInstance(instance *filev1beta1.Instance) (*ServiceIns
Labels: instance.Labels,
State: instance.State,
BackupSource: instance.FileShares[0].SourceBackup,
Protocol: instance.Protocol,
}, nil
}

Expand Down Expand Up @@ -513,9 +519,10 @@ func (manager *gcfsServiceManager) GetBackup(ctx context.Context, backupUri stri
return nil, err
}
return &Backup{
Backup: backup,
SourceInstance: backup.SourceInstance,
SourceShare: backup.SourceFileShare,
Backup: backup,
SourceInstance: backup.SourceInstance,
SourceShare: backup.SourceFileShare,
FileSystemProtocl: backup.FileSystemProtocol,
}, nil
}

Expand Down Expand Up @@ -990,6 +997,7 @@ func (manager *gcfsServiceManager) StartCreateMultishareInstanceOp(ctx context.C
Labels: instance.Labels,
Description: instance.Description,
MaxShareCount: int64(instance.MaxShareCount),
Protocol: instance.Protocol,
}

op, err := manager.multishareInstancesService.Create(locationURI(instance.Project, instance.Location), targetinstance).InstanceId(instance.Name).Context(ctx).Do()
Expand Down Expand Up @@ -1019,6 +1027,7 @@ func (manager *gcfsServiceManager) StartResizeMultishareInstanceOp(ctx context.C
KmsKeyName: obj.KmsKeyName,
Labels: obj.Labels,
Description: obj.Description,
Protocol: obj.Protocol,
}
op, err := manager.multishareInstancesService.Patch(instanceuri, targetinstance).UpdateMask(multishareCapacityUpdateMask).Context(ctx).Do()
if err != nil {
Expand Down Expand Up @@ -1138,7 +1147,6 @@ func (manager *gcfsServiceManager) ListShares(ctx context.Context, filter *ListF
klog.Errorf("Failed to parse share url :%s", sobj.Name)
return nil, err
}

s := &Share{
Name: shareName,
Parent: &MultishareInstance{
Expand Down
63 changes: 50 additions & 13 deletions pkg/csi_driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ const (
modeInstance = "modeInstance"
newInstanceVolume = "vol1"

defaultTier = "standard"
enterpriseTier = "enterprise"
premiumTier = "premium"
basicHDDTier = "basic_hdd"
basicSSDTier = "basic_ssd"
highScaleTier = "high_scale_ssd"
zonalTier = "zonal"
defaultNetwork = "default"
defaultTier = "standard"
enterpriseTier = "enterprise"
premiumTier = "premium"
basicHDDTier = "basic_hdd"
basicSSDTier = "basic_ssd"
highScaleTier = "high_scale_ssd"
zonalTier = "zonal"
defaultNetwork = "default"
v3FileProtocol = "NFS_V3"
v4_1FileProtocol = "NFS_V4_1"

defaultTierMinSize = 1 * util.Tb
defaultTierMaxSize = 639 * util.Tb / 10
Expand All @@ -72,6 +74,7 @@ const (
attrIP = "ip"
attrVolume = "volume"
attrSupportLockRelease = "supportLockRelease"
attrFileProtocol = "fileProtocol"
)

// CreateVolume parameters
Expand All @@ -87,6 +90,7 @@ const (
ParamMultishareInstanceScLabel = "instance-storageclass-label"
ParamNfsExportOptions = "nfs-export-options-on-create"
paramMaxVolumeSize = "max-volume-size"
paramFileProtocol = "protocol"

// Keys for PV and PVC parameters as reported by external-provisioner
ParameterKeyPVCName = "csi.storage.k8s.io/pvc/name"
Expand Down Expand Up @@ -279,13 +283,13 @@ func (s *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu
// Check if the filestore instance is in the process of getting created.
if filer.State == "CREATING" {
msg := fmt.Sprintf("Volume %v not ready, current state: %v", name, filer.State)
klog.V(4).Infof(msg)
klog.V(4).Info(msg)
return nil, status.Error(codes.DeadlineExceeded, msg)
}
if filer.State != "READY" {
msg := fmt.Sprintf("Volume %v not ready, current state: %v", name, filer.State)
klog.V(4).Infof(msg)
return nil, status.Errorf(codes.Unavailable, msg)
klog.V(4).Info(msg)
return nil, status.Error(codes.Unavailable, msg)
}
} else {
param := req.GetParameters()
Expand Down Expand Up @@ -603,6 +607,14 @@ func invalidVolumeExpansionRequest(capRange *csi.CapacityRange, currentCapacity
return false
}

func isBasicTier(tier string) bool {
switch tier {
case defaultTier, premiumTier, basicHDDTier, basicSSDTier:
return true
}
return false
}

// generateNewFileInstance populates the GCFS Instance object using
// CreateVolume parameters
func (s *controllerServer) generateNewFileInstance(name string, capBytes int64, params map[string]string, topo *csi.TopologyRequirement) (*file.ServiceInstance, error) {
Expand All @@ -617,6 +629,7 @@ func (s *controllerServer) generateNewFileInstance(name string, capBytes int64,
network := defaultNetwork
connectMode := directPeering
kmsKeyName := ""
fileProtocol := ""

// Validate parameters (case-insensitive).
for k, v := range params {
Expand Down Expand Up @@ -655,12 +668,25 @@ func (s *controllerServer) generateNewFileInstance(name string, capBytes int64,
continue
case cloud.ParameterKeyResourceTags:
continue
case paramFileProtocol:
fileProtocol = v
case ParameterKeyLabels, ParameterKeyPVCName, ParameterKeyPVCNamespace, ParameterKeyPVName:
case "csiprovisionersecretname", "csiprovisionersecretnamespace":
default:
return nil, fmt.Errorf("invalid parameter %q", k)
}
}

switch fileProtocol {
case v4_1FileProtocol:
if isBasicTier(tier) {
return nil, status.Errorf(codes.FailedPrecondition, "Filestore does not support NFSv4.1 protocol with Basic tiers")
}
case v3FileProtocol:
default:
fileProtocol = v3FileProtocol
}

return &file.ServiceInstance{
Project: s.config.cloud.Project,
Name: name,
Expand All @@ -676,6 +702,7 @@ func (s *controllerServer) generateNewFileInstance(name string, capBytes int64,
},
KmsKeyName: kmsKeyName,
NfsExportOptions: nfsExportOptions,
Protocol: fileProtocol,
}, nil
}

Expand All @@ -699,9 +726,19 @@ func (s *controllerServer) fileInstanceToCSIVolume(instance *file.ServiceInstanc
}
resp.ContentSource = contentSource
}
if s.config.features.FeatureLockRelease.Enabled && strings.ToLower(instance.Tier) == enterpriseTier {
resp.VolumeContext[attrSupportLockRelease] = "true"

switch instance.Protocol {
case v4_1FileProtocol:
resp.VolumeContext[attrFileProtocol] = v4_1FileProtocol
case v3FileProtocol:
resp.VolumeContext[attrFileProtocol] = v3FileProtocol
if s.config.features.FeatureLockRelease.Enabled && strings.ToLower(instance.Tier) == enterpriseTier {
resp.VolumeContext[attrSupportLockRelease] = "true"
}
default:
resp.VolumeContext[attrFileProtocol] = v3FileProtocol
}

return resp
}

Expand Down
Loading

0 comments on commit 6c974a4

Please sign in to comment.