Documentation
¶
Overview ¶
Package storage implements codersdk-backed REST storage for the aggregated API server's CoderWorkspace, CoderTemplate and CoderTemplateVersion resources.
v1 Semantics:
- Resources are namespace-scoped; the namespace represents the CoderControlPlane namespace.
- Template object names follow the format "<organization>.<template-name>".
- Workspace object names follow "<organization>.<user>.<workspace-name>".
- Template version object names follow "<organization>.<template-name>.<version-name>". Version names can contain dots. The first two dots separate the segments.
- The dot separator works because organization, user, template and workspace names are alphanumeric-with-hyphens (no dots), while Kubernetes object names allow dots (DNS-1123 subdomains).
- A single admin session token is used for all API calls (no per-request impersonation in v1).
- Storage resolves the backing codersdk.Client via a ClientProvider interface.
- All-namespaces LIST aggregates results across eligible CoderControlPlane namespaces when the provider implements NamespaceLister.
Index ¶
- Constants
- type TemplatePromoteStorage
- type TemplateStorage
- func (s *TemplateStorage) ConvertToTable(ctx context.Context, object, tableOptions runtime.Object) (*metav1.Table, error)
- func (s *TemplateStorage) Create(ctx context.Context, obj runtime.Object, ...) (runtime.Object, error)
- func (s *TemplateStorage) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, ...) (runtime.Object, bool, error)
- func (s *TemplateStorage) Destroy()
- func (s *TemplateStorage) Get(ctx context.Context, name string, _ *metav1.GetOptions) (runtime.Object, error)
- func (s *TemplateStorage) GetSingularName() string
- func (s *TemplateStorage) List(ctx context.Context, opts *metainternalversion.ListOptions) (runtime.Object, error)
- func (s *TemplateStorage) NamespaceScoped() bool
- func (s *TemplateStorage) New() runtime.Object
- func (s *TemplateStorage) NewList() runtime.Object
- func (s *TemplateStorage) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, ...) (runtime.Object, bool, error)
- func (s *TemplateStorage) Watch(ctx context.Context, opts *metainternalversion.ListOptions) (watch.Interface, error)
- type TemplateVersionStorage
- func (s *TemplateVersionStorage) ConvertToTable(_ context.Context, object, tableOptions runtime.Object) (*metav1.Table, error)
- func (s *TemplateVersionStorage) Destroy()
- func (s *TemplateVersionStorage) Get(ctx context.Context, name string, opts *metav1.GetOptions) (runtime.Object, error)
- func (s *TemplateVersionStorage) GetSingularName() string
- func (s *TemplateVersionStorage) List(ctx context.Context, opts *metainternalversion.ListOptions) (runtime.Object, error)
- func (s *TemplateVersionStorage) NamespaceScoped() bool
- func (s *TemplateVersionStorage) New() runtime.Object
- func (s *TemplateVersionStorage) NewList() runtime.Object
- type WorkspaceLogStorage
- func (s *WorkspaceLogStorage) Destroy()
- func (s *WorkspaceLogStorage) Get(ctx context.Context, name string, opts runtime.Object) (runtime.Object, error)
- func (s *WorkspaceLogStorage) New() runtime.Object
- func (s *WorkspaceLogStorage) NewGetOptions() (runtime.Object, bool, string)
- func (s *WorkspaceLogStorage) ProducesMIMETypes(string) []string
- func (s *WorkspaceLogStorage) ProducesObject(string) interface{}
- type WorkspaceStorage
- func (s *WorkspaceStorage) ConvertToTable(ctx context.Context, object, tableOptions runtime.Object) (*metav1.Table, error)
- func (s *WorkspaceStorage) Create(ctx context.Context, obj runtime.Object, ...) (runtime.Object, error)
- func (s *WorkspaceStorage) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, ...) (runtime.Object, bool, error)
- func (s *WorkspaceStorage) Destroy()
- func (s *WorkspaceStorage) Get(ctx context.Context, name string, _ *metav1.GetOptions) (runtime.Object, error)
- func (s *WorkspaceStorage) GetSingularName() string
- func (s *WorkspaceStorage) List(ctx context.Context, _ *metainternalversion.ListOptions) (runtime.Object, error)
- func (s *WorkspaceStorage) NamespaceScoped() bool
- func (s *WorkspaceStorage) New() runtime.Object
- func (s *WorkspaceStorage) NewList() runtime.Object
- func (s *WorkspaceStorage) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, ...) (runtime.Object, bool, error)
- func (s *WorkspaceStorage) Watch(ctx context.Context, opts *metainternalversion.ListOptions) (watch.Interface, error)
- type WorkspaceTransitionStorage
Constants ¶
const ( TemplatePromotePatchBudget = 10 * time.Second TemplatePromoteRereadReserve = 5 * time.Second )
The API server cuts every create request at 34 seconds and then answers 504 itself, whatever the storage did. A promotion therefore splits its deadline: the activation request gets at most TemplatePromotePatchBudget, and TemplatePromoteRereadReserve stays for the confirming re-read and the answer. The re-read ends a fifth of the reserve before the deadline, so after an activation the caller gets Promoted, 409 or 503 from this storage, never the API server's 504.
const ( // MaxTemplateVersionBuildWaitTimeout keeps template build waits within aggregated API request deadlines. MaxTemplateVersionBuildWaitTimeout = 30 * time.Minute )
const MaxWorkspaceLogDuration = 25 * time.Minute
MaxWorkspaceLogDuration bounds one coderworkspaces/log request: after it, the request reads nothing more from Coder. It stays below the aggregated API request timeout; the server checks that at startup.
const MaxWorkspaceLogSnapshotDuration = 60 * time.Second
MaxWorkspaceLogSnapshotDuration bounds a coderworkspaces/log snapshot request. In Kind, a snapshot of a 1 MB-capped build (1.66 MB rendered) took 0.39 s alone and 1.4 s at p99 with 64 concurrent requests, so 60 s leaves a wide margin while a stalled Coder holds a slot for at most one minute.
const TemplateVersionReadBudget = 25 * time.Second
TemplateVersionReadBudget bounds the total time of one GET (3 sequential Coder requests) or LIST (1+T sequential requests, T = number of templates). The API server allows reads up to its request timeout (30 minutes), and each Coder request can take up to the SDK timeout, far longer than kube-apiserver waits for a proxied read (60 seconds by default). The budget makes a slow Coder fail the read with 504 instead of holding it open.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TemplatePromoteStorage ¶ added in v0.1.3
type TemplatePromoteStorage struct {
// contains filtered or unexported fields
}
TemplatePromoteStorage serves the codertemplates/promote subresource. It activates an existing version of a template. It never downloads template source and never retries the activation.
func NewTemplatePromoteStorage ¶ added in v0.1.3
func NewTemplatePromoteStorage(provider coder.ClientProvider) *TemplatePromoteStorage
NewTemplatePromoteStorage builds codersdk-backed storage for the codertemplates/promote subresource.
func (*TemplatePromoteStorage) Create ¶ added in v0.1.3
func (s *TemplatePromoteStorage) Create( ctx context.Context, name string, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions, ) (runtime.Object, error)
Create activates spec.versionID on the template named name.
Every outcome reports observed state. AlreadyActive and dry-run send no write to Coder. A real activation is confirmed by re-reading the template: it returns 409 when another version became active instead, and 503 when the outcome cannot be confirmed. A 503 has no Retry-After, because the activation may already have been applied.
func (*TemplatePromoteStorage) Destroy ¶ added in v0.1.3
func (s *TemplatePromoteStorage) Destroy()
Destroy is a no-op: the storage holds no background resources.
func (*TemplatePromoteStorage) New ¶ added in v0.1.3
func (s *TemplatePromoteStorage) New() runtime.Object
New returns an empty CoderTemplateVersionPromotion object.
type TemplateStorage ¶
type TemplateStorage struct {
// contains filtered or unexported fields
}
TemplateStorage provides codersdk-backed CoderTemplate objects.
func NewTemplateStorage ¶
func NewTemplateStorage(provider coder.ClientProvider) *TemplateStorage
NewTemplateStorage builds codersdk-backed storage for CoderTemplate resources.
func (*TemplateStorage) ConvertToTable ¶
func (s *TemplateStorage) ConvertToTable(ctx context.Context, object, tableOptions runtime.Object) (*metav1.Table, error)
ConvertToTable converts a template object or list into kubectl table output.
func (*TemplateStorage) Create ¶
func (s *TemplateStorage) Create( ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions, ) (runtime.Object, error)
Create creates a CoderTemplate through codersdk.
func (*TemplateStorage) Delete ¶
func (s *TemplateStorage) Delete( ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions, ) (runtime.Object, bool, error)
Delete deletes a CoderTemplate through codersdk.
func (*TemplateStorage) Destroy ¶
func (s *TemplateStorage) Destroy()
Destroy cleans up storage resources.
func (*TemplateStorage) Get ¶
func (s *TemplateStorage) Get(ctx context.Context, name string, _ *metav1.GetOptions) (runtime.Object, error)
Get fetches a CoderTemplate by organization and template name.
func (*TemplateStorage) GetSingularName ¶
func (s *TemplateStorage) GetSingularName() string
GetSingularName returns the singular name of the CoderTemplate resource.
func (*TemplateStorage) List ¶
func (s *TemplateStorage) List(ctx context.Context, opts *metainternalversion.ListOptions) (runtime.Object, error)
List fetches CoderTemplate objects from codersdk and applies label and field selectors in memory. limit is ignored: the list is always complete and has no continue token.
func (*TemplateStorage) NamespaceScoped ¶
func (s *TemplateStorage) NamespaceScoped() bool
NamespaceScoped returns true because CoderTemplate is namespaced.
func (*TemplateStorage) New ¶
func (s *TemplateStorage) New() runtime.Object
New returns an empty CoderTemplate object.
func (*TemplateStorage) NewList ¶
func (s *TemplateStorage) NewList() runtime.Object
NewList returns an empty CoderTemplateList object.
func (*TemplateStorage) Update ¶
func (s *TemplateStorage) Update( ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions, ) (runtime.Object, bool, error)
Update applies a template metadata/source reconcile.
func (*TemplateStorage) Watch ¶
func (s *TemplateStorage) Watch(ctx context.Context, opts *metainternalversion.ListOptions) (watch.Interface, error)
Watch watches CoderTemplate objects backed by codersdk.
type TemplateVersionStorage ¶ added in v0.1.3
type TemplateVersionStorage struct {
// contains filtered or unexported fields
}
TemplateVersionStorage serves read-only CoderTemplateVersion objects from codersdk. Versions change outside this server (Coder UI and CLI, imports, template updates), so it deliberately implements no watch and no write verbs.
func NewTemplateVersionStorage ¶ added in v0.1.3
func NewTemplateVersionStorage(provider coder.ClientProvider) *TemplateVersionStorage
NewTemplateVersionStorage builds codersdk-backed storage for CoderTemplateVersion resources.
func (*TemplateVersionStorage) ConvertToTable ¶ added in v0.1.3
func (s *TemplateVersionStorage) ConvertToTable(_ context.Context, object, tableOptions runtime.Object) (*metav1.Table, error)
ConvertToTable renders versions for kubectl. -o wide adds the version ID and message.
func (*TemplateVersionStorage) Destroy ¶ added in v0.1.3
func (s *TemplateVersionStorage) Destroy()
Destroy is a no-op: the storage holds no background resources.
func (*TemplateVersionStorage) Get ¶ added in v0.1.3
func (s *TemplateVersionStorage) Get(ctx context.Context, name string, opts *metav1.GetOptions) (runtime.Object, error)
Get fetches a CoderTemplateVersion named <organization>.<template>.<version>. It makes three Coder requests (organization, template, version by name) and never downloads template source.
func (*TemplateVersionStorage) GetSingularName ¶ added in v0.1.3
func (s *TemplateVersionStorage) GetSingularName() string
GetSingularName returns the singular name of the CoderTemplateVersion resource.
func (*TemplateVersionStorage) List ¶ added in v0.1.3
func (s *TemplateVersionStorage) List(ctx context.Context, opts *metainternalversion.ListOptions) (runtime.Object, error)
List returns every version of every template, archived, failed and pending ones included. It makes one Coder request for the template list plus one per template, and never downloads template source. limit is ignored: the list is always complete and has no continue token.
func (*TemplateVersionStorage) NamespaceScoped ¶ added in v0.1.3
func (s *TemplateVersionStorage) NamespaceScoped() bool
NamespaceScoped returns true because CoderTemplateVersion is namespaced.
func (*TemplateVersionStorage) New ¶ added in v0.1.3
func (s *TemplateVersionStorage) New() runtime.Object
New returns an empty CoderTemplateVersion object.
func (*TemplateVersionStorage) NewList ¶ added in v0.1.3
func (s *TemplateVersionStorage) NewList() runtime.Object
NewList returns an empty CoderTemplateVersionList object.
type WorkspaceLogStorage ¶ added in v0.1.3
type WorkspaceLogStorage struct {
// contains filtered or unexported fields
}
WorkspaceLogStorage serves the coderworkspaces/log subresource: the latest build log of a workspace as text/plain, in Coder's own text line format.
func NewWorkspaceLogStorage ¶ added in v0.1.3
func NewWorkspaceLogStorage(workspaces *WorkspaceStorage) *WorkspaceLogStorage
NewWorkspaceLogStorage returns log storage that resolves workspaces through workspaces.
func (*WorkspaceLogStorage) Destroy ¶ added in v0.1.3
func (s *WorkspaceLogStorage) Destroy()
Destroy implements rest.Storage.
func (*WorkspaceLogStorage) Get ¶ added in v0.1.3
func (s *WorkspaceLogStorage) Get(ctx context.Context, name string, opts runtime.Object) (runtime.Object, error)
Get validates the request and returns a stream. It makes no Coder call: InputStream takes a slot first, so a request over the slot cap never reaches Coder.
func (*WorkspaceLogStorage) New ¶ added in v0.1.3
func (s *WorkspaceLogStorage) New() runtime.Object
New returns a CoderWorkspace, as Pod log storage returns a Pod; it is used only for API metadata.
func (*WorkspaceLogStorage) NewGetOptions ¶ added in v0.1.3
func (s *WorkspaceLogStorage) NewGetOptions() (runtime.Object, bool, string)
NewGetOptions implements rest.GetterWithOptions.
func (*WorkspaceLogStorage) ProducesMIMETypes ¶ added in v0.1.3
func (s *WorkspaceLogStorage) ProducesMIMETypes(string) []string
ProducesMIMETypes implements rest.StorageMetadata.
func (*WorkspaceLogStorage) ProducesObject ¶ added in v0.1.3
func (s *WorkspaceLogStorage) ProducesObject(string) interface{}
ProducesObject implements rest.StorageMetadata.
type WorkspaceStorage ¶
type WorkspaceStorage struct {
// contains filtered or unexported fields
}
WorkspaceStorage provides codersdk-backed CoderWorkspace objects.
func NewWorkspaceStorage ¶
func NewWorkspaceStorage(provider coder.ClientProvider) *WorkspaceStorage
NewWorkspaceStorage builds codersdk-backed storage for CoderWorkspace resources.
func (*WorkspaceStorage) ConvertToTable ¶
func (s *WorkspaceStorage) ConvertToTable(ctx context.Context, object, tableOptions runtime.Object) (*metav1.Table, error)
ConvertToTable converts a workspace object or list into kubectl table output.
func (*WorkspaceStorage) Create ¶
func (s *WorkspaceStorage) Create( ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions, ) (runtime.Object, error)
Create creates a CoderWorkspace through codersdk.
func (*WorkspaceStorage) Delete ¶
func (s *WorkspaceStorage) Delete( ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions, ) (runtime.Object, bool, error)
Delete requests workspace deletion through a codersdk build transition.
func (*WorkspaceStorage) Destroy ¶
func (s *WorkspaceStorage) Destroy()
Destroy cleans up storage resources.
func (*WorkspaceStorage) Get ¶
func (s *WorkspaceStorage) Get(ctx context.Context, name string, _ *metav1.GetOptions) (runtime.Object, error)
Get fetches a CoderWorkspace by organization, owner, and workspace name.
func (*WorkspaceStorage) GetSingularName ¶
func (s *WorkspaceStorage) GetSingularName() string
GetSingularName returns the singular name of the CoderWorkspace resource.
func (*WorkspaceStorage) List ¶
func (s *WorkspaceStorage) List(ctx context.Context, _ *metainternalversion.ListOptions) (runtime.Object, error)
List fetches CoderWorkspace objects from codersdk.
func (*WorkspaceStorage) NamespaceScoped ¶
func (s *WorkspaceStorage) NamespaceScoped() bool
NamespaceScoped returns true because CoderWorkspace is namespaced.
func (*WorkspaceStorage) New ¶
func (s *WorkspaceStorage) New() runtime.Object
New returns an empty CoderWorkspace object.
func (*WorkspaceStorage) NewList ¶
func (s *WorkspaceStorage) NewList() runtime.Object
NewList returns an empty CoderWorkspaceList object.
func (*WorkspaceStorage) Update ¶
func (s *WorkspaceStorage) Update( ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions, ) (runtime.Object, bool, error)
Update updates workspace run state through codersdk build transitions.
func (*WorkspaceStorage) Watch ¶
func (s *WorkspaceStorage) Watch(ctx context.Context, opts *metainternalversion.ListOptions) (watch.Interface, error)
Watch watches CoderWorkspace objects backed by codersdk.
type WorkspaceTransitionStorage ¶ added in v0.1.3
type WorkspaceTransitionStorage struct {
// contains filtered or unexported fields
}
WorkspaceTransitionStorage serves the coderworkspaces/start or coderworkspaces/stop subresource. It decides from the latest build whether a new build is needed, so a repeated request converges on the requested state instead of queueing more builds.
func NewWorkspaceTransitionStorage ¶ added in v0.1.3
func NewWorkspaceTransitionStorage(workspaces *WorkspaceStorage, transition codersdk.WorkspaceTransition) *WorkspaceTransitionStorage
NewWorkspaceTransitionStorage returns storage for the start or stop transition.
func (*WorkspaceTransitionStorage) Create ¶ added in v0.1.3
func (s *WorkspaceTransitionStorage) Create( ctx context.Context, name string, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions, ) (runtime.Object, error)
Create starts or stops the workspace name. It always answers with a fresh object that holds only metadata and the outcome.
func (*WorkspaceTransitionStorage) Destroy ¶ added in v0.1.3
func (s *WorkspaceTransitionStorage) Destroy()
Destroy implements rest.Storage.
func (*WorkspaceTransitionStorage) New ¶ added in v0.1.3
func (s *WorkspaceTransitionStorage) New() runtime.Object
New implements rest.Storage.