Skip to content

Commit 1fe9593

Browse files
committed
Reverted changes to volume manager
Added CnsPVCProtectionCleanupIntervalInMin to Config and a watcher for it
1 parent 2b0d73a commit 1fe9593

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

pkg/common/cns-lib/volume/manager.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,7 @@ func constructBatchAttachSpecList(ctx context.Context, vm *cnsvsphere.VirtualMac
35323532
Sharing: volume.SharingMode,
35333533
DiskMode: volume.DiskMode,
35343534
BackingTypeName: cnstypes.CnsVolumeBackingType(volume.BackingType),
3535+
VolumeEncrypted: volume.VolumeEncrypted,
35353536
}
35363537

35373538
// Set controllerKey and unitNumber only if they are provided by the user.
@@ -3541,11 +3542,6 @@ func constructBatchAttachSpecList(ctx context.Context, vm *cnsvsphere.VirtualMac
35413542
if volume.UnitNumber != nil {
35423543
cnsAttachDetachSpec.UnitNumber = volume.UnitNumber
35433544
}
3544-
// Set volumeEncrypted only if it's provided and encryption is enabled.
3545-
// This field is not supported by older vCenter versions, so we only set it when needed.
3546-
if volume.VolumeEncrypted != nil && *volume.VolumeEncrypted {
3547-
cnsAttachDetachSpec.VolumeEncrypted = volume.VolumeEncrypted
3548-
}
35493545
cnsAttachSpecList = append(cnsAttachSpecList, cnsAttachDetachSpec)
35503546
}
35513547

pkg/common/config/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ const (
6868
// interval after which successful CnsRegisterVolumes will be cleaned up.
6969
// Current default value is set to 12 hours
7070
DefaultCnsRegisterVolumesCleanupIntervalInMin = 720
71+
// DefaultCnsPVCProtectionCleanupIntervalInMin is the default time interval after which
72+
// orphaned PVCs will be cleaned up.
73+
// Current default value is set to 12 hours
74+
DefaultCnsPVCProtectionCleanupIntervalInMin = 720
7175
// DefaultVolumeMigrationCRCleanupIntervalInMin is the default time interval
7276
// after which stale CnsVSphereVolumeMigration CRs will be cleaned up.
7377
// Current default value is set to 2 hours.
@@ -451,6 +455,9 @@ func validateConfig(ctx context.Context, cfg *Config) error {
451455
if cfg.Global.CnsRegisterVolumesCleanupIntervalInMin == 0 {
452456
cfg.Global.CnsRegisterVolumesCleanupIntervalInMin = DefaultCnsRegisterVolumesCleanupIntervalInMin
453457
}
458+
if cfg.Global.CnsPVCProtectionCleanupIntervalInMin == 0 {
459+
cfg.Global.CnsPVCProtectionCleanupIntervalInMin = DefaultCnsPVCProtectionCleanupIntervalInMin
460+
}
454461
if cfg.Global.VolumeMigrationCRCleanupIntervalInMin == 0 {
455462
cfg.Global.VolumeMigrationCRCleanupIntervalInMin = DefaultVolumeMigrationCRCleanupIntervalInMin
456463
}

pkg/common/config/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ type Config struct {
5151
// CnsRegisterVolumesCleanupIntervalInMin specifies the interval after which
5252
// successful CnsRegisterVolumes will be cleaned up.
5353
CnsRegisterVolumesCleanupIntervalInMin int `gcfg:"cnsregistervolumes-cleanup-intervalinmin"`
54+
// CnsPVCProtectionCleanupIntervalInMin specifies the interval after which
55+
// orphaned PVCs will be cleaned up.
56+
CnsPVCProtectionCleanupIntervalInMin int `gcfg:"cnspvcprotection-cleanup-intervalinmin"`
5457
// VolumeMigrationCRCleanupIntervalInMin specifies the interval after which
5558
// stale CnsVSphereVolumeMigration CRs will be cleaned up.
5659
VolumeMigrationCRCleanupIntervalInMin int `gcfg:"volumemigration-cr-cleanup-intervalinmin"`

pkg/syncer/cnsoperator/manager/init.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ func InitCnsOperator(ctx context.Context, clusterFlavor cnstypes.CnsClusterFlavo
138138
return err
139139
}
140140

141+
err = watcher(ctx, cnsOperator)
142+
if err != nil {
143+
log.Error("Failed to watch on config file for changes to "+
144+
"CnsPVCProtectionCleanupIntervalInMin. Error: %+v", err)
145+
return err
146+
}
147+
141148
// Start cleanup routine to remove orphaned PVC finalizers.
142149
// This handles cases where CnsNodeVMBatchAttachment CRs are deleted before
143150
// removing finalizers from their associated PVCs.
@@ -148,7 +155,7 @@ func InitCnsOperator(ctx context.Context, clusterFlavor cnstypes.CnsClusterFlavo
148155
log.Info("Triggering PVC finalizer cleanup routine")
149156
cleanupPVCs(ctx, *restConfig)
150157
log.Info("Completed PVC finalizer cleanup")
151-
for i := 1; i <= 2; i++ {
158+
for i := 1; i <= cnsOperator.configInfo.Cfg.Global.CnsPVCProtectionCleanupIntervalInMin; i++ {
152159
time.Sleep(1 * time.Minute)
153160
}
154161
}

0 commit comments

Comments
 (0)