storage

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 37 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const (

	// MaxTemplateVersionBuildWaitTimeout keeps template build waits within aggregated API request deadlines.
	MaxTemplateVersionBuildWaitTimeout = 30 * time.Minute
)
View Source
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.

View Source
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.

View Source
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

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

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

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

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

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

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

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

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

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

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

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

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

New implements rest.Storage.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL