server

package
v0.17.6 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: AGPL-3.0 Imports: 43 Imported by: 0

Documentation

Overview

Package server implements the gRPC ProvisionerService and owns the top-level Server struct that wires together configuration, blueprints, the Helm client, identity, NATS, and the injection watcher into a running service.

Index

Constants

This section is empty.

Variables

View Source
var PAT_SCOPES = []string{
	"session:list:self",
	"user:read:profile:self",
	"user:read:credentials:registry:self",
	"user:read:credentials:kubernetes:self",
	"user:read:credentials:git:self",
	"git:fetch",
	"git:push",
	"user:write:password:self",
	"workspace:delete:self",
}

PAT_SCOPES defines the scopes for the Personal Access Token created for the workspace.

Functions

This section is empty.

Types

type InjectionWatcher

type InjectionWatcher struct {
	// contains filtered or unexported fields
}

InjectionWatcher watches workloads (Deployment, StatefulSet, DaemonSet) across the configured injection namespaces and cleans up workspace resources when a workload loses its injection annotation (either updated away or deleted).

func NewInjectionWatcher

func NewInjectionWatcher(helmClient *helm.Client, namespaces []string) *InjectionWatcher

func (*InjectionWatcher) Run

func (w *InjectionWatcher) Run(ctx context.Context)

Run starts one set of informers per injection namespace (or cluster-scoped informers when namespaces contains "*") and blocks until ctx is cancelled.

type ProvisionJobServer

type ProvisionJobServer struct {
	models.ProvisionJob `json:",inline"`
	NextEventId         int64 `json:"-"`
	// contains filtered or unexported fields
}

ProvisionJobServer extends models.ProvisionJob with a NATS KV handle and a monotonic event counter so that provisioning progress can be observed by clients polling the NATS bucket independently of the streaming gRPC connection.

func LoadProvisionJob added in v0.16.0

func LoadProvisionJob(kv *natsc.JetStreamKV, jobID string, log *zerolog.Logger) (*ProvisionJobServer, error)

LoadProvisionJob fetches an existing provision job from the NATS KV store by ID and wraps it in a ProvisionJobServer so further events can be appended and its status updated, continuing the event ID sequence from where the stored record left off. Returns an error if the job is missing or the stored record cannot be decoded.

func NewProvisionJob

func NewProvisionJob(WorkspaceName string, username string, kv *natsc.JetStreamKV, log *zerolog.Logger) *ProvisionJobServer

NewProvisionJob creates a new ProvisionJob instance with the given username and monitor URL.

func (*ProvisionJobServer) AddEvent

AddEvent appends a stream event to the job record and persists it to the NATS KV store so async clients can reconstruct the provisioning timeline.

func (*ProvisionJobServer) SetStatus

func (j *ProvisionJobServer) SetStatus(status models.ProvisionJobStatus)

SetStatus updates the job status and, when transitioning to Completed, stamps the finished-at timestamp before persisting to the NATS KV store.

type ProvisionerService

type ProvisionerService struct {
	provisionerv1.UnimplementedProvisionerServiceServer
	// contains filtered or unexported fields
}

ProvisionerService implements the gRPC service for workspace provisioning

func NewProvisionerService

func NewProvisionerService(server *Server) *ProvisionerService

NewProvisionerService creates a new instance of the ProvisionerService

func (*ProvisionerService) CreateBlueprint added in v0.16.0

CreateBlueprint stores a new org-scoped blueprint in the database. The blueprint's name, description and is_template flag are read from the submitted YAML document, which is validated exactly as ValidateBlueprint does before it is persisted; the blueprint manager's merged view is then refreshed so the new blueprint is immediately usable.

func (*ProvisionerService) DeleteBlueprint added in v0.16.0

DeleteBlueprint removes an org-scoped blueprint from the database, and refreshes the blueprint manager's merged view so it stops being served.

func (*ProvisionerService) DeleteUserWorkspaces added in v0.16.0

DeleteUserWorkspaces hard-deletes every workspace (standalone and injected) owned by a user. It is intended as a cleanup step when a user is removed from the system: the actual deletion runs in the background so this RPC can return quickly to a synchronous caller, but a distributed lock keyed by username ensures only one replica performs the cleanup at a time and that a call made while cleanup is already in progress is rejected rather than starting a second, overlapping run.

func (*ProvisionerService) DeleteWorkspace

DeleteWorkspace deletes a workspace asynchronously with distributed locking

func (*ProvisionerService) DiffWorkspaceBlueprint added in v0.17.1

DiffWorkspaceBlueprint compares the blueprint a workspace was provisioned from, recovered from its stored Helm values, with what that blueprint resolves to now for the workspace's owner, and returns the result as aligned side-by-side rows.

func (*ProvisionerService) EjectWorkspace

EjectWorkspace removes a previously injected workspace from a workload and deletes all supporting resources (ConfigMaps, PVCs, NetworkPolicies) in the target namespace.

func (*ProvisionerService) FindWorkspace

FindWorkspace retrieves the details of a specific workspace

func (*ProvisionerService) FindWorkspaceByAlias added in v0.16.8

FindWorkspaceByAlias retrieves the details of the workspace holding a web-proxy alias within an organization.

func (*ProvisionerService) GetBlueprint added in v0.16.0

GetBlueprint returns the full raw (unevaluated) spec of a single blueprint, both merged with its inherited Template and as defined directly on the blueprint itself, so callers can tell which fields are inherited rather than set on this blueprint. When req.Org is set, an org-scoped database blueprint of that name takes precedence over a file-based one.

