From a6fc1b5ad3ff5e9e5a9bf60397e5fa891a56899f Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Sat, 31 Oct 2026 21:28:21 +0000 Subject: [PATCH 01/16] feat: add the Share mode API fields to workspace pools, claims, and members (#153 PR 14) CoderControlPlane spec.workspacePools.owners[].shareGroupIDs turns on Share mode for an owner. CoderWorkspacePool claims.mode accepts Share. CoderWorkspaceClaim gets spec.share.user and status.sharedUserID, and CoderWorkspacePoolMember gets status.sharedUserID and the Shared condition. Generated deepcopy, CRDs, install bundle, and API reference. Change-Id: I946f8f3d0e916d3baa5819e8b4c8ae54712964fb Signed-off-by: Thomas Kosiewski --- api/v1alpha1/coderworkspaceclaim_types.go | 27 ++++++- api/v1alpha1/coderworkspacepool_types.go | 23 +++++- .../coderworkspacepoolmember_types.go | 19 ++++- api/v1alpha1/zz_generated.deepcopy.go | 28 +++++++- .../bases/coder.com_codercontrolplanes.yaml | 16 +++++ .../bases/coder.com_coderworkspaceclaims.yaml | 32 +++++++++ .../coder.com_coderworkspacepoolmembers.yaml | 17 ++++- .../bases/coder.com_coderworkspacepools.yaml | 6 +- dist/install.yaml | 71 ++++++++++++++++++- docs/reference/api/codercontrolplane.md | 1 + docs/reference/api/coderworkspaceclaim.md | 12 ++++ docs/reference/api/coderworkspacepool.md | 2 +- .../reference/api/coderworkspacepoolmember.md | 3 +- ...dercontrolplane_workspacepools_api_test.go | 9 ++- .../coderworkspaceclaim_api_test.go | 31 ++++++++ .../controller/coderworkspacepool_api_test.go | 8 ++- .../coderworkspacepoolmember_api_test.go | 9 +++ 17 files changed, 299 insertions(+), 15 deletions(-) diff --git a/api/v1alpha1/coderworkspaceclaim_types.go b/api/v1alpha1/coderworkspaceclaim_types.go index 5139af2b1..8a8201a29 100644 --- a/api/v1alpha1/coderworkspaceclaim_types.go +++ b/api/v1alpha1/coderworkspaceclaim_types.go @@ -14,8 +14,8 @@ const ( // a claim never binds again. CoderWorkspaceClaimPhaseLost = "Lost" - // CoderWorkspaceClaimConditionReady is True when the claim is bound and - // its workspace is ready. + // CoderWorkspaceClaimConditionReady is True when the claim is bound, its + // workspace is ready, and, with spec.share, shared. CoderWorkspaceClaimConditionReady = "Ready" // CoderWorkspaceClaimConditionReconciling is True while the claim waits. CoderWorkspaceClaimConditionReconciling = "Reconciling" @@ -33,6 +33,22 @@ type CoderWorkspaceClaimSpec struct { // +kubebuilder:validation:MaxLength=253 // +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$` PoolName string `json:"poolName"` + // Share names the Coder user that gets the workspace. Required when the + // pool's claims.mode is Share, refused otherwise: such a claim never binds + // and is Stalled with ClaimModeMismatch. + // +optional + Share *CoderWorkspaceClaimShare `json:"share,omitempty"` +} + +// CoderWorkspaceClaimShare names the Coder user of a Share claim. +type CoderWorkspaceClaimShare struct { + // User is a Coder username or user UUID (lower case with hyphens). + // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:MaxLength=36 + // +kubebuilder:validation:Pattern=`^([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$` + // +kubebuilder:validation:XValidation:rule="self.size() <= 32 || self.matches('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$')",message="user must be a Coder username of at most 32 characters or a lower-case UUID" + // +kubebuilder:validation:XValidation:rule="self != 'c42fdf75-3097-471c-8c33-fb52454d81c0'",message="user must not be the Coder prebuilds system user" + User string `json:"user"` } // CoderWorkspaceClaimStatus defines the observed state of a @@ -60,6 +76,13 @@ type CoderWorkspaceClaimStatus struct { // BoundTime is when a member took the claim. // +optional BoundTime *metav1.Time `json:"boundTime,omitempty"` + // SharedUserID is the Coder user that has the `use` role on the + // workspace through this claim, as the member last read it from Coder. + // +kubebuilder:validation:MaxLength=36 + // +kubebuilder:validation:Pattern=`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` + // +kubebuilder:validation:XValidation:rule="self != 'c42fdf75-3097-471c-8c33-fb52454d81c0'",message="sharedUserID must not be the Coder prebuilds system user" + // +optional + SharedUserID string `json:"sharedUserID,omitempty"` // Reason is the current wait reason or the reason for Lost. // +optional Reason string `json:"reason,omitempty"` diff --git a/api/v1alpha1/coderworkspacepool_types.go b/api/v1alpha1/coderworkspacepool_types.go index 60839eb3b..2f7e433c8 100644 --- a/api/v1alpha1/coderworkspacepool_types.go +++ b/api/v1alpha1/coderworkspacepool_types.go @@ -26,6 +26,9 @@ const ( // The consumer connects with credentials it already holds for the pool // owner. CoderWorkspacePoolClaimModeReserve = "Reserve" + // CoderWorkspacePoolClaimModeShare binds a ready workspace to a claim and + // gives the claim's spec.share.user the Coder `use` role on it. + CoderWorkspacePoolClaimModeShare = "Share" // CoderWorkspacePoolSelectorLabel is the label key of the pool's // status.selector: =. @@ -76,6 +79,19 @@ type WorkspacePoolOwner struct { // +kubebuilder:validation:Maximum=100 // +optional MaxWorkspaces *int32 `json:"maxWorkspaces,omitempty"` + // ShareGroupIDs turn on Share mode for this owner: they are the Coder + // groups whose members a Share claim can name. Empty means Share mode is + // off for this owner. The template organization's ID names its Everyone + // group: every active member of that organization, without a license. + // Other groups need a Premium license (Coder answers 403 without one, and + // the share is refused). Every claimant can act as the pool owner if the + // template exposes the owner's session token (see the how-to). + // +kubebuilder:validation:MaxItems=16 + // +kubebuilder:validation:items:MaxLength=36 + // +kubebuilder:validation:items:Pattern=`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` + // +listType=set + // +optional + ShareGroupIDs []string `json:"shareGroupIDs,omitempty"` } // CoderWorkspacePoolVersion selects the template version of new members. Set @@ -117,8 +133,11 @@ type CoderWorkspacePoolParameter struct { // CoderWorkspacePoolClaims configures how the pool hands out workspaces. type CoderWorkspacePoolClaims struct { // Mode is how a claim gets its workspace. Reserve binds a ready workspace - // to the claim, and the workspace stays with the pool owner. - // +kubebuilder:validation:Enum=Reserve + // to the claim, and the workspace stays with the pool owner. Share also + // gives the claim's spec.share.user the Coder `use` role on the workspace + // (open apps, SSH, start, stop; never delete), where the organization's + // sharing setting and the owner's shareGroupIDs allow it. + // +kubebuilder:validation:Enum=Reserve;Share // +kubebuilder:default=Reserve // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="claims.mode is immutable" // +optional diff --git a/api/v1alpha1/coderworkspacepoolmember_types.go b/api/v1alpha1/coderworkspacepoolmember_types.go index bd4895bb6..e9af92cc5 100644 --- a/api/v1alpha1/coderworkspacepoolmember_types.go +++ b/api/v1alpha1/coderworkspacepoolmember_types.go @@ -30,6 +30,12 @@ const ( // CoderWorkspacePoolMemberConditionWorkspaceDeleted reports whether the // member's workspace is gone, with the CoderTemplateTest reasons. CoderWorkspacePoolMemberConditionWorkspaceDeleted = "WorkspaceDeleted" + // CoderWorkspacePoolMemberConditionShared is True while Coder's ACL gives + // status.sharedUserID the use role on the workspace of a Share claim. + // Reason ShareRefused: the policy or Coder refused the share. Reason + // ShareRemoved: the share is gone from Coder, and the controller does not + // share again. + CoderWorkspacePoolMemberConditionShared = "Shared" // CoderWorkspacePoolMemberCleanupFinalizer keeps a member until its // workspace is deleted. @@ -177,6 +183,16 @@ type CoderWorkspacePoolMemberStatus struct { // that the extension happened. // +optional BindExtendDeadline *metav1.Time `json:"bindExtendDeadline,omitempty"` + // SharedUserID is the Coder user that the controller shares the + // workspace with for a Share claim. The controller stores it before its + // first ACL write and never changes it, so a renamed or reused username + // never moves the share to another user. The Shared condition reports + // whether Coder's ACL gives this user the `use` role. + // +kubebuilder:validation:MaxLength=36 + // +kubebuilder:validation:Pattern=`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` + // +kubebuilder:validation:XValidation:rule="self != 'c42fdf75-3097-471c-8c33-fb52454d81c0'",message="sharedUserID must not be the Coder prebuilds system user" + // +optional + SharedUserID string `json:"sharedUserID,omitempty"` // DeleteBuildID is the ID of the current delete build. // +optional DeleteBuildID string `json:"deleteBuildID,omitempty"` @@ -190,7 +206,8 @@ type CoderWorkspacePoolMemberStatus struct { // logs, parameter values, or tokens. // +optional Message string `json:"message,omitempty"` - // Conditions are Ready, Used, and WorkspaceDeleted. + // Conditions are Ready, Used, WorkspaceDeleted, and, for a Share claim, + // Shared. // +listType=map // +listMapKey=type // +optional diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 7e421c947..eef00a437 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -1284,7 +1284,7 @@ func (in *CoderWorkspaceClaim) DeepCopyInto(out *CoderWorkspaceClaim) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec + in.Spec.DeepCopyInto(&out.Spec) in.Status.DeepCopyInto(&out.Status) return } @@ -1356,9 +1356,30 @@ func (in *CoderWorkspaceClaimReference) DeepCopy() *CoderWorkspaceClaimReference return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CoderWorkspaceClaimShare) DeepCopyInto(out *CoderWorkspaceClaimShare) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CoderWorkspaceClaimShare. +func (in *CoderWorkspaceClaimShare) DeepCopy() *CoderWorkspaceClaimShare { + if in == nil { + return nil + } + out := new(CoderWorkspaceClaimShare) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CoderWorkspaceClaimSpec) DeepCopyInto(out *CoderWorkspaceClaimSpec) { *out = *in + if in.Share != nil { + in, out := &in.Share, &out.Share + *out = new(CoderWorkspaceClaimShare) + **out = **in + } return } @@ -2289,6 +2310,11 @@ func (in *WorkspacePoolOwner) DeepCopyInto(out *WorkspacePoolOwner) { *out = new(int32) **out = **in } + if in.ShareGroupIDs != nil { + in, out := &in.ShareGroupIDs, &out.ShareGroupIDs + *out = make([]string, len(*in)) + copy(*out, *in) + } return } diff --git a/config/crd/bases/coder.com_codercontrolplanes.yaml b/config/crd/bases/coder.com_codercontrolplanes.yaml index 0c07cd8d8..abb52c32d 100644 --- a/config/crd/bases/coder.com_codercontrolplanes.yaml +++ b/config/crd/bases/coder.com_codercontrolplanes.yaml @@ -4390,6 +4390,22 @@ spec: maximum: 100 minimum: 1 type: integer + shareGroupIDs: + description: |- + ShareGroupIDs turn on Share mode for this owner: they are the Coder + groups whose members a Share claim can name. Empty means Share mode is + off for this owner. The template organization's ID names its Everyone + group: every active member of that organization, without a license. + Other groups need a Premium license (Coder answers 403 without one, and + the share is refused). Every claimant can act as the pool owner if the + template exposes the owner's session token (see the how-to). + items: + maxLength: 36 + pattern: ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ + type: string + maxItems: 16 + type: array + x-kubernetes-list-type: set templates: description: |- Templates are the only Coder templates, as `.