Skip to content

Commit

Permalink
feat(ws): add Workspace and WorkspaceKind CRD scaffolds (kubeflow#6)
Browse files Browse the repository at this point in the history
* feat(ws): add `Workspace` and `WorkspaceKind` CRD scaffolds

Co-authored-by: Mathew Wicks <[email protected]>

Signed-off-by: Jiri Daněk <[email protected]>

* fixup, regenerate WOrkspaceKind to be cluster scope

Signed-off-by: Jiri Daněk <[email protected]>

* fixes to crd spec

Signed-off-by: Mathew Wicks <[email protected]>

* updates to CRD spec

Signed-off-by: Mathew Wicks <[email protected]>

---------

Signed-off-by: Jiri Daněk <[email protected]>
Signed-off-by: Mathew Wicks <[email protected]>
Co-authored-by: Mathew Wicks <[email protected]>
  • Loading branch information
2 people authored and Adembc committed Jun 20, 2024
1 parent 12cd353 commit e74ad99
Show file tree
Hide file tree
Showing 9 changed files with 3,506 additions and 30 deletions.
1 change: 0 additions & 1 deletion workspaces/controller/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ resources:
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: kubeflow.org
kind: WorkspaceKind
Expand Down
120 changes: 113 additions & 7 deletions workspaces/controller/api/v1beta1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,60 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// 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.

// WorkspaceSpec defines the desired state of Workspace
type WorkspaceSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of Workspace. Edit workspace_types.go to remove/update
Foo string `json:"foo,omitempty"`
// if the workspace should be paused (no pods running)
//+kubebuilder:default=false
//+kubebuilder:validation:Optional
Paused bool `json:"paused,omitempty"`

// the WorkspaceKind to use
//+kubebuilder:validation:Required
//+kubebuilder:validation:MinLength:=2
//+kubebuilder:validation:MaxLength:=63
//+kubebuilder:validation:Pattern:=^[a-z0-9][-a-z0-9]*[a-z0-9]$
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Workspace 'kind' is immutable"
//+kubebuilder:example="jupyter-lab"
Kind string `json:"kind"`

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

// WorkspaceStatus defines the observed state of Workspace
type WorkspaceStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// 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
Expand All @@ -62,3 +97,74 @@ type WorkspaceList struct {
func init() {
SchemeBuilder.Register(&Workspace{}, &WorkspaceList{})
}

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

// volume configs
Volumes PodVolumes `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"`
}

type PodMetadata struct {
// labels to be applied to the Pod resource
//+kubebuilder:validation:Optional
Labels map[string]string `json:"labels,omitempty"`

// annotations to be applied to the Pod resource
//+kubebuilder:validation:Optional
Annotations map[string]string `json:"annotations,omitempty"`
}

type PodVolumes struct {
// A PVC to mount as the home directory.
// This PVC must already exist in the Namespace
// This PVC must be RWX (ReadWriteMany, ReadWriteOnce)
// Mount path is defined in the WorkspaceKind under `spec.podTemplate.volumeMounts.home`
//+kubebuilder:validation:MinLength:=2
//+kubebuilder:validation:MaxLength:=63
//+kubebuilder:validation:Pattern:=^[a-z0-9][-a-z0-9]*[a-z0-9]$
//+kubebuilder:example="my-home-pvc"
Home string `json:"home"`

// additional data PVCs to mount, these PVCs must already exist in the Namespace
//+kubebuilder:validation:Optional
Data []PodVolumeMount `json:"data,omitempty"`
}

type PodVolumeMount struct {
//+kubebuilder:validation:MinLength:=2
//+kubebuilder:validation:MaxLength:=63
//+kubebuilder:validation:Pattern:=^[a-z0-9][-a-z0-9]*[a-z0-9]$
//+kubebuilder:example="my-data-pvc"
Name string `json:"name"`

//+kubebuilder:validation:MinLength:=2
//+kubebuilder:validation:MaxLength:=4096
//+kubebuilder:validation:Pattern:=^/[^/].*$
//+kubebuilder:example="/data/my-data"
MountPath string `json:"mountPath"`
}

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

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

type Options struct {
// the id of an image option
// - options are defined in WorkspaceKind under
// `spec.podTemplate.options.imageConfig.values[]`
//+kubebuilder:example="jupyter_scipy_170"
ImageConfig string `json:"imageConfig"`

//+kubebuilder:example="big_gpu"
PodConfig string `json:"podConfig"`
}
Loading

0 comments on commit e74ad99

Please sign in to comment.