-
Couldn't load subscription status.
- Fork 8
feat: idle-shutdown of workspaces #88
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
base: main
Are you sure you want to change the base?
Conversation
14d665b to
a875077
Compare
a875077 to
1b63898
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few high-level comments:
- pipe through the command as
execattribute of theidleShutdownConfig(following Probe precedent - look at probe interface, and evaluate if we should reuse the interface
- if no reuse, then evaluate which attributes are relevant
api/v1alpha1/workspace_types.go
Outdated
| // EndpointCheck specifies HTTP endpoint to check for idle status | ||
| // +optional | ||
| EndpointCheck *EndpointCheckSpec `json:"endpointCheck,omitempty"` | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-blocking: should there be a HealthCheckIntervalMinutes attribute or similar?
Consider following the precedent of ReadinessProbe:
kubectl explain pod.spec.containers.readinessProbeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did consider this - my preference is to start with a reasonable default ( in this PR it's 5 mins ) and add in support for HealthCheckIntervalMinutes in future if needed.
config/samples/idle-shutdown/templates/02-jupyter-template.yaml
Outdated
Show resolved
Hide resolved
| } | ||
| } | ||
|
|
||
| // CheckWorkspaceIdle checks if a workspace is idle using the configured detection method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add to the comment what the bool, bool return type means?
Consider creating a struct for better readability/maintainability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added an IdleCheckResult struct
internal/controller/idle_checker.go
Outdated
| return false, true, fmt.Errorf("failed to find workspace pod: %w", err) | ||
| } | ||
|
|
||
| logger.V(1).Info("Found workspace pod", "pod", pod.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sanity-check: are you sure you want to record this log? Your call, I'm just worried about the amount of logs in the Workspace reconciliation loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair point, removed
internal/controller/state_machine.go
Outdated
|
|
||
| // NewStateMachine creates a new StateMachine | ||
| func NewStateMachine(resourceManager *ResourceManager, statusManager *StatusManager, templateResolver *TemplateResolver, recorder record.EventRecorder) *StateMachine { | ||
| func NewStateMachine(resourceManager *ResourceManager, statusManager *StatusManager, templateResolver *TemplateResolver, recorder record.EventRecorder, idleChecker *WorkspaceIdleChecker) *StateMachine { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional: consider reformating with 1-arg per line.
internal/controller/state_machine.go
Outdated
|
|
||
| // If idle shutdown is not enabled, no requeue needed | ||
| if idleConfig == nil || !idleConfig.Enabled { | ||
| logger.V(1).Info("Idle shutdown not enabled") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the verbosity level is set to V(1) which is equivalent to debug
I can see them as DEBUG logs in controller logs
internal/controller/state_machine.go
Outdated
|
|
||
| logger.Info("Processing idle shutdown", | ||
| "timeout", idleConfig.TimeoutMinutes, | ||
| "resourceVersion", workspace.ResourceVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combine logs please
internal/controller/state_machine.go
Outdated
| logger.Info("Updated workspace desired status to Stopped") | ||
|
|
||
| // Immediate requeue to start stopping process | ||
| return ctrl.Result{RequeueAfter: 0}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider adding a minimal wait here (few ms)
internal/controller/state_machine.go
Outdated
| } | ||
|
|
||
| // areWorkspacePodsReady checks if workspace pods are ready for idle checking | ||
| func (sm *StateMachine) areWorkspacePodsReady(ctx context.Context, workspace *workspacev1alpha1.Workspace) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on logic, rename: isAtLeastOneWorkspacePodReady()
|
High-level question:
|
yes, it should be - I'm tracking that in separate issue - #84 |
I looked at the probe interface, Even though our implementation of HTTPGet detector internally uses pods/exec - that's an internal implementation detail. The detection method is still to make an http call at an endpoint - so I think it fits |
Add Idle Shutdown Support for Workspace and WorkspaceTemplates
Templates can define default idle shutdown settings settings that workspaces inherit or override within configurable bounds.
Workspaces automatically stop after the configured idle period.
Templates can enforce policies by disabling overrides or setting timeout limits.
Future items for idle-shutdown - #84
Other changes
Testing