Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not delete cluster that is older than 7 days #88

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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