template

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package template provides reusable workload blueprints. A Template captures the spec needed to instantiate a Workload — image, resources, env, secrets references, config files, volumes, ports, health check, labels and annotations — without any runtime state. Templates are authored directly via the template Service or forked from an existing Workload via CreateFromWorkload.

Templates are tenant-scoped. The persistent schema lives in store/<backend>/template.go and is owned by this package — deploy no longer participates in template storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewService

func NewService(store Store, events event.Bus) *service

NewService wires the template service. The WorkloadSpecReader is optional at construction time — call SetWorkloadReader once the workload service is built to enable CreateFromWorkload. Returns a concrete *service so the caller can use both Service methods and SetWorkloadReader.

The event bus is also optional — pass nil and template lifecycle events will be silently dropped. The default app wiring always passes the shared bus so events flow into the audit hook.

Types

type ConfigFile

type ConfigFile = provider.ConfigFile

ConfigFile is an alias for provider.ConfigFile. See SecretRef for the rationale.

type CreateFromWorkloadRequest

type CreateFromWorkloadRequest struct {
	Name        string `json:"name"                  validate:"required"`
	Description string `json:"description,omitempty"`
	Notes       string `json:"notes,omitempty"`
}

CreateFromWorkloadRequest forks a template from an existing workload's spec. Only Name and Description are user-supplied — every other field is read from the workload via the WorkloadSpecReader.

type CreateRequest

type CreateRequest struct {
	Name            string                    `json:"name"                       validate:"required"`
	Description     string                    `json:"description,omitempty"`
	DefaultKind     provider.WorkloadKind     `json:"default_kind,omitempty"`
	DefaultStrategy string                    `json:"default_strategy,omitempty"`
	Services        []provider.ServiceSpec    `json:"services,omitempty"`
	Labels          map[string]string         `json:"labels,omitempty"`
	Notes           string                    `json:"notes,omitempty"`
	Variables       []vars.Definition         `json:"variables,omitempty"`
	Source          provider.DeploymentSource `json:"source,omitzero"`
}

CreateRequest holds the parameters for creating a workload template.

A template describes what to deploy via Source. For backward compatibility, callers may instead populate Services alone — Create projects them onto a services Source.

type ListOptions

type ListOptions struct {
	Cursor string `json:"cursor,omitempty"`
	Limit  int    `json:"limit,omitempty"`
}

ListOptions configures template listing.

type ListResult

type ListResult struct {
	Items      []*Template `json:"items"`
	NextCursor string      `json:"next_cursor,omitempty"`
	Total      int         `json:"total"`
}

ListResult holds a page of templates with a total count.

type SecretRef

type SecretRef = provider.SecretRef

SecretRef is an alias for provider.SecretRef. The canonical type lives in the provider package so it can sit alongside ServiceSpec without introducing a template ↔ provider import cycle. Kept here as a thin alias so existing callers that referenced template.SecretRef do not need to chase the rename.

type Service

type Service interface {
	// Create persists a new template authored from raw fields.
	Create(ctx context.Context, req CreateRequest) (*Template, error)

	// CreateFromWorkload forks a new template from an existing
	// workload's current spec. The workload's image, env, secrets,
	// config files, volumes, ports, health check, labels and
	// annotations are copied wholesale into the template.
	CreateFromWorkload(ctx context.Context, workloadID id.ID, req CreateFromWorkloadRequest) (*Template, error)

	// Get returns a specific template.
	Get(ctx context.Context, templateID id.ID) (*Template, error)

	// Update mutates an existing template; nil request fields are left untouched.
	Update(ctx context.Context, templateID id.ID, req UpdateRequest) (*Template, error)

	// Delete removes a template.
	Delete(ctx context.Context, templateID id.ID) error

	// List returns templates for the caller's tenant.
	List(ctx context.Context, opts ListOptions) (*ListResult, error)
}

Service manages workload templates. It supports authoring templates directly, listing/reading/updating/deleting them, and forking a new template from an existing workload's spec.

