@@ -42,6 +42,12 @@ import (
4242 filev1beta1multishare "google.golang.org/api/file/v1beta1"
4343)
4444
45+ // PerformanceConfig holds performance parameters for a Filestore instance.
46+ type PerformanceConfig struct {
47+ FixedIOPS int64 // Fixed IOPS (input/output operations per second).
48+ IOPSPerTB int64 // IOPS per TiB for density-based provisioning.
49+ }
50+
4551const (
4652 testEndpoint = "test-file.sandbox.googleapis.com"
4753 stagingEndpoint = "staging-file.sandbox.googleapis.com"
@@ -99,18 +105,19 @@ type ListFilter struct {
99105}
100106
101107type ServiceInstance struct {
102- Project string
103- Name string
104- Location string
105- Tier string
106- Network Network
107- Volume Volume
108- Labels map [string ]string
109- State string
110- KmsKeyName string
111- BackupSource string
112- NfsExportOptions []* NfsExportOptions
113- Protocol string
108+ Project string
109+ Name string
110+ Location string
111+ Tier string
112+ Network Network
113+ Volume Volume
114+ Labels map [string ]string
115+ State string
116+ KmsKeyName string
117+ BackupSource string
118+ NfsExportOptions []* NfsExportOptions
119+ Protocol string
120+ PerformanceConfig * PerformanceConfig
114121}
115122
116123type Volume struct {
@@ -166,6 +173,7 @@ type Service interface {
166173 GetInstance (ctx context.Context , obj * ServiceInstance ) (* ServiceInstance , error )
167174 ListInstances (ctx context.Context , obj * ServiceInstance ) ([]* ServiceInstance , error )
168175 ResizeInstance (ctx context.Context , obj * ServiceInstance ) (* ServiceInstance , error )
176+ UpdateInstancePerformance (ctx context.Context , obj * ServiceInstance , perfConfig * PerformanceConfig ) error
169177 GetBackup (ctx context.Context , backupUri string ) (* Backup , error )
170178 CreateBackup (ctx context.Context , backupInfo * BackupInfo ) (* filev1beta1.Backup , error )
171179 DeleteBackup (ctx context.Context , backupId string ) error
@@ -297,7 +305,26 @@ func (manager *gcfsServiceManager) CreateInstance(ctx context.Context, obj *Serv
297305 Protocol : obj .Protocol ,
298306 }
299307
300- 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" ,
308+ // Add performance config if provided. Only one of FixedIOPS or IOPSPerTB
309+ // may be set at a time.
310+ if obj .PerformanceConfig != nil {
311+ if obj .PerformanceConfig .FixedIOPS > 0 && obj .PerformanceConfig .IOPSPerTB > 0 {
312+ return nil , fmt .Errorf ("performance config must have only one of FixedIOPS or IOPSPerTB set" )
313+ }
314+ instance .PerformanceConfig = & filev1beta1.PerformanceConfig {}
315+ if obj .PerformanceConfig .FixedIOPS > 0 {
316+ instance .PerformanceConfig .FixedIops = & filev1beta1.FixedIOPS {
317+ MaxIops : obj .PerformanceConfig .FixedIOPS ,
318+ }
319+ }
320+ if obj .PerformanceConfig .IOPSPerTB > 0 {
321+ instance .PerformanceConfig .IopsPerTb = & filev1beta1.IOPSPerTB {
322+ MaxIopsPerTb : obj .PerformanceConfig .IOPSPerTB ,
323+ }
324+ }
325+ }
326+
327+ 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, performance config %+v" ,
301328 obj .Name ,
302329 obj .Location ,
303330 instance .Tier ,
@@ -308,7 +335,8 @@ func (manager *gcfsServiceManager) CreateInstance(ctx context.Context, obj *Serv
308335 instance .KmsKeyName ,
309336 instance .Labels ,
310337 instance .FileShares [0 ].SourceBackup ,
311- obj .Protocol )
338+ obj .Protocol ,
339+ obj .PerformanceConfig )
312340 op , err := manager .instancesService .Create (locationURI (obj .Project , obj .Location ), instance ).InstanceId (obj .Name ).Context (ctx ).Do ()
313341 if err != nil {
314342 klog .Errorf ("CreateInstance operation failed for instance %v: %v" , obj .Name , err )
@@ -356,6 +384,19 @@ func cloudInstanceToServiceInstance(instance *filev1beta1.Instance) (*ServiceIns
356384 if len (instance .Networks [0 ].IpAddresses ) > 0 {
357385 ip = instance .Networks [0 ].IpAddresses [0 ]
358386 }
387+ // Map performance config if present
388+ var perfCfg * PerformanceConfig
389+ if instance .PerformanceConfig != nil {
390+ perf := & PerformanceConfig {}
391+ if instance .PerformanceConfig .FixedIops != nil {
392+ perf .FixedIOPS = instance .PerformanceConfig .FixedIops .MaxIops
393+ }
394+ if instance .PerformanceConfig .IopsPerTb != nil {
395+ perf .IOPSPerTB = instance .PerformanceConfig .IopsPerTb .MaxIopsPerTb
396+ }
397+ perfCfg = perf
398+ }
399+
359400 return & ServiceInstance {
360401 Project : project ,
361402 Location : location ,
@@ -371,11 +412,12 @@ func cloudInstanceToServiceInstance(instance *filev1beta1.Instance) (*ServiceIns
371412 ReservedIpRange : instance .Networks [0 ].ReservedIpRange ,
372413 ConnectMode : instance .Networks [0 ].ConnectMode ,
373414 },
374- KmsKeyName : instance .KmsKeyName ,
375- Labels : instance .Labels ,
376- State : instance .State ,
377- BackupSource : instance .FileShares [0 ].SourceBackup ,
378- Protocol : instance .Protocol ,
415+ KmsKeyName : instance .KmsKeyName ,
416+ Labels : instance .Labels ,
417+ State : instance .State ,
418+ BackupSource : instance .FileShares [0 ].SourceBackup ,
419+ Protocol : instance .Protocol ,
420+ PerformanceConfig : perfCfg ,
379421 }, nil
380422}
381423
@@ -513,6 +555,56 @@ func (manager *gcfsServiceManager) ResizeInstance(ctx context.Context, obj *Serv
513555 return instance , nil
514556}
515557
558+ // UpdateInstancePerformance updates the performance configuration of a Filestore instance.
559+ func (manager * gcfsServiceManager ) UpdateInstancePerformance (ctx context.Context , obj * ServiceInstance , perfConfig * PerformanceConfig ) error {
560+ if perfConfig == nil {
561+ return fmt .Errorf ("performance config cannot be nil" )
562+ }
563+
564+ instanceuri := instanceURI (obj .Project , obj .Location , obj .Name )
565+
566+ // Validate config and log the intended change
567+ if perfConfig .FixedIOPS <= 0 && perfConfig .IOPSPerTB <= 0 {
568+ return fmt .Errorf ("performance config must have either FixedIOPS or IOPSPerTB set" )
569+ }
570+ if perfConfig .FixedIOPS > 0 && perfConfig .IOPSPerTB > 0 {
571+ return fmt .Errorf ("performance config must have only one of FixedIOPS or IOPSPerTB set" )
572+ }
573+
574+ // Create a file instance for the Patch request with performance config
575+ betaObj := & filev1beta1.Instance {
576+ PerformanceConfig : & filev1beta1.PerformanceConfig {},
577+ }
578+
579+ if perfConfig .FixedIOPS > 0 {
580+ klog .V (4 ).Infof ("Updating instance %q with FixedIOPS: %d" , obj .Name , perfConfig .FixedIOPS )
581+ betaObj .PerformanceConfig .FixedIops = & filev1beta1.FixedIOPS {
582+ MaxIops : perfConfig .FixedIOPS ,
583+ }
584+ }
585+ if perfConfig .IOPSPerTB > 0 {
586+ klog .V (4 ).Infof ("Updating instance %q with IOPSPerTB: %d" , obj .Name , perfConfig .IOPSPerTB )
587+ betaObj .PerformanceConfig .IopsPerTb = & filev1beta1.IOPSPerTB {
588+ MaxIopsPerTb : perfConfig .IOPSPerTB ,
589+ }
590+ }
591+
592+ klog .V (4 ).Infof ("Patching instance %q with performance configuration: %+v" , obj .Name , perfConfig )
593+ op , err := manager .instancesService .Patch (instanceuri , betaObj ).UpdateMask ("performanceConfig" ).Context (ctx ).Do ()
594+ if err != nil {
595+ return fmt .Errorf ("patch operation failed for performance update: %w" , err )
596+ }
597+
598+ klog .V (4 ).Infof ("For instance %s, waiting for performance update op %v to complete" , instanceuri , op .Name )
599+ err = manager .waitForOp (ctx , op )
600+ if err != nil {
601+ return fmt .Errorf ("WaitFor performance update op %s failed: %w" , op .Name , err )
602+ }
603+
604+ klog .Infof ("Successfully updated performance configuration for instance %q" , obj .Name )
605+ return nil
606+ }
607+
516608func (manager * gcfsServiceManager ) GetBackup (ctx context.Context , backupUri string ) (* Backup , error ) {
517609 backup , err := manager .backupService .Get (backupUri ).Context (ctx ).Do ()
518610 if err != nil {
0 commit comments