Skip to content

Commit

Permalink
feat(ws): update Workspace and WorkspaceKind definitions (#16)
Browse files Browse the repository at this point in the history
Signed-off-by: Mathew Wicks <[email protected]>
  • Loading branch information
thesuperzapper authored Jun 21, 2024
1 parent 0ff4d03 commit 565a740
Show file tree
Hide file tree
Showing 8 changed files with 861 additions and 458 deletions.
176 changes: 105 additions & 71 deletions workspaces/controller/api/v1beta1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import (
)

// Important: Run "make" to regenerate code after modifying this file
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

/*
===============================================================================
Workspace - Spec
===============================================================================
*/

// WorkspaceSpec defines the desired state of Workspace
type WorkspaceSpec struct {
Expand All @@ -41,76 +46,22 @@ type WorkspaceSpec struct {
Kind string `json:"kind"`

// options for "podTemplate"-type WorkspaceKinds
PodTemplate PodTemplate `json:"podTemplate"`
}

// WorkspaceStatus defines the observed state of Workspace
type WorkspaceStatus struct {

// information populated by activity probes, used to determine when to cull
Activity Activity `json:"activity"`

// the time when the Workspace was paused, 0 if the Workspace is not paused
//+kubebuilder:example=1704067200
PauseTime int64 `json:"pauseTime"`

// if the current Pod does not reflect the current "desired" state (after redirects)
//+kubebuilder:example=false
PendingRestart bool `json:"pendingRestart"`

// actual "target" podTemplateOptions, taking into account redirects
PodTemplateOptions Options `json:"podTemplateOptions"`

// the current state of the Workspace
//+kubebuilder:validation:Enum:={"Running","Terminating","Paused","Pending","Error","Unknown"}
//+kubebuilder:example="Running"
State string `json:"state"`

// a human-readable message about the state of the Workspace
// WARNING: this field is NOT FOR MACHINE USE, subject to change without notice
//+kubebuilder:example="Pod is not ready"
StateMessage string `json:"stateMessage"`
}

//+kubebuilder:object:root=true
//+kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="The current state of the Workspace"
//+kubebuilder:subresource:status

// Workspace is the Schema for the workspaces API
type Workspace struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec WorkspaceSpec `json:"spec,omitempty"`
Status WorkspaceStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// WorkspaceList contains a list of Workspace
type WorkspaceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Workspace `json:"items"`
PodTemplate WorkspacePodTemplate `json:"podTemplate"`
}

func init() {
SchemeBuilder.Register(&Workspace{}, &WorkspaceList{})
}

type PodTemplate struct {
type WorkspacePodTemplate struct {
// metadata to be applied to the Pod resource
//+kubebuilder:validation:Optional
PodMetadata PodMetadata `json:"podMetadata,omitempty"`
PodMetadata WorkspacePodMetadata `json:"podMetadata,omitempty"`

// volume configs
Volumes PodVolumes `json:"volumes"`
Volumes WorkspacePodVolumes `json:"volumes"`

// spawner options, these are the user-selected options from the Workspace Spawner UI which determine the PodSpec of the Workspace Pod
Options Options `json:"options"`
Options WorkspacePodOptions `json:"options"`
}

type PodMetadata struct {
type WorkspacePodMetadata struct {
// labels to be applied to the Pod resource
//+kubebuilder:validation:Optional
Labels map[string]string `json:"labels,omitempty"`
Expand All @@ -120,7 +71,7 @@ type PodMetadata struct {
Annotations map[string]string `json:"annotations,omitempty"`
}

type PodVolumes struct {
type WorkspacePodVolumes struct {
// A PVC to mount as the home directory.
// This PVC must already exist in the Namespace
// This PVC must be RWX (ReadWriteMany, ReadWriteOnce)
Expand Down Expand Up @@ -150,15 +101,7 @@ type PodVolumeMount struct {
MountPath string `json:"mountPath"`
}

type Activity struct {
//+kubebuilder:example=1704067200
LastActivity int64 `json:"lastActivity"`

//+kubebuilder:example=1704067200
LastUpdate int64 `json:"lastUpdate"`
}

type Options struct {
type WorkspacePodOptions struct {
// the id of an image option
// - options are defined in WorkspaceKind under
// `spec.podTemplate.options.imageConfig.values[]`
Expand All @@ -168,3 +111,94 @@ type Options struct {
//+kubebuilder:example="big_gpu"
PodConfig string `json:"podConfig"`
}

/*
===============================================================================
Workspace - Status
===============================================================================
*/

// WorkspaceStatus defines the observed state of Workspace
type WorkspaceStatus struct {

// information populated by activity probes, used to determine when to cull
Activity WorkspaceActivity `json:"activity"`

// the time when the Workspace was paused, 0 if the Workspace is not paused
//+kubebuilder:example=1704067200
PauseTime int64 `json:"pauseTime"`

// if the current Pod does not reflect the current "desired" state (after redirects)
//+kubebuilder:example=false
PendingRestart bool `json:"pendingRestart"`

// actual "target" podTemplateOptions, taking into account redirects
PodTemplateOptions WorkspacePodOptions `json:"podTemplateOptions"`

// the current state of the Workspace
//+kubebuilder:example="Running"
State WorkspaceState `json:"state"`

// a human-readable message about the state of the Workspace
// WARNING: this field is NOT FOR MACHINE USE, subject to change without notice
//+kubebuilder:example="Pod is not ready"
StateMessage string `json:"stateMessage"`
}

type WorkspaceActivity struct {
//+kubebuilder:example=1704067200
LastActivity int64 `json:"lastActivity"`

//+kubebuilder:example=1704067200
LastUpdate int64 `json:"lastUpdate"`
}

// +kubebuilder:validation:Enum:={"Running","Terminating","Paused","Pending","Error","Unknown"}
type WorkspaceState string

const (
WorkspaceStateRunning WorkspaceState = "Running"
WorkspaceStateTerminating WorkspaceState = "Terminating"
WorkspaceStatePaused WorkspaceState = "Paused"
WorkspaceStatePending WorkspaceState = "Pending"
WorkspaceStateError WorkspaceState = "Error"
WorkspaceStateUnknown WorkspaceState = "Unknown"
)

/*
===============================================================================
Workspace
===============================================================================
*/

//+kubebuilder:object:root=true
//+kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="The current state of the Workspace"
//+kubebuilder:subresource:status

// Workspace is the Schema for the Workspaces API
type Workspace struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec WorkspaceSpec `json:"spec,omitempty"`
Status WorkspaceStatus `json:"status,omitempty"`
}

/*
===============================================================================
WorkspaceList
===============================================================================
*/

//+kubebuilder:object:root=true

// WorkspaceList contains a list of Workspace
type WorkspaceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Workspace `json:"items"`
}

func init() {
SchemeBuilder.Register(&Workspace{}, &WorkspaceList{})
}
Loading

0 comments on commit 565a740

Please sign in to comment.