Volume Management Specification
Overview
This specification defines the volume management system for k8s-cli. The system provides persistent storage capabilities through Kubernetes PersistentVolumeClaims (PVCs), allowing tasks to maintain state across executions.
Requirements
Core Functionality
Volume Creation
- The system MUST support creating volumes with a specified name and size
- The system MUST generate a unique volume ID for each created volume
- The system MUST create a Kubernetes PersistentVolumeClaim (PVC) for each volume
- The system MAY support specifying a storage class via the
storage_classfield - The system MUST support specifying access modes via the
access_modesfield - The system MUST default to
ReadWriteOnceaccess mode if not specified - The system MUST label all PVCs with
skypilot-volume: true
Volume Metadata
- The system MUST store
volume-idlabel on the PVC for identification - The system MUST store
volume-namelabel on the PVC for user-friendly names - The system MUST store
usernamelabel on the PVC for user isolation - The system MUST store
created-atannotation on the PVC with ISO timestamp
Volume Status Tracking
- The system MUST track the status of each volume (Pending, Bound, Lost)
- The system MUST report volume size, storage class, and access modes
- The system MUST provide creation timestamp for each volume
- The system MUST return metadata including PVC name and namespace
Volume Deletion
- The system MUST support deleting a volume by volume ID
- The system MUST delete the associated Kubernetes PVC
- The system MUST prevent users from deleting volumes owned by other users
- The system SHOULD provide a confirmation prompt before deletion (CLI)
Volume Listing
- The system MUST support listing all volumes for the current user
- The system MAY support listing volumes for all users (admin operation)
- The system MUST return volume status, size, and metadata for each volume
Volume Resolution
- The system MUST support resolving user-friendly volume names to PVC names
- The system MUST look up PVCs by
volume-nameandusernamelabels first - The system MUST fall back to using the volume name as the PVC name directly
- The system MUST use resolved PVC names when mounting volumes in tasks
CLI Interface
- The system MUST provide a
volumes createcommand to create volumes - The system MUST provide a
volumes listcommand to list volumes - The system MUST provide a
volumes deletecommand to delete volumes - The system SHOULD support the
--storage-classflag to specify storage class - The system SHOULD support the
--access-modesflag to specify access modes - The system SHOULD support the
--detailsflag to show extended information - The system SHOULD support the
--all-usersflag to list volumes from all users - The system SHOULD support the
--forceflag to skip deletion confirmation
REST API Interface
- The system MUST provide a
POST /volumes/createendpoint to create volumes - The system MUST provide a
GET /volumesendpoint to list volumes - The system MUST provide a
DELETE /volumes/{volume_id}endpoint to delete volumes - The system MUST provide a
GET /volumes/{volume_id}endpoint to get volume status - The system MUST require an
X-Userheader for user identification - The system MUST support an
all_usersquery parameter for privileged operations
User Isolation
- The system MUST isolate volumes by username using Kubernetes labels
- The system MUST sanitize usernames for use in Kubernetes labels (replace
@with-) - The system MUST prevent users from accessing volumes owned by other users
- The system MAY allow privileged operations to list volumes across all users
Error Handling
- The system MUST return appropriate HTTP status codes for API errors
- The system MUST return 404 if a volume ID is not found for the user
- The system MUST provide descriptive error messages for failed operations
- The system MUST validate volume size format (e.g., "10Gi", "1Ti")
Kubernetes Integration
- The system MUST label all PVCs with
skypilot-volume: true - The system MUST use the
defaultnamespace for all PVCs - The system MUST respect the specified storage class when creating PVCs
- The system MUST respect the specified access modes when creating PVCs
Data Models
VolumeDefinition
name(required): User-friendly volume namesize(required): Volume size in Kubernetes format (e.g., "10Gi", "1Ti")storage_class(optional): Kubernetes storage class nameaccess_modes(optional): List of access modes (default:["ReadWriteOnce"])
VolumeStatus
volume_id: Unique volume identifiername: User-friendly volume namesize: Volume sizestorage_class: Storage class nameaccess_modes: List of access modesstatus: PVC phase (Pending, Bound, Lost)created_at: ISO timestamp of volume creationusername: User who created the volumemetadata: Additional information including PVC name and namespace
Implementation Notes
- Volume IDs are 8-character UUID prefixes
- PVC names follow the pattern
{volume-name}-{volume-id} - Username sanitization replaces
@with-for DNS-1123 compliance - Volume resolution is performed when tasks reference volumes by name
- Access modes are specified as a list to support multi-mode configurations