memory-bank/components/ws-daemon-api.md
The Workspace Daemon API defines the gRPC interfaces for the Workspace Daemon service, which is responsible for managing workspace content, filesystem operations, and low-level container operations within the Gitpod platform. This API enables the initialization, backup, and disposal of workspace content, as well as advanced container operations like user namespace setup and network configuration.
This API provides a standardized interface for:
The Workspace Daemon API is implemented as a set of gRPC services defined in Protocol Buffer files. These definitions are used to generate client and server code in Go and TypeScript for use by the workspace daemon and other components in the system.
Provides methods for managing workspace content:
InitWorkspace: Initializes a new workspace folder in the working areaWaitForInit: Waits until a workspace is fully initializedIsWorkspaceExists: Checks if ws-daemon knows about a workspaceTakeSnapshot: Creates a backup/snapshot of a workspaceDisposeWorkspace: Cleans up a workspace, possibly after taking a final backupBackupWorkspace: Creates a backup of a workspaceProvides methods for low-level container operations:
PrepareForUserNS: Prepares a workspace container for wrapping it in a user namespaceWriteIDMapping: Writes a new user/group ID mapping for user namespacesEvacuateCGroup: Empties the workspace pod cgroup and produces a new substructureMountProc: Mounts a masked proc in the container's rootfsUmountProc: Unmounts a masked proc from the container's rootfsMountSysfs: Mounts a masked sysfs in the container's rootfsUmountSysfs: Unmounts a masked sysfs from the container's rootfsMountNfs: Mounts an NFS share into the container's rootfsUmountNfs: Unmounts an NFS share from the container's rootfsTeardown: Prepares workspace content backups and unmounts shiftfs mountsWipingTeardown: Undoes everything PrepareForUserNS doesSetupPairVeths: Sets up a pair of virtual Ethernet interfacesWorkspaceInfo: Gets information about the workspaceProvides methods for retrieving workspace information:
WorkspaceInfo: Gets information about the workspace resourcesContains metadata associated with a workspace:
Enum defining the state of workspace content:
NONE: No workspace content and no work is underwaySETTING_UP: Workspace content is being produced/checked out/unarchivedAVAILABLE: Workspace content is fully present and ready for useWRAPPING_UP: Workspace is being torn downEnum defining the method for establishing ID shift for user namespaced workspaces:
SHIFTFS: Using shiftfs for ID shiftingContains information about workspace resources:
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.
The Workspace Daemon 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-daemon-api directory:
cd components/ws-daemon-api
Run the generate script:
./generate.sh
This script performs the following actions:
protoc-gen-go and protoc-gen-go-grpcAdditionally, the script:
mockgen for testinggomodifytagsAfter regenerating the code, you may need to rebuild components that depend on the Workspace Daemon 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 Daemon API is primarily used by the ws-daemon component, which runs on each Kubernetes node and manages workspace content and container operations. It plays a critical role in the workspace lifecycle by handling content initialization, backup, and disposal, as well as advanced container operations.