Skip to content

Commit 7f85b00

Browse files
committed
feat: add DevWorkspace pruner
Signed-off-by: Oleksii Kurinnyi <[email protected]>
1 parent fc93707 commit 7f85b00

File tree

7 files changed

+518
-0
lines changed

7 files changed

+518
-0
lines changed

apis/controller/v1alpha1/devworkspaceoperatorconfig_types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@ type OperatorConfiguration struct {
4949
EnableExperimentalFeatures *bool `json:"enableExperimentalFeatures,omitempty"`
5050
}
5151

52+
type CleanupCronJobConfig struct {
53+
// Enable determines whether the cleanup cron job is enabled.
54+
// Defaults to false if not specified.
55+
// +kubebuilder:validation:Optional
56+
Enable *bool `json:"enable,omitempty"`
57+
// Image specifies the container image to use for the cleanup cron job.
58+
// If not specified, a suitable default image for the Kubernetes/OpenShift environment will be used.
59+
// +kubebuilder:validation:Optional
60+
Image string `json:"image,omitempty"`
61+
// RetainTime specifies the minimum time (in seconds) since a DevWorkspace was last started before it is considered stale and eligible for cleanup.
62+
// For example, a value of 2592000 (30 days) would mean that any DevWorkspace that has not been started in the last 30 days will be deleted.
63+
// Defaults to 2592000 seconds (30 days) if not specified.
64+
// +kubebuilder:validation:Minimum=0
65+
// +kubebuilder:default:=2592000
66+
// +kubebuilder:validation:Optional
67+
RetainTime *int32 `json:"retainTime,omitempty"`
68+
// DryRun determines whether the cleanup cron job should be run in dry-run mode.
69+
// If set to true, the cron job will not delete any DevWorkspaces, but will log the DevWorkspaces that would have been deleted.
70+
// Defaults to false if not specified.
71+
// +kubebuilder:validation:Optional
72+
DryRun *bool `json:"dryRun,omitempty"`
73+
// CronJobScript specifies the name of a ConfigMap containing the script to be executed by the cleanup cron job.
74+
// This ConfigMap must reside in the same namespace as the DevWorkspace Operator.
75+
// The script is responsible for identifying and deleting stale DevWorkspaces (based on the `retainTime`).
76+
// The script must be idempotent. If not specified, defaults to `devworkspace-pruner`.
77+
// +kubebuilder:default:=devworkspace-pruner
78+
// +kubebuilder:validation:Optional
79+
CronJobScript string `json:"cronJobScript,omitempty"`
80+
}
81+
5282
type RoutingConfig struct {
5383
// DefaultRoutingClass specifies the routingClass to be used when a DevWorkspace
5484
// specifies an empty `.spec.routingClass`. Supported routingClasses can be defined
@@ -161,6 +191,8 @@ type WorkspaceConfig struct {
161191
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
162192
// RuntimeClassName defines the spec.runtimeClassName for DevWorkspace pods created by the DevWorkspace Operator.
163193
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
194+
// CleanupCronJobConfig defines configuration options for a cron job that automatically cleans up stale DevWorkspaces.
195+
CleanupCronJob *CleanupCronJobConfig `json:"cleanupCronJob,omitempty"`
164196
}
165197

166198
type WebhookConfig struct {

0 commit comments

Comments
 (0)