Skip to content

Commit

Permalink
PB-7645: Add pause to cleanup of resources if env is set in kdmp-conf…
Browse files Browse the repository at this point in the history
…ig configmap

Signed-off-by: Abhisheka <[email protected]>
  • Loading branch information
aks-px committed Jul 26, 2024
1 parent 1f487d1 commit 4187bb4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
19 changes: 17 additions & 2 deletions pkg/controllers/dataexport/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,12 @@ func (c *Controller) stageLocalSnapshotRestore(ctx context.Context, dataExport *
}
return true, c.updateStatus(dataExport, data)
} else if dataExport.Status.Status == kdmpapi.DataExportStatusFailed {
err := c.cleanupLocalRestoredSnapshotResources(dataExport, false)
val, err := utils.PauseCleanupResource()
if err == nil && val != 0 {
logrus.Infof("Starting to wait for %v minutes before cleanup of local restored snapshot resources for dataexport:%v", val, dataExport.Name)
time.Sleep(val)
}
err = c.cleanupLocalRestoredSnapshotResources(dataExport, false)
if err != nil {
logrus.Errorf("cleaning up temporary resources for restoring from snapshot failed for data export %s/%s: %v", dataExport.Namespace, dataExport.Name, err)
}
Expand Down Expand Up @@ -1284,7 +1289,12 @@ func (c *Controller) stageLocalSnapshotRestoreInProgress(ctx context.Context, da
}
return true, c.updateStatus(dataExport, data)
} else if dataExport.Status.Status == kdmpapi.DataExportStatusFailed {
err := c.cleanupLocalRestoredSnapshotResources(dataExport, false)
val, err := utils.PauseCleanupResource()
if err == nil && val != 0 {
logrus.Infof("Starting to wait for %v minutes before cleanup of local restored snapshots for dataexport:%v", val, dataExport.Name)
time.Sleep(val)
}
err = c.cleanupLocalRestoredSnapshotResources(dataExport, false)
// Already done with max retries, so moving to kdmp restore anyway
if err != nil {
logrus.Errorf("cleaning up temporary resources for restoring from snapshot failed for data export %s/%s: %v", dataExport.Namespace, dataExport.Name, err)
Expand Down Expand Up @@ -1455,6 +1465,11 @@ func (c *Controller) cleanUp(driver drivers.Interface, de *kdmpapi.DataExport) e
// No cleanup needed for rsync
return nil
}
val, err := utils.PauseCleanupResource()
if err == nil && val != 0 {
logrus.Infof("Starting to wait for %v minutes before cleanup of dataexport:%v", val, de.Name)
time.Sleep(val)
}
if hasLocalRestoreStage(de) {
err := c.cleanupLocalRestoredSnapshotResources(de, true)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/controllers/resourceexport/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"reflect"
"time"

storkapi "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
"github.com/libopenstorage/stork/pkg/controllers"
Expand Down Expand Up @@ -245,6 +246,11 @@ func (c *Controller) process(ctx context.Context, in *kdmpapi.ResourceExport) (b
}

func (c *Controller) cleanupResources(resourceExport *kdmpapi.ResourceExport) error {
val, err := utils.PauseCleanupResource()
if err == nil && val != 0 {
logrus.Infof("Starting to wait for %v minutes before cleanup of resourceExport:%v", val, resourceExport.Name)
time.Sleep(val)
}
// clean up resources
rbNamespace, rbName, err := utils.ParseJobID(resourceExport.Status.TransferID)
if err != nil {
Expand Down
27 changes: 23 additions & 4 deletions pkg/drivers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ const (
ResourceCleanupKey = "RESOURCE_CLEANUP"
// ResourceCleanupDefaultValue is true as resource cleanup process is enabled by default for debugging user can set to false.
ResourceCleanupDefaultValue = "true"
volumeinitialDelay = 2 * time.Second
volumeFactor = 1.5
volumeSteps = 15
nfsVolumeSize = "10Gi"
// PauseResourceCleanupKey - this key pauses the resource cleanup process.
PauseResourceCleanupKey = "PAUSE_RESOURCE_CLEANUP"
volumeinitialDelay = 2 * time.Second
volumeFactor = 1.5
volumeSteps = 15
nfsVolumeSize = "10Gi"
// ResourceUploadSuccessMsg - resource update success message
ResourceUploadSuccessMsg = "upload resource Successfully"
// PvcBoundSuccessMsg - pvc bound success message
Expand Down Expand Up @@ -1088,3 +1090,20 @@ func GetOcpNsUidGid(nsName string, psaJobUid string, psaJobGid string) (string,
}
return psaJobUid, psaJobGid, isOcp, nil
}

// PauseCleanupResource returns whether to pause the cleanup the CRs & other resources.
func PauseCleanupResource() (time.Duration, error) {
pauseCleanupVal := time.Duration(0)
pauseCleanupValStr, err := k8sutils.GetConfigValue(KdmpConfig, defaultPXNamespace, PauseResourceCleanupKey)
if err != nil {
logrus.Errorf("Failed to get %s key from kdmp-config-map: %v", PauseResourceCleanupKey, err)
return pauseCleanupVal, err
}
if pauseCleanupValStr != "" {
pauseCleanupVal, err = time.ParseDuration(pauseCleanupValStr)
if err != nil {
return pauseCleanupVal, err
}
}
return pauseCleanupVal, nil
}

0 comments on commit 4187bb4

Please sign in to comment.