k8s

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package k8s provides Kubernetes client wrappers for the kube-workspaces API server. It includes specialized clients for workspaces, images, CRDs, core resources (pods, services, PVCs), and a metrics buffer for caching pod resource usage data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetClientset

func GetClientset() (kubernetes.Interface, error)

GetClientset returns a Kubernetes clientset for use by the exec handler.

func GetRESTConfig

func GetRESTConfig() (*rest.Config, error)

GetRESTConfig returns a Kubernetes REST config for use by the exec handler.

func NewClient

func NewClient() (*kubernetes.Clientset, error)

NewClient creates a Kubernetes clientset (used by volumes and namespaces services).

func NewDynamicClient

func NewDynamicClient() (dynamic.Interface, error)

NewDynamicClient creates a dynamic Kubernetes client for working with CRDs.

Types

type CRDClient

type CRDClient struct {
	// contains filtered or unexported fields
}

CRDClient provides operations on CustomResourceDefinition resources.

func NewCRDClient

func NewCRDClient() (*CRDClient, error)

NewCRDClient creates a new CRDClient using the same config as other clients.

func (*CRDClient) GetCRD

func (c *CRDClient) GetCRD(ctx context.Context, name string) (*unstructured.Unstructured, error)

GetCRD gets a CustomResourceDefinition by name.

func (*CRDClient) ListCRDInstances

func (c *CRDClient) ListCRDInstances(ctx context.Context, group, version, resource, namespace string) (*unstructured.UnstructuredList, error)

ListCRDInstances lists all instances of a CRD identified by group/version/resource. For namespaced CRDs, pass namespace; for cluster-scoped, pass "".

func (*CRDClient) ListCRDs

ListCRDs lists all CustomResourceDefinitions in the cluster.

func (*CRDClient) ListCRDsByGroup

func (c *CRDClient) ListCRDsByGroup(ctx context.Context, group string) (*unstructured.UnstructuredList, error)

ListCRDsByGroup lists CustomResourceDefinitions filtered by spec.group.

type CoreClient

type CoreClient struct {
	// contains filtered or unexported fields
}

CoreClient provides operations on core Kubernetes resources (pods, events).

func NewCoreClient

func NewCoreClient() (*CoreClient, error)

NewCoreClient creates a new CoreClient using in-cluster config or kubeconfig.

func (*CoreClient) AnnotateNamespace

func (c *CoreClient) AnnotateNamespace(ctx context.Context, name, key, value string) error

AnnotateNamespace sets or removes an annotation on a namespace. If value is empty, the annotation is removed.

func (*CoreClient) CreateWorkspaceEvent

func (c *CoreClient) CreateWorkspaceEvent(ctx context.Context, namespace, workspaceName, action, actor, message string) error

CreateWorkspaceEvent creates a Kubernetes Event associated with a Workspace CR.

func (*CoreClient) GetPod

func (c *CoreClient) GetPod(ctx context.Context, namespace, name string) (*corev1.Pod, error)

GetPod returns a pod by name and namespace.

func (*CoreClient) GetPodLogs

func (c *CoreClient) GetPodLogs(ctx context.Context, namespace, name, container string, tailLines int64) (string, error)

GetPodLogs returns the logs of a pod's container as a string.

func (*CoreClient) GetStatefulSet

func (c *CoreClient) GetStatefulSet(ctx context.Context, namespace, name string) (interface{}, error)

GetStatefulSet returns a StatefulSet by name and namespace.

func (*CoreClient) ListEvents

func (c *CoreClient) ListEvents(ctx context.Context, namespace, fieldSelector string) (*corev1.EventList, error)

ListEvents returns events for a specific object (by field selector).

func (*CoreClient) ListNamespaceEvents

func (c *CoreClient) ListNamespaceEvents(ctx context.Context, namespace string) (*corev1.EventList, error)

ListNamespaceEvents returns all events in a namespace, optionally filtered.

func (*CoreClient) ListNamespaces

func (c *CoreClient) ListNamespaces(ctx context.Context) (*corev1.NamespaceList, error)

ListNamespaces returns all namespaces in the cluster.

func (*CoreClient) ListPods

func (c *CoreClient) ListPods(ctx context.Context, namespace, labelSelector string) (*corev1.PodList, error)

ListPods returns pods matching label selector in a namespace.

func (*CoreClient) ListWorkspaceEvents

func (c *CoreClient) ListWorkspaceEvents(ctx context.Context, namespace, workspaceName string) (*corev1.EventList, error)

