* [memory-bank] Tell cline how to build components Tool: gitpod/catfood.gitpod.cloud * [memory-bank] Document API components as well Tool: gitpod/catfood.gitpod.cloud * [memory-bank] Document content-service-api, ide-metrics-api, ide-service-api Tool: gitpod/catfood.gitpod.cloud * [memory-bank] Document image-builder-api, local-app-api, registry-facade-api Tool: gitpod/catfood.gitpod.cloud * [memory-bank] Document supervisor-api, usage-api, ws-daemon-api Tool: gitpod/catfood.gitpod.cloud * [memory-bank] Document ws-manager-api, ws-manager-bridge-api Tool: gitpod/catfood.gitpod.cloud
6.4 KiB
Workspace Manager API
Overview
The Workspace Manager API defines the gRPC interfaces for the Workspace Manager service, which is responsible for managing the lifecycle of workspaces within the Gitpod platform. This API enables the creation, monitoring, and control of workspaces running in Kubernetes clusters.
Purpose
This API provides a standardized interface for:
- Starting and stopping workspaces
- Monitoring workspace status
- Managing workspace timeouts and activity
- Controlling port exposure and admission settings
- Creating snapshots and backups of workspaces
- Retrieving information about available workspace classes
Architecture
The Workspace Manager API is implemented as a gRPC service defined in Protocol Buffer files. These definitions are used to generate client and server code in Go and TypeScript for use by the workspace manager and other components in the system.
Key Services
WorkspaceManager
Provides methods for managing workspaces:
GetWorkspaces: Retrieves a list of running workspaces and their statusStartWorkspace: Creates a new running workspace within the manager's clusterStopWorkspace: Stops a running workspaceDescribeWorkspace: Investigates a workspace and returns its status and configurationBackupWorkspace: Backs up a running workspaceSubscribe: Streams all status updates to a clientMarkActive: Records a workspace as being active, preventing it from timing outSetTimeout: Changes the default timeout for a running workspaceControlPort: Publicly exposes or un-exposes a network port for a workspaceTakeSnapshot: Creates a copy of the workspace content for initializing a new workspaceControlAdmission: Makes a workspace accessible for everyone or for the owner onlyDeleteVolumeSnapshot: Deletes a specific volume snapshotUpdateSSHKey: Updates SSH keys for a workspaceDescribeCluster: Provides information about the cluster
Key Data Structures
WorkspaceStatus
Represents the current status of a workspace:
- ID and metadata
- Specification
- Phase (e.g., PENDING, CREATING, INITIALIZING, RUNNING)
- Conditions (detailed state information)
- Runtime information
- Authentication settings
- Initializer metrics
WorkspacePhase
Enum defining the high-level state of a workspace:
UNKNOWN: Cannot determine the actual phasePENDING: Workspace is waiting for resources in the clusterCREATING: Workspace is being created (downloading images)INITIALIZING: Workspace is executing the initializerRUNNING: Workspace is actively performing workINTERRUPTED: Workspace is temporarily unavailableSTOPPING: Workspace is shutting downSTOPPED: Workspace has ended regularly
WorkspaceSpec
Defines the runtime configuration of a workspace:
- Workspace image
- IDE image and layers
- Exposed ports
- Timeout settings
- Workspace class
StartWorkspaceSpec
Defines the configuration for starting a workspace:
- Workspace image
- IDE image and layers
- Feature flags
- Initializer configuration
- Ports to expose
- Environment variables
- Git configuration
- Timeout settings
- Admission level
- SSH public keys
PortSpec
Describes a networking port exposed on a workspace:
- Port number
- Visibility (private or public)
- URL
- Protocol (HTTP or HTTPS)
WorkspaceClass
Describes a workspace class supported by the cluster:
- ID
- Display name
- Description
- Credits per minute
Communication Patterns
- The API uses gRPC for efficient, typed communication
- The
Subscribemethod uses server-side streaming to provide real-time updates - Requests include workspace IDs to identify the relevant workspace
- Filtering can be applied using metadata to target specific workspaces
Dependencies
- Depends on the Content Service API for workspace initialization
- Used by the server component for workspace management
- Used by the ws-manager-bridge to communicate with workspace managers
- Integrated with Kubernetes for cluster management
Usage Examples
- Workspace creation process uses this API to start new workspaces
- Monitoring systems use this API to track workspace status
- Billing systems use this API to track workspace activity
- Administrative tools use this API to manage workspaces
Version Compatibility
The API uses Protocol Buffers version 3 (proto3) syntax, which provides forward and backward compatibility features. The service is designed to allow for the addition of new workspace management features without breaking existing clients.
Code Generation and Building
Regenerating Code from Protobuf Definitions
The Workspace Manager API uses Protocol Buffers and gRPC for defining interfaces. When changes are made to the .proto files, the corresponding code in Go and TypeScript needs to be regenerated.
To regenerate the code:
-
Navigate to the ws-manager-api directory:
cd components/ws-manager-api -
Run the generate script:
./generate.sh
This script performs the following actions:
- Installs necessary dependencies (protoc plugins)
- Generates Go code using
protoc-gen-goandprotoc-gen-go-grpc - Generates TypeScript code
- Generates mock implementations for testing
- Patches the generated TypeScript code for compatibility
- Updates license headers
Implementation Details
The generate.sh script uses functions from the shared script at scripts/protoc-generator.sh:
install_dependencies: Installs required protoc pluginsgo_protoc: Generates Go codetypescript_protoc: Generates TypeScript codeupdate_license: Updates license headers in generated files
Additionally, the script:
- Generates mock implementations using
mockgenfor testing - Patches the generated TypeScript code using a script from the content-service-api
Building After Code Generation
After regenerating the code, you may need to rebuild components that depend on the Workspace Manager API. This typically involves:
-
For Go components:
cd <component-directory> go build ./... -
For TypeScript components:
cd <component-directory> yarn install yarn build -
Using Leeway (for CI/CD):
leeway build -D components/<component-name>:app
The Workspace Manager API is primarily used by the ws-manager-mk2 component, which is a Kubernetes controller for managing workspace lifecycle. It plays a critical role in the platform by enabling the creation, monitoring, and control of workspaces running in Kubernetes clusters.