type Store

type Store interface {
	InsertTemplate(ctx context.Context, t *Template) error
	GetTemplate(ctx context.Context, tenantID string, templateID id.ID) (*Template, error)
	UpdateTemplate(ctx context.Context, t *Template) error
	DeleteTemplate(ctx context.Context, tenantID string, templateID id.ID) error
	ListTemplates(ctx context.Context, tenantID string, opts ListOptions) (*ListResult, error)
}

Store is the persistence interface for workload templates. Method names are entity-suffixed so a single concrete store type can implement Template + Workload + Instance + Deploy + Network etc. without method-name collisions on Insert/Get/List/Update/Delete.

type Template

type Template struct {
	ctrlplane.Entity

	TenantID        string                 `db:"tenant_id"        json:"tenant_id"`
	Name            string                 `db:"name"             json:"name"`
	Description     string                 `db:"description"      json:"description,omitempty"`
	DefaultKind     provider.WorkloadKind  `db:"default_kind"     json:"default_kind,omitempty"`
	DefaultStrategy string                 `db:"default_strategy" json:"default_strategy,omitempty"`
	Services        []provider.ServiceSpec `db:"services"         json:"services"`
	Labels          map[string]string      `db:"labels"           json:"labels,omitempty"`
	Notes           string                 `db:"notes"            json:"notes,omitempty"`

	// Variables declares the typed template variables resolved at
	// instantiation time and injected into the deployment source.
	Variables []vars.Definition `db:"variables" json:"variables,omitempty"`

	// Source describes what the template deploys (services | helm |
	// manifests | argocd). Legacy templates carry only Services; call
	// NormalizeSource to project them onto a services Source.
	Source provider.DeploymentSource `db:"source" json:"source,omitzero"`
}

Template is a reusable workload blueprint that can be instantiated to create a Workload. The Services slice mirrors a Workload's Services — instantiation copies them onto the new Workload verbatim. Workload- level fields (DefaultKind, DefaultStrategy, Labels) seed the workload at creation time and may be overridden by the CreateRequest.

func (*Template) MainService

func (t *Template) MainService() *provider.ServiceSpec

MainService returns the template's Main service, or nil when none is configured. Used by the dashboard to show "the template's image" when a single representative is needed.

func (*Template) NormalizeSource added in v1.5.2

func (t *Template) NormalizeSource()

NormalizeSource projects a legacy services-only template onto a typed services Source when no Source.Type is set. Idempotent — an explicit Source is left untouched.

type UpdateRequest

type UpdateRequest struct {
	Name            *string                    `json:"name,omitempty"`
	Description     *string                    `json:"description,omitempty"`
	DefaultKind     *provider.WorkloadKind     `json:"default_kind,omitempty"`
	DefaultStrategy *string                    `json:"default_strategy,omitempty"`
	Services        []provider.ServiceSpec     `json:"services,omitempty"`
	Labels          map[string]string          `json:"labels,omitempty"`
	Notes           *string                    `json:"notes,omitempty"`
	Variables       []vars.Definition          `json:"variables,omitempty"`
	Source          *provider.DeploymentSource `json:"source,omitempty"`
}

UpdateRequest holds the parameters for updating a workload template. Pointer fields enable partial updates — only non-nil fields are applied.

type WorkloadSpec

type WorkloadSpec struct {
	Kind     provider.WorkloadKind
	Services []provider.ServiceSpec
	Labels   map[string]string
}

WorkloadSpec is the projection of a Workload's blueprint-relevant fields the template service needs in order to fork a template from a workload. The workload package adapts its concrete Workload onto this shape via WorkloadSpecReader so this package never imports workload.

type WorkloadSpecReader

type WorkloadSpecReader interface {
	ReadWorkloadSpec(ctx context.Context, tenantID string, workloadID id.ID) (*WorkloadSpec, error)
}

WorkloadSpecReader is the dependency template uses to read a workload's spec when forking a template.

Jump to

Keyboard shortcuts

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