ListWorkspaceEvents returns events related to a specific workspace.

type Image

type Image struct {
	Name                  string
	DisplayName           string
	Description           string
	Category              string
	Tags                  []string
	Image                 string
	DefaultPort           int32
	DefaultPath           string
	Icon                  string
	DefaultArgs           []string
	DefaultEnv            []ImageEnvVar
	DefaultCredentials    *ImageCredentials
	Privileged            bool
	HomepageURL           string
	SourceURL             string
	ImageHomepageURL      string
	DefaultUser           string
	DefaultHomedir        string
	DefaultShell          string
	Links                 []ImageLink
	ProxyConfig           *ImageProxyConfig
	DefaultUID            *int64
	DefaultSharedMemory   bool
	DefaultInitContainers []ImageInitContainer
	AdditionalPorts       []ImagePort
}

Image represents a parsed Image CR.

type ImageClient

type ImageClient struct {
	// contains filtered or unexported fields
}

ImageClient provides operations on Image custom resources.

func NewImageClient

func NewImageClient() (*ImageClient, error)

NewImageClient creates a new ImageClient.

func (*ImageClient) CreateImage

func (c *ImageClient) CreateImage(ctx context.Context, name string, spec map[string]interface{}) (*unstructured.Unstructured, error)

CreateImage creates a new Image CR.

func (*ImageClient) DeleteImage

func (c *ImageClient) DeleteImage(ctx context.Context, name string) error

DeleteImage deletes an Image CR.

func (*ImageClient) GetImage

func (c *ImageClient) GetImage(ctx context.Context, name string) (*Image, error)

GetImage gets an Image CR by name.

func (*ImageClient) GetImageByRef

func (c *ImageClient) GetImageByRef(ctx context.Context, imageRef string) (*Image, error)

GetImageByRef finds an Image CR whose spec.image matches the given reference.

func (*ImageClient) GetImageRaw

func (c *ImageClient) GetImageRaw(ctx context.Context, name string) (*unstructured.Unstructured, error)

GetImageRaw returns the raw unstructured Image CR object.

func (*ImageClient) ListImages

func (c *ImageClient) ListImages(ctx context.Context) ([]Image, error)

ListImages lists all Image CRs (cluster-scoped).

func (*ImageClient) UpdateImage

func (c *ImageClient) UpdateImage(ctx context.Context, name string, spec map[string]interface{}) (*unstructured.Unstructured, error)

UpdateImage updates an existing Image CR.

type ImageCredentials

type ImageCredentials struct {
	Username string
	Password string
}

ImageCredentials represents default login credentials for a workspace image.

type ImageEnvVar

type ImageEnvVar struct {
	Name  string
	Value string
}

ImageEnvVar is an environment variable with optional placeholder support.

type ImageInitContainer

type ImageInitContainer struct {
	Name         string
	Image        string
	Command      []string
	Args         []string
	Env          []ImageEnvVar
	VolumeMounts []ImageVolumeMount
}

ImageInitContainer represents a simplified init container spec for Image CR defaults.

type ImageLink struct {
	Title string
	URL   string
}

ImageLink represents a named URL link for an image.

type ImagePort

type ImagePort struct {
	Name     string
	Port     int32
	Protocol string
}

ImagePort represents an additional container port to expose.

type ImageProxyConfig

type ImageProxyConfig struct {
	NeedsNoOpSW              bool
	WebSocketPaths           []string
	RewriteHostAbsolutePaths bool
	CustomRequestHeaders     map[string]string
	InjectBaseTag            bool
	TLSInsecure              bool
	PreservePathPrefix       bool
	AudioPort                int32
}

ImageProxyConfig describes proxy behavior for an image.

type ImageVolumeMount

type ImageVolumeMount struct {
	Name      string
	MountPath string
}

ImageVolumeMount represents a volume mount for an init container.

type MetricPoint

type MetricPoint struct {
	Timestamp     time.Time `json:"timestamp"`
	CPUMillicores int64     `json:"cpu_mc"`
	MemoryBytes   int64     `json:"memory_bytes"`
}

type MetricsBuffer

type MetricsBuffer struct {
	// contains filtered or unexported fields
}

func NewMetricsBuffer

func NewMetricsBuffer(client *MetricsClient, interval, maxAge time.Duration) *MetricsBuffer

func (*MetricsBuffer) Client

func (b *MetricsBuffer) Client() *MetricsClient

func (*MetricsBuffer) EnsurePod

