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 ¶
- Variables
- type InjectionWatcher
- type ProvisionJobServer
- type ProvisionerService
- func (p *ProvisionerService) CreateBlueprint(_ context.Context, req *provisionerv1.CreateBlueprintRequest) (*provisionerv1.OrgBlueprint, error)
- func (p *ProvisionerService) DeleteBlueprint(_ context.Context, req *provisionerv1.DeleteBlueprintRequest) (*provisionerv1.DeleteBlueprintResponse, error)
- func (p *ProvisionerService) DeleteUserWorkspaces(ctx context.Context, req *provisionerv1.DeleteUserWorkspacesRequest) (*provisionerv1.DeleteUserWorkspacesResponse, error)
- func (p *ProvisionerService) DeleteWorkspace(ctx context.Context, req *provisionerv1.DeleteWorkspaceRequest) (*provisionerv1.DeleteWorkspaceResponse, error)
- func (p *ProvisionerService) DiffWorkspaceBlueprint(ctx context.Context, req *provisionerv1.DiffWorkspaceBlueprintRequest) (*provisionerv1.DiffWorkspaceBlueprintResponse, error)
- func (p *ProvisionerService) EjectWorkspace(ctx context.Context, req *provisionerv1.EjectWorkspaceRequest) (*provisionerv1.EjectWorkspaceResponse, error)
- func (p *ProvisionerService) FindWorkspace(ctx context.Context, req *provisionerv1.FindWorkspaceRequest) (*commonv1.WorkspaceDetails, error)
- func (p *ProvisionerService) FindWorkspaceByAlias(ctx context.Context, req *provisionerv1.FindWorkspaceByAliasRequest) (*commonv1.WorkspaceDetails, error)
- func (p *ProvisionerService) GetBlueprint(_ context.Context, req *provisionerv1.GetBlueprintRequest) (*provisionerv1.GetBlueprintResponse, error)
- func (p *ProvisionerService) GetBlueprintsQuerySchema(_ context.Context, _ *provisionerv1.GetBlueprintsQuerySchemaRequest) (*queryv1.Descriptor, error)
- func (p *ProvisionerService) GetVersionInfo(_ context.Context, _ *commonv1.GetVersionInfoRequest) (*commonv1.GetVersionInfoResponse, error)
- func (p *ProvisionerService) GetWorkspaces(ctx context.Context, req *provisionerv1.GetWorkspacesRequest) (*provisionerv1.GetWorkspacesResponse, error)
- func (p *ProvisionerService) GetWorkspacesByUserStr(ctx context.Context, req *provisionerv1.GetWorkspacesByUserStrRequest) (*provisionerv1.GetWorkspacesResponse, error)
- func (p *ProvisionerService) GetWorkspacesQuerySchema(_ context.Context, _ *provisionerv1.GetWorkspacesQuerySchemaRequest) (*queryv1.Descriptor, error)
- func (p *ProvisionerService) ListBlueprints(_ context.Context, _ *provisionerv1.ListBlueprintsRequest) (*provisionerv1.ListBlueprintsResponse, error)
- func (p *ProvisionerService) ListInjectNamespaces(ctx context.Context, _ *provisionerv1.ListInjectNamespacesRequest) (*provisionerv1.ListInjectNamespacesResponse, error)
- func (p *ProvisionerService) ListInjectWorkloads(ctx context.Context, req *provisionerv1.ListInjectWorkloadsRequest) (*provisionerv1.ListInjectWorkloadsResponse, error)
- func (p *ProvisionerService) ProvisionWorkspaceStream(req *provisionerv1.ProvisionWorkspaceRequest, ...) error
- func (p *ProvisionerService) QueryBlueprints(_ context.Context, req *provisionerv1.QueryBlueprintsRequest) (*provisionerv1.QueryBlueprintsResponse, error)
- func (p *ProvisionerService) QueryWorkspaces(ctx context.Context, req *provisionerv1.QueryWorkspacesRequest) (*provisionerv1.GetWorkspacesResponse, error)
- func (p *ProvisionerService) StartWorkspaceStream(req *provisionerv1.StartWorkspaceRequest, ...) error
- func (p *ProvisionerService) StopWorkspace(ctx context.Context, req *provisionerv1.StopWorkspaceRequest) (*provisionerv1.StopWorkspaceResponse, error)
- func (p *ProvisionerService) UpdateBlueprint(_ context.Context, req *provisionerv1.UpdateBlueprintRequest) (*provisionerv1.OrgBlueprint, error)
- func (p *ProvisionerService) UpdateWorkspaceResources(ctx context.Context, req *provisionerv1.UpdateWorkspaceResourcesRequest) (*provisionerv1.UpdateWorkspaceResourcesResponse, error)
- func (p *ProvisionerService) ValidateBlueprint(_ context.Context, req *provisionerv1.ValidateBlueprintRequest) (*provisionerv1.ValidateBlueprintResponse, error)
- type Server
Constants ¶
This section is empty.
Variables ¶
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 ¶
func (j *ProvisionJobServer) AddEvent(ev *provisionerv1.ProvisionEvent)
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
func (p *ProvisionerService) CreateBlueprint(_ context.Context, req *provisionerv1.CreateBlueprintRequest) (*provisionerv1.OrgBlueprint, error)
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
func (p *ProvisionerService) DeleteBlueprint(_ context.Context, req *provisionerv1.DeleteBlueprintRequest) (*provisionerv1.DeleteBlueprintResponse, error)
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
func (p *ProvisionerService) DeleteUserWorkspaces(ctx context.Context, req *provisionerv1.DeleteUserWorkspacesRequest) (*provisionerv1.DeleteUserWorkspacesResponse, error)
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 ¶
func (p *ProvisionerService) DeleteWorkspace(ctx context.Context, req *provisionerv1.DeleteWorkspaceRequest) (*provisionerv1.DeleteWorkspaceResponse, error)
DeleteWorkspace deletes a workspace asynchronously with distributed locking
func (*ProvisionerService) DiffWorkspaceBlueprint ¶ added in v0.17.1
func (p *ProvisionerService) DiffWorkspaceBlueprint(ctx context.Context, req *provisionerv1.DiffWorkspaceBlueprintRequest) (*provisionerv1.DiffWorkspaceBlueprintResponse, error)
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 ¶
func (p *ProvisionerService) EjectWorkspace( ctx context.Context, req *provisionerv1.EjectWorkspaceRequest, ) (*provisionerv1.EjectWorkspaceResponse, error)
EjectWorkspace removes a previously injected workspace from a workload and deletes all supporting resources (ConfigMaps, PVCs, NetworkPolicies) in the target namespace.
func (*ProvisionerService) FindWorkspace ¶
func (p *ProvisionerService) FindWorkspace(ctx context.Context, req *provisionerv1.FindWorkspaceRequest) (*commonv1.WorkspaceDetails, error)
FindWorkspace retrieves the details of a specific workspace
func (*ProvisionerService) FindWorkspaceByAlias ¶ added in v0.16.8
func (p *ProvisionerService) FindWorkspaceByAlias(ctx context.Context, req *provisionerv1.FindWorkspaceByAliasRequest) (*commonv1.WorkspaceDetails, error)
FindWorkspaceByAlias retrieves the details of the workspace holding a web-proxy alias within an organization.
func (*ProvisionerService) GetBlueprint ¶ added in v0.16.0
func (p *ProvisionerService) GetBlueprint(_ context.Context, req *provisionerv1.GetBlueprintRequest, ) (*provisionerv1.GetBlueprintResponse, error)
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
func (p *ProvisionerService) GetBlueprintsQuerySchema(_ context.Context, _ *provisionerv1.GetBlueprintsQuerySchemaRequest) (*queryv1.Descriptor, error)
GetBlueprintsQuerySchema returns the query.v1.Descriptor advertising which blueprint fields are queryable/sortable via QueryBlueprints.
func (*ProvisionerService) GetVersionInfo ¶ added in v0.16.0
func (p *ProvisionerService) GetVersionInfo(_ context.Context, _ *commonv1.GetVersionInfoRequest) (*commonv1.GetVersionInfoResponse, error)
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 ¶
func (p *ProvisionerService) GetWorkspaces( ctx context.Context, req *provisionerv1.GetWorkspacesRequest, ) (*provisionerv1.GetWorkspacesResponse, error)
GetWorkspaces lists all workspaces, optionally filtered by user and/or blueprint
func (*ProvisionerService) GetWorkspacesByUserStr ¶
func (p *ProvisionerService) GetWorkspacesByUserStr( ctx context.Context, req *provisionerv1.GetWorkspacesByUserStrRequest, ) (*provisionerv1.GetWorkspacesResponse, error)
GetWorkspacesByUserStr returns workspaces matching the given userstr
func (*ProvisionerService) GetWorkspacesQuerySchema ¶ added in v0.16.0
func (p *ProvisionerService) GetWorkspacesQuerySchema(_ context.Context, _ *provisionerv1.GetWorkspacesQuerySchemaRequest) (*queryv1.Descriptor, error)
GetWorkspacesQuerySchema returns the query.v1.Descriptor advertising which workspace fields are queryable/sortable via QueryWorkspaces.
func (*ProvisionerService) ListBlueprints ¶ added in v0.16.0
func (p *ProvisionerService) ListBlueprints(_ context.Context, _ *provisionerv1.ListBlueprintsRequest, ) (*provisionerv1.ListBlueprintsResponse, error)
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
func (p *ProvisionerService) ListInjectNamespaces(ctx context.Context, _ *provisionerv1.ListInjectNamespacesRequest) (*provisionerv1.ListInjectNamespacesResponse, error)
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
func (p *ProvisionerService) ListInjectWorkloads(ctx context.Context, req *provisionerv1.ListInjectWorkloadsRequest) (*provisionerv1.ListInjectWorkloadsResponse, error)
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 ¶
func (p *ProvisionerService) ProvisionWorkspaceStream( req *provisionerv1.ProvisionWorkspaceRequest, stream provisionerv1.ProvisionerService_ProvisionWorkspaceStreamServer, ) error
ProvisionWorkspaceStream provisions a new workspace with streaming updates
func (*ProvisionerService) QueryBlueprints ¶ added in v0.16.0
func (p *ProvisionerService) QueryBlueprints(_ context.Context, req *provisionerv1.QueryBlueprintsRequest, ) (*provisionerv1.QueryBlueprintsResponse, error)
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
func (p *ProvisionerService) QueryWorkspaces( ctx context.Context, req *provisionerv1.QueryWorkspacesRequest, ) (*provisionerv1.GetWorkspacesResponse, error)
QueryWorkspaces retrieves workspaces matching a generic query.v1.Payload, as advertised by GetWorkspacesQuerySchema.
func (*ProvisionerService) StartWorkspaceStream ¶ added in v0.16.0
func (p *ProvisionerService) StartWorkspaceStream( req *provisionerv1.StartWorkspaceRequest, stream provisionerv1.ProvisionerService_StartWorkspaceStreamServer, ) error
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 ¶
func (p *ProvisionerService) StopWorkspace(ctx context.Context, req *provisionerv1.StopWorkspaceRequest) (*provisionerv1.StopWorkspaceResponse, error)
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
func (p *ProvisionerService) UpdateBlueprint(_ context.Context, req *provisionerv1.UpdateBlueprintRequest) (*provisionerv1.OrgBlueprint, error)
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
func (p *ProvisionerService) UpdateWorkspaceResources(ctx context.Context, req *provisionerv1.UpdateWorkspaceResourcesRequest) (*provisionerv1.UpdateWorkspaceResourcesResponse, error)
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
func (p *ProvisionerService) ValidateBlueprint(_ context.Context, req *provisionerv1.ValidateBlueprintRequest, ) (*provisionerv1.ValidateBlueprintResponse, error)
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 ¶
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.