Skip to content

Commit 7c1c704

Browse files
authored
Add subordinate volume support for autogrow in serial core
1 parent 8e65251 commit 7c1c704

File tree

2 files changed

+327
-59
lines changed

2 files changed

+327
-59
lines changed

core/orchestrator_core.go

Lines changed: 81 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -364,24 +364,8 @@ func (o *TridentOrchestrator) bootstrapVolumes(ctx context.Context) error {
364364

365365
// Rebuild Autogrow policy associations (CSI mode only)
366366
if config.CurrentDriverContext == config.ContextCSI {
367-
// Resolve effective Autogrow policy
368-
effectiveAGPolicy, policyErr := o.resolveEffectiveAutogrowPolicy(ctx, vol.Config)
369-
if policyErr != nil {
370-
if errors.IsAutogrowPolicyNotFoundError(policyErr) {
371-
Logc(ctx).WithFields(LogFields{
372-
"volume": vol.Config.Name,
373-
}).Debug("Referenced Autogrow policy not found during bootstrap.")
374-
} else if errors.IsAutogrowPolicyNotUsableError(policyErr) {
375-
Logc(ctx).WithFields(LogFields{
376-
"volume": vol.Config.Name,
377-
}).Debug("Referenced Autogrow policy not usable during bootstrap.")
378-
}
379-
}
380-
381-
// Always set effective Autogrow policy even if it does not exist yet
382-
vol.EffectiveAGPolicy = effectiveAGPolicy
367+
effectiveAGPolicy, policyErr := o.resolveAndSetEffectiveAutogrowPolicy(ctx, vol, "bootstrap", true)
383368
// Associate only if policy exists AND not disabled
384-
// Skips if: policyErr != nil OR effectiveAGPolicy.PolicyName == ""
385369
if policyErr == nil && effectiveAGPolicy.PolicyName != "" {
386370
o.associateVolumeWithAutogrowPolicyInternal(ctx, vol.Config.Name, effectiveAGPolicy.PolicyName)
387371
}
@@ -2287,20 +2271,7 @@ func (o *TridentOrchestrator) addVolumeFinish(
22872271
}
22882272

22892273
// Resolve and set the EffectiveAGPolicy before saving to persistent store
2290-
effectiveAGPolicy, policyErr := o.resolveEffectiveAutogrowPolicy(ctx, vol.Config)
2291-
// Associate only if policy exists AND not disabled
2292-
if policyErr != nil {
2293-
if errors.IsAutogrowPolicyNotFoundError(policyErr) {
2294-
Logc(ctx).WithFields(LogFields{
2295-
"volume": vol.Config.Name,
2296-
}).Warn("Referenced Autogrow policy not found during volume creation.")
2297-
} else if errors.IsAutogrowPolicyNotUsableError(policyErr) {
2298-
Logc(ctx).WithFields(LogFields{
2299-
"volume": vol.Config.Name,
2300-
}).Warn("Referenced Autogrow policy not usable during volume creation.")
2301-
}
2302-
}
2303-
vol.EffectiveAGPolicy = effectiveAGPolicy
2274+
effectiveAGPolicy, policyErr := o.resolveAndSetEffectiveAutogrowPolicy(ctx, vol, "volume creation", false)
23042275

23052276
// Add new volume to persistent store
23062277
if err = o.storeClient.AddVolume(ctx, vol); err != nil {
@@ -3008,27 +2979,15 @@ func (o *TridentOrchestrator) ImportVolume(
30082979
volumeConfig.ImportBackendUUID, err)
30092980
}
30102981

2982+
// Resolve the effective Autogrow policy for the volume and associate the volume with the Autogrow policy
2983+
effectiveAGPolicy, policyErr := o.resolveAndSetEffectiveAutogrowPolicy(ctx, volume, "volume import", false)
2984+
30112985
err = o.storeClient.AddVolume(ctx, volume)
30122986
if err != nil {
30132987
return nil, fmt.Errorf("failed to persist imported volume data: %v", err)
30142988
}
30152989
o.volumes[volumeConfig.Name] = volume
30162990

3017-
// Resolve the effective Autogrow policy for the volume and associate the volume with the Autogrow policy
3018-
effectiveAGPolicy, policyErr := o.resolveEffectiveAutogrowPolicy(ctx, volume.Config)
3019-
if policyErr != nil {
3020-
if errors.IsAutogrowPolicyNotFoundError(policyErr) {
3021-
Logc(ctx).WithFields(LogFields{
3022-
"volume": volume.Config.Name,
3023-
}).Warn("Referenced Autogrow policy not found during volume import")
3024-
} else if errors.IsAutogrowPolicyNotUsableError(policyErr) {
3025-
Logc(ctx).WithFields(LogFields{
3026-
"volume": volume.Config.Name,
3027-
}).Warn("Referenced Autogrow policy not usable during volume import")
3028-
}
3029-
}
3030-
volume.EffectiveAGPolicy = effectiveAGPolicy
3031-
30322991
// Associate only if policy exists and if effectiveAGPolicy.PolicyName is not empty
30332992
if policyErr == nil && effectiveAGPolicy.PolicyName != "" {
30342993
o.associateVolumeWithAutogrowPolicyInternal(ctx, volume.Config.Name, volume.EffectiveAGPolicy.PolicyName)
@@ -4275,6 +4234,9 @@ func (o *TridentOrchestrator) addSubordinateVolume(
42754234
volume = storage.NewVolume(volumeConfig, sourceVolume.BackendUUID, sourceVolume.Pool, false,
42764235
storage.VolumeStateSubordinate)
42774236

4237+
// Resolve and set the EffectiveAGPolicy before saving to persistent store
4238+
effectiveAGPolicy, policyErr := o.resolveAndSetEffectiveAutogrowPolicy(ctx, volume, "subordinate volume creation", false)
4239+
42784240
// Add new volume to persistent store
42794241
if err = o.storeClient.AddVolume(ctx, volume); err != nil {
42804242
return nil, err
@@ -4288,6 +4250,11 @@ func (o *TridentOrchestrator) addSubordinateVolume(
42884250

42894251
// Update internal cache and return external form of the new volume
42904252
o.subordinateVolumes[volume.Config.Name] = volume
4253+
// Associate volume with Autogrow policy if Autogrow policy is present and Autogrow policy name is not empty
4254+
if policyErr == nil && effectiveAGPolicy.PolicyName != "" {
4255+
o.associateVolumeWithAutogrowPolicyInternal(ctx, volume.Config.Name, volume.EffectiveAGPolicy.PolicyName)
4256+
}
4257+
42914258
return volume.ConstructExternal(), nil
42924259
}
42934260

@@ -4324,6 +4291,11 @@ func (o *TridentOrchestrator) deleteSubordinateVolume(ctx context.Context, volum
43244291
}
43254292
}
43264293

4294+
// Store deletion succeeded - now safe to disassociate from Autogrow policy
4295+
if volume.EffectiveAGPolicy.PolicyName != "" {
4296+
o.disassociateVolumeFromAutogrowPolicyInternal(ctx, volumeName, volume.EffectiveAGPolicy.PolicyName)
4297+
}
4298+
43274299
delete(o.subordinateVolumes, volumeName)
43284300
return nil
43294301
}
@@ -6101,7 +6073,7 @@ func (o *TridentOrchestrator) DeleteStorageClass(ctx context.Context, scName str
61016073
}).Debug("Re-resolving Autogrow policy for volumes after StorageClass deletion.")
61026074

61036075
// Find all volumes using this deleted SC
6104-
for _, volume := range o.volumes {
6076+
for _, volume := range o.getAllVolumes() {
61056077
// Only update volumes that:
61066078
// 1. Were using this SC
61076079
// 2. Have NO volume-level autogrow policy (were inheriting from SC)
@@ -7861,8 +7833,12 @@ func (o *TridentOrchestrator) UpdateVolumeAutogrowPolicy(
78617833
// Get the volume
78627834
volume, ok := o.volumes[volumeName]
78637835
if !ok {
7864-
o.mutex.Unlock()
7865-
return errors.NotFoundError("volume %s not found", volumeName)
7836+
// Check if the volume is a subordinate volume
7837+
volume, ok = o.subordinateVolumes[volumeName]
7838+
if !ok {
7839+
o.mutex.Unlock()
7840+
return errors.NotFoundError("volume %s not found", volumeName)
7841+
}
78667842
}
78677843

78687844
// Store old effective Autogrow policy for comparison
@@ -8006,7 +7982,7 @@ func (o *TridentOrchestrator) upsertStorageClassAutogrowPolicyInternal(
80067982
}
80077983
newEffectiveAGPolicy, policyError = o.resolveEffectiveAutogrowPolicy(ctx, tempConfig)
80087984
// Find all volumes using this storage class and update their effective policy
8009-
for _, volume := range o.volumes {
7985+
for _, volume := range o.getAllVolumes() {
80107986
// Only update volumes that use this SC and have no volume-level autogrow policy
80117987
if volume.Config.StorageClass != scName || volume.Config.RequestedAutogrowPolicy != "" {
80127988
continue // Early continue for non-matching volumes
@@ -8210,7 +8186,11 @@ func (o *TridentOrchestrator) invalidateVolumesForPolicy(ctx context.Context, ag
82108186
for _, associatedVolumeName := range associatedVolumes {
82118187
associatedVolume, ok := o.volumes[associatedVolumeName]
82128188
if !ok {
8213-
continue
8189+
// Check if the volume is a subordinate volume
8190+
associatedVolume, ok = o.subordinateVolumes[associatedVolumeName]
8191+
if !ok {
8192+
continue
8193+
}
82148194
}
82158195

82168196
// Disassociate from this policy
@@ -8239,7 +8219,7 @@ func (o *TridentOrchestrator) invalidateVolumesForPolicy(ctx context.Context, ag
82398219
// For Success policies: volumes are associated
82408220
// For Failed/Deleting policies: volume reasons are updated to "Unusable" without association
82418221
func (o *TridentOrchestrator) reevaluateVolumesForPolicy(ctx context.Context, agPolicyName string) {
8242-
for _, volume := range o.volumes {
8222+
for _, volume := range o.getAllVolumes() {
82438223
// Skip volumes that explicitly reference a different policy
82448224
// If volume has autogrow policy for a different policy, it can't use this one
82458225
if volume.Config.RequestedAutogrowPolicy != "" {
@@ -8286,3 +8266,52 @@ func (o *TridentOrchestrator) reevaluateVolumesForPolicy(ctx context.Context, ag
82868266
"policyName": agPolicyName,
82878267
}).Info("Completed re-evaluating volumes for policy.")
82888268
}
8269+
8270+
// getAllVolumes returns all volumes (regular + subordinate) as a slice.
8271+
// Assumes the orchestrator mutex is already held by the caller.
8272+
func (o *TridentOrchestrator) getAllVolumes() []*storage.Volume {
8273+
allVolumes := make([]*storage.Volume, 0, len(o.volumes)+len(o.subordinateVolumes))
8274+
for _, vol := range o.volumes {
8275+
allVolumes = append(allVolumes, vol)
8276+
}
8277+
for _, vol := range o.subordinateVolumes {
8278+
allVolumes = append(allVolumes, vol)
8279+
}
8280+
return allVolumes
8281+
}
8282+
8283+
// resolveAndSetEffectiveAutogrowPolicy resolves the effective Autogrow policy for a volume,
8284+
// logs any errors appropriately, and sets it on the volume.
8285+
// Returns the policy info and any error for the caller to handle association logic.
8286+
// Assumes the orchestrator mutex is already held by the caller.
8287+
func (o *TridentOrchestrator) resolveAndSetEffectiveAutogrowPolicy(
8288+
ctx context.Context, vol *storage.Volume, operationContext string, isBootstrap bool,
8289+
) (models.EffectiveAutogrowPolicyInfo, error) {
8290+
// Resolve effective Autogrow policy
8291+
effectiveAGPolicy, policyErr := o.resolveEffectiveAutogrowPolicy(ctx, vol.Config)
8292+
8293+
// Log any resolution errors
8294+
if policyErr != nil {
8295+
logFields := LogFields{"volume": vol.Config.Name}
8296+
if errors.IsAutogrowPolicyNotFoundError(policyErr) {
8297+
msg := fmt.Sprintf("Referenced Autogrow policy not found during %s.", operationContext)
8298+
if isBootstrap {
8299+
Logc(ctx).WithFields(logFields).Debug(msg)
8300+
} else {
8301+
Logc(ctx).WithFields(logFields).Warn(msg)
8302+
}
8303+
} else if errors.IsAutogrowPolicyNotUsableError(policyErr) {
8304+
msg := fmt.Sprintf("Referenced Autogrow policy not usable during %s.", operationContext)
8305+
if isBootstrap {
8306+
Logc(ctx).WithFields(logFields).Debug(msg)
8307+
} else {
8308+
Logc(ctx).WithFields(logFields).Warn(msg)
8309+
}
8310+
}
8311+
}
8312+
8313+
// Always set effective Autogrow policy even if it does not exist yet
8314+
vol.EffectiveAGPolicy = effectiveAGPolicy
8315+
8316+
return effectiveAGPolicy, policyErr
8317+
}

0 commit comments

Comments
 (0)