func (b *MetricsBuffer) EnsurePod(ctx context.Context, namespace, name string, container string)

func (*MetricsBuffer) GetMetrics

func (b *MetricsBuffer) GetMetrics(namespace, name string, window time.Duration) ([]MetricPoint, string)

func (*MetricsBuffer) Run

func (b *MetricsBuffer) Run(ctx context.Context)

func (*MetricsBuffer) Stop

func (b *MetricsBuffer) Stop()

type MetricsClient

type MetricsClient struct {
	// contains filtered or unexported fields
}

func NewMetricsClient

func NewMetricsClient() (*MetricsClient, error)

func (*MetricsClient) GetPodMetrics

func (c *MetricsClient) GetPodMetrics(ctx context.Context, namespace, name string) (*metricsv1beta1.PodMetrics, error)

func (*MetricsClient) GetPodMetricsSnapshot

func (c *MetricsClient) GetPodMetricsSnapshot(ctx context.Context, namespace, name string) (*MetricsSnapshot, error)

func (*MetricsClient) IsAvailable

func (c *MetricsClient) IsAvailable(ctx context.Context) bool

type MetricsSnapshot

type MetricsSnapshot struct {
	CPUMillicores int64
	MemoryBytes   int64
}

type PodDefault

type PodDefault struct {
	Name               string
	Namespace          string
	Desc               string
	Selector           *metav1.LabelSelector
	Env                []PodDefaultEnvVar
	VolumeMounts       []PodDefaultVolumeMount
	Volumes            []map[string]interface{}
	ServiceAccountName string
	Annotations        map[string]string
	Labels             map[string]string
}

PodDefault represents a parsed PodDefault CR.

type PodDefaultClient

type PodDefaultClient struct {
	// contains filtered or unexported fields
}

PodDefaultClient provides operations on PodDefault custom resources.

func NewPodDefaultClient

func NewPodDefaultClient() (*PodDefaultClient, error)

NewPodDefaultClient creates a new PodDefaultClient.

func (*PodDefaultClient) GetMatchingPodDefaults

func (c *PodDefaultClient) GetMatchingPodDefaults(ctx context.Context, namespace string, workspaceLabels map[string]string) ([]PodDefault, error)

GetMatchingPodDefaults returns PodDefaults in the given namespace whose selector matches the provided workspace labels. PodDefaults with no selector match all workspaces.

func (*PodDefaultClient) ListPodDefaults

func (c *PodDefaultClient) ListPodDefaults(ctx context.Context, namespace string) ([]PodDefault, error)

ListPodDefaults lists all PodDefault CRs in a namespace.

type PodDefaultEnvVar

type PodDefaultEnvVar struct {
	Name  string
	Value string
}

PodDefaultEnvVar is an environment variable to inject.

type PodDefaultVolumeMount

type PodDefaultVolumeMount struct {
	Name      string
	MountPath string
	ReadOnly  bool
}

PodDefaultVolumeMount is a volume mount to inject.

type WorkspaceClient

type WorkspaceClient struct {
	// contains filtered or unexported fields
}

WorkspaceClient provides operations on Workspace custom resources.

func NewWorkspaceClient

func NewWorkspaceClient() (*WorkspaceClient, error)

NewWorkspaceClient creates a new WorkspaceClient.

func (*WorkspaceClient) CreateWorkspace

func (c *WorkspaceClient) CreateWorkspace(ctx context.Context, workspace *unstructured.Unstructured) (*unstructured.Unstructured, error)

CreateWorkspace creates a new workspace CR.

func (*WorkspaceClient) DeleteWorkspace

func (c *WorkspaceClient) DeleteWorkspace(ctx context.Context, namespace, name string) error

DeleteWorkspace deletes a workspace CR.

func (*WorkspaceClient) GetWorkspace

func (c *WorkspaceClient) GetWorkspace(ctx context.Context, namespace, name string) (*unstructured.Unstructured, error)

GetWorkspace gets a workspace CR by name.

func (*WorkspaceClient) ListWorkspaces

func (c *WorkspaceClient) ListWorkspaces(ctx context.Context, namespace string) (*unstructured.UnstructuredList, error)

ListWorkspaces lists all workspace CRs in a namespace.

func (*WorkspaceClient) UpdateWorkspace

func (c *WorkspaceClient) UpdateWorkspace(ctx context.Context, workspace *unstructured.Unstructured) (*unstructured.Unstructured, error)

UpdateWorkspace updates an existing workspace CR.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL