Skip to content

Workspace

The Workspace resource represents a Kubernetes environment that can be managed, hibernated, and forked by the forkspacer operator. It provides capabilities for environment lifecycle management, including automatic hibernation scheduling and connection configuration.

  • API Group: batch.forkspacer.com
  • API Version: v1
  • Kind: Workspace
  • Short Name: ws
apiVersion: batch.forkspacer.com/v1
kind: Workspace
metadata:
name: dev-environment
namespace: default
spec:
type: kubernetes
hibernated: false
connection:
type: local

The .spec field defines the desired state of the Workspace.

FieldTypeDescriptionRequired
typestringType of workspace. Currently only supports kubernetes.No (default: kubernetes)
fromobjectReference to another workspace to fork from. See FromReference.No
hibernatedbooleanWhether the workspace should be in hibernated state.No (default: false)
connectionobjectConfiguration for connecting to the workspace. See Connection.No
autoHibernationobjectConfiguration for automatic hibernation scheduling. See AutoHibernation.No

The from field allows you to create a workspace by forking from an existing workspace. Forking creates a new workspace with copies of all modules from the source workspace. Optionally, you can migrate persistent data from the source workspace to the new workspace.

FieldTypeDescriptionRequired
namestringName of the source workspace to fork from.Yes
namespacestringNamespace of the source workspace.Yes (default: default)
migrateDatabooleanWhether to migrate persistent data (PVCs, Secrets, ConfigMaps) from source workspace modules to the new workspace.No (default: false)

Note: Data migration is not 100% guaranteed and depends on factors such as storage class compatibility, cluster connectivity, and resource accessibility.

Example - Simple Forking:

spec:
from:
name: production-workspace
namespace: prod

Example - Forking with Data Migration:

spec:
from:
name: production-workspace
namespace: prod
migrateData: true

The connection field configures how the operator connects to the workspace.

FieldTypeDescriptionRequired
typestringConnection type. Options: local, in-cluster, kubeconfig.Yes (default: local)
secretReferenceobjectReference to a secret containing connection credentials. See SecretReference.No

Example:

spec:
connection:
type: kubeconfig
secretReference:
name: workspace-kubeconfig
namespace: default

The secretReference field within connection specifies a Kubernetes Secret containing connection credentials.

FieldTypeDescriptionRequired
namestringName of the secret.Yes
namespacestringNamespace of the secret.No (default: default)

The autoHibernation field enables automatic hibernation and wake scheduling based on cron expressions.

FieldTypeDescriptionRequired
enabledbooleanWhether auto-hibernation is enabled.No (default: false)
schedulestringCron expression for hibernation schedule. Supports standard 5-field format or 6-field format with optional seconds.Yes (when enabled)
wakeSchedulestringCron expression for wake schedule. Supports standard 5-field format or 6-field format with optional seconds.No

Cron Format:

The cron expressions support two formats:

  • 5-field format: minute hour day month weekday (e.g., 0 22 * * *)
  • 6-field format: second minute hour day month weekday (e.g., 0 0 22 * * *)

Example:

spec:
autoHibernation:
enabled: true
schedule: "0 22 * * *" # 5-field: Hibernate at 10 PM daily
wakeSchedule: "0 0 6 * * *" # 6-field: Wake at 6 AM daily (with seconds)

The .status field reflects the observed state of the Workspace.

FieldTypeDescriptionRequired
phasestringCurrent phase of the workspace. Values: ready, hibernated, failed, terminating.Yes
readybooleanIndicates if the workspace is fully operational.No (default: false)
lastActivitystring (date-time)Timestamp of the last activity in the workspace.No
hibernatedAtstring (date-time)Timestamp when the workspace was hibernated.No
messagestringHuman-readable message about the current state.No
conditionsarrayStandard Kubernetes conditions. See Conditions.No

Standard Kubernetes condition types used to represent the workspace state:

  • Available: The workspace is fully functional and ready for use.
  • Progressing: The workspace is being created, updated, or transitioning between states.
  • Degraded: The workspace failed to reach or maintain its desired state.

Each condition has the following fields:

FieldTypeDescription
typestringCondition type (e.g., “Available”, “Progressing”, “Degraded”).
statusstringCondition status: True, False, or Unknown.
lastTransitionTimestring (date-time)Last time the condition transitioned.
reasonstringProgrammatic identifier for the condition’s last transition.
messagestringHuman-readable message explaining the condition.
observedGenerationintegerThe .metadata.generation that the condition was set based upon.

The status.phase field can have the following values:

  • ready: Workspace is operational and available for use.
  • hibernated: Workspace is in hibernated state with resources scaled down.
  • failed: Workspace encountered an error and is not operational.
  • terminating: Workspace is being deleted.
apiVersion: batch.forkspacer.com/v1
kind: Workspace
metadata:
name: my-workspace
spec:
type: kubernetes

Creating a Workspace with Auto-Hibernation

Section titled “Creating a Workspace with Auto-Hibernation”
apiVersion: batch.forkspacer.com/v1
kind: Workspace
metadata:
name: cost-optimized-workspace
spec:
autoHibernation:
enabled: true
schedule: "0 18 * * 1-5" # Hibernate on weekday evenings
wakeSchedule: "0 8 * * 1-5" # Wake on weekday mornings

Create a copy of an existing workspace without data migration:

apiVersion: batch.forkspacer.com/v1
kind: Workspace
metadata:
name: testing-workspace
spec:
from:
name: production-workspace
namespace: prod

Create a copy of an existing workspace and migrate persistent data (PVCs, Secrets, ConfigMaps) from the source workspace:

apiVersion: batch.forkspacer.com/v1
kind: Workspace
metadata:
name: testing-workspace-with-data
spec:
from:
name: production-workspace
namespace: prod
migrateData: true

⚠️ Important Considerations for Data Migration:

  • Temporary Downtime: The migration process will temporarily hibernate both source and destination modules during data transfer to ensure data consistency
  • Migration Requirements: Helm modules in the source workspace must have migration configuration defined in their resource definitions (e.g., migration.pvc, migration.secret, migration.configMap)
  • Not 100% Guaranteed: Migration may fail due to storage class incompatibilities, cluster connectivity issues, or resource accessibility problems
  • Selective Migration: Only Helm modules with migration enabled for specific resource types will have their data migrated
  • Source Preservation: The source workspace and its data remain unchanged after migration (original hibernation state is restored)
  • Immutable Resources: If a Secret or ConfigMap is marked as immutable in the destination, it will be deleted and recreated while preserving its labels and annotations
apiVersion: batch.forkspacer.com/v1
kind: Workspace
metadata:
name: my-workspace
spec:
hibernated: true
  • Module - Modules are deployed into Workspaces
  • Overview - CRD overview and architecture