func (*ProvisionerService) GetBlueprintsQuerySchema added in v0.16.0

GetBlueprintsQuerySchema returns the query.v1.Descriptor advertising which blueprint fields are queryable/sortable via QueryBlueprints.

func (*ProvisionerService) GetVersionInfo added in v0.16.0

GetVersionInfo returns the provisioner's released version, the git commit it was built from, and a short description of the service. The version and commit are injected at build time via -ldflags into main.PROVISIONER_VERSION / main.PROVISIONER_COMMIT (see docker/provisioner/Dockerfile) and threaded through NewServer; local builds report the development placeholders.

func (*ProvisionerService) GetWorkspaces

GetWorkspaces lists all workspaces, optionally filtered by user and/or blueprint

func (*ProvisionerService) GetWorkspacesByUserStr

GetWorkspacesByUserStr returns workspaces matching the given userstr

func (*ProvisionerService) GetWorkspacesQuerySchema added in v0.16.0

GetWorkspacesQuerySchema returns the query.v1.Descriptor advertising which workspace fields are queryable/sortable via QueryWorkspaces.

func (*ProvisionerService) ListBlueprints added in v0.16.0

ListBlueprints returns a summary of every blueprint the provisioner knows about: the file-based, global blueprints and every org-scoped database blueprint.

func (*ProvisionerService) ListInjectNamespaces added in v0.16.0

ListInjectNamespaces returns the namespaces the provisioner is configured to allow workload injection into. When injection is cluster-wide ("*"), it lists the namespaces that currently exist in the cluster.

func (*ProvisionerService) ListInjectWorkloads added in v0.16.0

ListInjectWorkloads returns the workloads a workspace can be injected into, each reporting whether it already hosts an injected workspace and who owns it.

func (*ProvisionerService) ProvisionWorkspaceStream

ProvisionWorkspaceStream provisions a new workspace with streaming updates

func (*ProvisionerService) QueryBlueprints added in v0.16.0

QueryBlueprints retrieves blueprint summaries matching a generic query.v1.Payload, as advertised by GetBlueprintsQuerySchema. Like ListBlueprints, it is transparent to whether a matched blueprint is file-based or stored in the database.

func (*ProvisionerService) QueryWorkspaces added in v0.16.0

QueryWorkspaces retrieves workspaces matching a generic query.v1.Payload, as advertised by GetWorkspacesQuerySchema.

func (*ProvisionerService) StartWorkspaceStream added in v0.16.0

StartWorkspaceStream resumes a previously stopped workspace: it recreates the pod from the existing Helm release, minting a fresh PAT along the way (the previous one was deleted on stop), streaming progress the same way ProvisionWorkspaceStream does. Calling it on an already-running workspace is rejected with AlreadyExists, mirroring ProvisionWorkspaceStream.

func (*ProvisionerService) StopWorkspace

StopWorkspace deletes only the workspace pod, leaving the Helm release and all other resources (PVCs, secrets, ConfigMaps) intact for later re-provisioning.

func (*ProvisionerService) UpdateBlueprint added in v0.16.0

UpdateBlueprint replaces the YAML content of an existing org-scoped blueprint, identified by org plus the name read from the submitted YAML document. The description and is_template flag are refreshed from the document too. The YAML is validated exactly as ValidateBlueprint does before it is persisted, and the blueprint manager's merged view is refreshed so the change is immediately visible.

func (*ProvisionerService) UpdateWorkspaceResources added in v0.16.0

UpdateWorkspaceResources changes a workspace's CPU/memory limits and/or its network policy class and egress rules directly on the live Kubernetes objects, without touching the Helm release. The pod is resized in place via the pods/resize subresource and the NetworkPolicies are re-rendered from the chart and re-applied. Because the Helm release is left as-is, a later re-provision (or a stop followed by a start) reverts the workspace to the resources and network class declared in its blueprint.

func (*ProvisionerService) ValidateBlueprint added in v0.16.0

ValidateBlueprint validates a standalone blueprint YAML document without registering it in the provisioner, returning every validation problem found. When req.Org is set, a `template:` reference resolves to an org-scoped template of that name in that org before a global/file template of the same name, matching how a stored org blueprint of that org resolves its parent.

type Server

type Server struct {
	Identity *identity.IdentityClient
	Authz    authzv1.AuthzServiceClient

	DB *db.DB
	// contains filtered or unexported fields
}

Server holds all long-lived dependencies of the provisioner process: config, blueprint manager, Helm/Kubernetes client, identity client, NATS connection, JWT verifier, and the gRPC server handle.

func NewServer

func NewServer(configFile string, appVersion string, commit string) (*Server, error)

NewServer constructs and fully initialises a Server from the given config file. It loads blueprints, connects to NATS and the identity service, creates the Helm client, registers the gRPC service, and ensures base Kubernetes resources are present before returning.

func (*Server) GetBlueprintScope

func (s *Server) GetBlueprintScope(blueprintName string, user *models.User,
	bpMetadata *models.BlueprintMetadata, workspaceName string) (*blueprint.BlueprintScope, error)

GetBlueprintScope constructs a BlueprintScope for CEL template evaluation, filling repository metadata fields with placeholder values when bpMetadata is nil or has empty fields so templates always receive a consistent variable set.

func (*Server) Serve

func (s *Server) Serve() error

Start starts the gRPC server and waits for shutdown signals

Jump to

Keyboard shortcuts

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