Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Testing] initial v4 changes for single share #1002

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
65 changes: 55 additions & 10 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 @@ -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,29 @@ 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:
if isBasicTier(tier) {
fileProtocol = v3FileProtocol
} else {
fileProtocol = v4_1FileProtocol
}
}

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

Expand All @@ -699,9 +730,23 @@ 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:
if isBasicTier(instance.Tier) {
resp.VolumeContext[attrFileProtocol] = v3FileProtocol
} else {
resp.VolumeContext[attrFileProtocol] = v4_1FileProtocol
}
}

return resp
}

Expand Down
Loading