Documentation
¶
Overview ¶
Package k8s provides Kubernetes client functionality for StreamSpace CRD operations.
This file implements the Kubernetes client wrapper for StreamSpace custom resources.
Purpose: - Provide typed access to StreamSpace CRDs (Session, Template) - Wrap Kubernetes dynamic client for custom resource operations - Simplify CRUD operations on Sessions and Templates - Watch for changes to sessions and templates - Access core Kubernetes resources (Pods, Services, PVCs, Nodes)
Features: - Session management (create, get, list, update, delete, watch) - Template management (create, get, list, delete, watch) - State transitions (running → hibernated → terminated) - Resource filtering (by user, category, labels) - Cluster resource introspection (nodes, pods, services) - Auto-configuration (in-cluster or kubeconfig)
Custom Resource Definitions:
Sessions (stream.space/v1alpha1)
Represents a user's containerized workspace session
States: running, hibernated, terminated
Includes resource limits, idle timeout, persistence settings
Templates (stream.space/v1alpha1)
Defines application templates (Firefox, VS Code, etc.)
Contains container image, VNC/webapp config, resources
Categorized for catalog organization
Implementation Details: - Uses Kubernetes dynamic client for CRD operations - Auto-detects in-cluster vs local configuration - Parses unstructured data to typed Go structs - Supports namespace isolation (default: "streamspace") - Thread-safe client operations
Thread Safety: - Kubernetes clients are thread-safe - Safe for concurrent access across goroutines
Dependencies: - k8s.io/client-go for Kubernetes API access - k8s.io/api for core resource types
Example Usage:
// Initialize client
client, err := k8s.NewClient()
if err != nil {
log.Fatal(err)
}
// Create a session
session := &k8s.Session{
Name: "user1-firefox",
Namespace: "streamspace",
User: "user1",
Template: "firefox-browser",
State: "running",
PersistentHome: true,
IdleTimeout: "30m",
}
created, err := client.CreateSession(ctx, session)
// List sessions for a user
sessions, err := client.ListSessionsByUser(ctx, "streamspace", "user1")
// Update session state (hibernate)
updated, err := client.UpdateSessionState(ctx, "streamspace", "user1-firefox", "hibernated")
// Watch for session changes
watcher, err := client.WatchSessions(ctx, "streamspace")
for event := range watcher.ResultChan() {
session := event.Object.(*unstructured.Unstructured)
// Handle session change
}
Index ¶
- type ApplicationInstall
- type Client
- func (c *Client) CordonNode(ctx context.Context, name string) error
- func (c *Client) CreateApplicationInstall(ctx context.Context, appInstall *ApplicationInstall) (*ApplicationInstall, error)
- func (c *Client) CreateSession(ctx context.Context, session *Session) (*Session, error)
- func (c *Client) CreateTemplate(ctx context.Context, template *Template) (*Template, error)
- func (c *Client) DeleteApplicationInstall(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteSession(ctx context.Context, namespace, name string) error
- func (c *Client) DeleteTemplate(ctx context.Context, namespace, name string) error
- func (c *Client) DrainNode(ctx context.Context, name string, gracePeriodSeconds *int64) error
- func (c *Client) GetApplicationInstall(ctx context.Context, namespace, name string) (*ApplicationInstall, error)
- func (c *Client) GetClientset() *kubernetes.Clientset
- func (c *Client) GetDynamicClient() dynamic.Interface
- func (c *Client) GetNamespaces(ctx context.Context) (*corev1.NamespaceList, error)
- func (c *Client) GetNode(ctx context.Context, name string) (*corev1.Node, error)
- func (c *Client) GetNodes(ctx context.Context) (*corev1.NodeList, error)
- func (c *Client) GetPVCs(ctx context.Context, namespace string) (*corev1.PersistentVolumeClaimList, error)
- func (c *Client) GetPods(ctx context.Context, namespace string) (*corev1.PodList, error)
- func (c *Client) GetServices(ctx context.Context, namespace string) (*corev1.ServiceList, error)
- func (c *Client) GetSession(ctx context.Context, namespace, name string) (*Session, error)
- func (c *Client) GetTemplate(ctx context.Context, namespace, name string) (*Template, error)
- func (c *Client) ListApplicationInstalls(ctx context.Context, namespace string) ([]*ApplicationInstall, error)
- func (c *Client) ListSessions(ctx context.Context, namespace string) ([]*Session, error)
- func (c *Client) ListSessionsByUser(ctx context.Context, namespace, user string) ([]*Session, error)
- func (c *Client) ListTemplates(ctx context.Context, namespace string) ([]*Template, error)
- func (c *Client) ListTemplatesByCategory(ctx context.Context, namespace, category string) ([]*Template, error)
- func (c *Client) PatchNode(ctx context.Context, name string, patchData []byte) error
- func (c *Client) UncordonNode(ctx context.Context, name string) error
- func (c *Client) UpdateApplicationInstallStatus(ctx context.Context, namespace, name string, phase, message string) error
- func (c *Client) UpdateNodeTaints(ctx context.Context, name string, taints []corev1.Taint) error
- func (c *Client) UpdateSession(ctx context.Context, session *Session) error
- func (c *Client) UpdateSessionState(ctx context.Context, namespace, name, state string) (*Session, error)
- func (c *Client) UpdateSessionStatus(ctx context.Context, session *Session) error
- func (c *Client) WatchApplicationInstalls(ctx context.Context, namespace string) (watch.Interface, error)
- func (c *Client) WatchSessions(ctx context.Context, namespace string) (watch.Interface, error)
- func (c *Client) WatchTemplates(ctx context.Context, namespace string) (watch.Interface, error)
- type Session
- type SessionStatus
- type Template
- type VNCConfig
- type WebAppConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplicationInstall ¶
type ApplicationInstall struct {
Name string
Namespace string
CatalogTemplateID int
TemplateName string
DisplayName string
Description string
Category string
Icon string
Manifest string // YAML manifest for the Template
InstalledBy string
// Status fields
Phase string // Pending, Creating, Ready, Failed
StatusMessage string
LastTransitionTime *time.Time
CreatedTemplateName string
CreatedTemplateNS string
}
ApplicationInstall represents a request to install an application The controller watches these and creates the corresponding Template CRD
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps Kubernetes clients for StreamSpace CRD operations
func (*Client) CordonNode ¶
CordonNode marks a node as unschedulable
func (*Client) CreateApplicationInstall ¶
func (c *Client) CreateApplicationInstall(ctx context.Context, appInstall *ApplicationInstall) (*ApplicationInstall, error)
CreateApplicationInstall creates a new ApplicationInstall resource The controller will watch this and create the corresponding Template CRD
func (*Client) CreateSession ¶
CreateSession creates a new Session resource
func (*Client) CreateTemplate ¶
CreateTemplate creates a new Template resource
func (*Client) DeleteApplicationInstall ¶
DeleteApplicationInstall deletes an ApplicationInstall
func (*Client) DeleteSession ¶
DeleteSession deletes a Session
func (*Client) DeleteTemplate ¶
DeleteTemplate deletes a Template
func (*Client) GetApplicationInstall ¶
func (c *Client) GetApplicationInstall(ctx context.Context, namespace, name string) (*ApplicationInstall, error)
GetApplicationInstall retrieves an ApplicationInstall by name
func (*Client) GetClientset ¶
func (c *Client) GetClientset() *kubernetes.Clientset
GetClientset returns the underlying Kubernetes clientset
func (*Client) GetDynamicClient ¶
GetDynamicClient returns the underlying dynamic client
func (*Client) GetNamespaces ¶
GetNamespaces returns all namespaces
func (*Client) GetPVCs ¶
func (c *Client) GetPVCs(ctx context.Context, namespace string) (*corev1.PersistentVolumeClaimList, error)
GetPVCs returns PVCs in a namespace
func (*Client) GetServices ¶
GetServices returns services in a namespace
func (*Client) GetSession ¶
GetSession retrieves a Session by name
func (*Client) GetTemplate ¶
GetTemplate retrieves a Template by name
func (*Client) ListApplicationInstalls ¶
func (c *Client) ListApplicationInstalls(ctx context.Context, namespace string) ([]*ApplicationInstall, error)
ListApplicationInstalls lists all ApplicationInstalls in a namespace
func (*Client) ListSessions ¶
ListSessions lists all Sessions in a namespace
func (*Client) ListSessionsByUser ¶
func (c *Client) ListSessionsByUser(ctx context.Context, namespace, user string) ([]*Session, error)
ListSessionsByUser lists Sessions for a specific user
func (*Client) ListTemplates ¶
ListTemplates lists all Templates in a namespace
func (*Client) ListTemplatesByCategory ¶
func (c *Client) ListTemplatesByCategory(ctx context.Context, namespace, category string) ([]*Template, error)
ListTemplatesByCategory lists Templates by category
func (*Client) UncordonNode ¶
UncordonNode marks a node as schedulable
func (*Client) UpdateApplicationInstallStatus ¶
func (c *Client) UpdateApplicationInstallStatus(ctx context.Context, namespace, name string, phase, message string) error
UpdateApplicationInstallStatus updates the status of an ApplicationInstall
func (*Client) UpdateNodeTaints ¶
UpdateNodeTaints updates the taints on a node
func (*Client) UpdateSession ¶
UpdateSession updates a Session resource
func (*Client) UpdateSessionState ¶
func (c *Client) UpdateSessionState(ctx context.Context, namespace, name, state string) (*Session, error)
UpdateSessionState updates the state of a Session (running, hibernated, terminated)
func (*Client) UpdateSessionStatus ¶
UpdateSessionStatus updates a Session's status subresource
func (*Client) WatchApplicationInstalls ¶
func (c *Client) WatchApplicationInstalls(ctx context.Context, namespace string) (watch.Interface, error)
WatchApplicationInstalls watches for ApplicationInstall changes
func (*Client) WatchSessions ¶
WatchSessions watches for Session changes
type Session ¶
type Session struct {
Name string
Namespace string
User string
Template string
State string // running, hibernated, terminated
Resources struct {
Memory string
CPU string
}
PersistentHome bool
IdleTimeout string
MaxSessionDuration string
Tags []string
Status SessionStatus
CreatedAt time.Time
}
Session represents a StreamSpace Session CRD
type SessionStatus ¶
type SessionStatus struct {
Phase string // Pending, Running, Hibernated, Failed, Terminated
PodName string
URL string
LastActivity *time.Time
ResourceUsage struct {
Memory string
CPU string
}
Conditions []metav1.Condition
}
SessionStatus represents the status of a Session
type Template ¶
type Template struct {
Name string
Namespace string
DisplayName string
Description string
Category string
Icon string
BaseImage string
AppType string // desktop, webapp
DefaultResources struct {
Memory string
CPU string
}
Ports []struct {
Name string
ContainerPort int32
Protocol string
}
Env []corev1.EnvVar
VolumeMounts []corev1.VolumeMount
VNC *VNCConfig
WebApp *WebAppConfig
Capabilities []string
Tags []string
Featured bool // Whether template is featured in catalog
UsageCount int // Number of times template has been used
CreatedAt time.Time
}
Template represents a StreamSpace Template CRD
type WebAppConfig ¶
WebAppConfig represents webapp configuration for native web apps