Skip to content

Commit

Permalink
Do not delete cluster that is older than 7 days (#88)
Browse files Browse the repository at this point in the history
* do-not-delete-clusters-that-are-older-than-7-days

* typos

* Update controllers/cluster_controller.go

Co-authored-by: Andreas Sommer <[email protected]>

* Update CHANGELOG.md

Co-authored-by: Andreas Sommer <[email protected]>

---------

Co-authored-by: Andreas Sommer <[email protected]>
  • Loading branch information
calvix and AndiDog authored Apr 30, 2024
1 parent c6154db commit 357c976
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Ignore cluster from being deleted, if it is older than 7 days and does not have the `keep-until` label. This is to prevent the deletion of customer clusters in case this app is accidentally deployed to a production MC.

## [0.9.0] - 2024-02-15

### Changed
Expand Down
8 changes: 8 additions & 0 deletions controllers/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ func (r *ClusterReconciler) reconcile(ctx context.Context, cluster *capi.Cluster
log.Info(fmt.Sprintf("Found label %s. Cluster will be ignored for deletion", keepUntil))
return ctrl.Result{RequeueAfter: 24 * time.Hour}, nil
}
} else {
// ignore cluster from being deleted if it is older than 7 days and do NOT have keep-until label
// this is to prevent deletion in a case of accidental deployment of the app to production MCs
if time.Since(cluster.CreationTimestamp.Time).Hours() > 24*7 {
log.Info(fmt.Sprintf("Cluster is older than 7 days and does not have label %s. Cluster will be ignored for deletion", keepUntil))
return ctrl.Result{}, nil
}

}

// immediately delete the cluster if defaultTTL has passed
Expand Down

0 comments on commit 357c976

Please sign in to comment.