swarm

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: PostgreSQL Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceUserRoleRO = "ro"
	ServiceUserRoleRW = "rw"
)
View Source
const (
	OverlayDriver = "overlay"
)
View Source
const ResourceTypeCheckWillRestart resource.Type = "swarm.check_will_restart"
View Source
const ResourceTypeEtcdCreds resource.Type = "swarm.etcd_creds"
View Source
const ResourceTypeMCPConfig resource.Type = "swarm.mcp_config"
View Source
const ResourceTypeNetwork resource.Type = "swarm.network"
View Source
const ResourceTypePatroniCluster resource.Type = "swarm.patroni_cluster"
View Source
const ResourceTypePatroniConfig resource.Type = "swarm.patroni_config"
View Source
const ResourceTypePatroniMember resource.Type = "swarm.patroni_member"
View Source
const ResourceTypePgBackRestConfig resource.Type = "swarm.pgbackrest_config"
View Source
const ResourceTypePgBackRestRestore resource.Type = "swarm.pgbackrest_restore"
View Source
const ResourceTypePgBackRestStanza resource.Type = "swarm.pgbackrest_stanza"
View Source
const ResourceTypePostgresCerts resource.Type = "swarm.postgres_certs"
View Source
const ResourceTypePostgresService resource.Type = "swarm.postgres_service"
View Source
const ResourceTypePostgresServiceSpec resource.Type = "swarm.postgres_service_spec"
View Source
const ResourceTypeScaleService resource.Type = "swarm.scale_service"
View Source
const ResourceTypeServiceInstance resource.Type = database.ResourceTypeServiceInstance
View Source
const ResourceTypeServiceInstanceSpec resource.Type = "swarm.service_instance_spec"
View Source
const ResourceTypeServiceUserRole resource.Type = "swarm.service_user_role"
View Source
const ResourceTypeSwitchover resource.Type = "swarm.switchover"

Variables

View Source
var (
	ErrNoPostgresContainer = errors.New("no postgres container found")
	ErrNoPostgresService   = errors.New("no postgres service found")
	ErrNoServiceContainer  = errors.New("no service container found")
)

Functions

func CheckWillRestartIdentifier

func CheckWillRestartIdentifier(instanceID string) resource.Identifier

func DatabaseServiceSpec

func DatabaseServiceSpec(
	instance *database.InstanceSpec,
	options *HostOptions,
) (swarm.ServiceSpec, error)

func EtcdCredsIdentifier

func EtcdCredsIdentifier(instanceID string) resource.Identifier

func GenerateEmptyTokenFile added in v0.7.0

func GenerateEmptyTokenFile() ([]byte, error)

GenerateEmptyTokenFile generates an empty but valid tokens.yaml file.

func GenerateEmptyUserFile added in v0.7.0

func GenerateEmptyUserFile() ([]byte, error)

GenerateEmptyUserFile generates an empty but valid users.yaml file.

func GenerateMCPConfig added in v0.7.0

func GenerateMCPConfig(params *MCPConfigParams) ([]byte, error)

GenerateMCPConfig generates the YAML config file content for the MCP server.

func GenerateTokenFile added in v0.7.0

func GenerateTokenFile(initToken string) ([]byte, error)

GenerateTokenFile generates a tokens.yaml file from the given init token. The token is SHA256-hashed to match the MCP server's auth.HashToken() format.

func GenerateUserFile added in v0.7.0

func GenerateUserFile(users []database.MCPServiceUser) ([]byte, error)

GenerateUserFile generates a users.yaml file from the given bootstrap users. Passwords are bcrypt-hashed with cost 12 to match the MCP server's auth.HashPassword() format.

func GetPostgresContainer

func GetPostgresContainer(ctx context.Context, dockerClient *docker.Docker, instanceID string) (types.Container, error)

func GetServiceContainer added in v0.7.0

func GetServiceContainer(ctx context.Context, dockerClient *docker.Docker, serviceInstanceID string) (types.Container, error)

func MCPConfigResourceIdentifier added in v0.7.0

func MCPConfigResourceIdentifier(serviceInstanceID string) resource.Identifier

func NetworkResourceIdentifier

func NetworkResourceIdentifier(name string) resource.Identifier

func PatroniClusterResourceIdentifier

func PatroniClusterResourceIdentifier(nodeName string) resource.Identifier

func PatroniConfigIdentifier

func PatroniConfigIdentifier(instanceID string) resource.Identifier

func PatroniMemberResourceIdentifier

func PatroniMemberResourceIdentifier(instanceID string) resource.Identifier

func PgBackRestBackupCmd

func PgBackRestBackupCmd(command string, args ...string) pgbackrest.Cmd

func PgBackRestConfigIdentifier

func PgBackRestConfigIdentifier(instanceID string, configType PgBackRestConfigType) resource.Identifier

func PgBackRestRestoreCmd

func PgBackRestRestoreCmd(command string, args ...string) pgbackrest.Cmd

func PgBackRestRestoreResourceIdentifier

func PgBackRestRestoreResourceIdentifier(instanceID string) resource.Identifier

func PgBackRestStanzaIdentifier

func PgBackRestStanzaIdentifier(nodeName string) resource.Identifier

func PostgresCertsIdentifier

func PostgresCertsIdentifier(instanceID string) resource.Identifier

func PostgresContainerExec

func PostgresContainerExec(ctx context.Context, w io.Writer, dockerClient *docker.Docker, instanceID string, cmd []string) error

func PostgresServiceResourceIdentifier

func PostgresServiceResourceIdentifier(instanceID string) resource.Identifier

func PostgresServiceSpecResourceIdentifier

func PostgresServiceSpecResourceIdentifier(instanceID string) resource.Identifier

func Provide

func Provide(i *do.Injector)

func RegisterResourceTypes

func RegisterResourceTypes(registry *resource.Registry)

func ScaleServiceResourceIdentifier

func ScaleServiceResourceIdentifier(instanceID string, direction ScaleDirection) resource.Identifier

func ServiceContainerSpec added in v0.7.0

func ServiceContainerSpec(opts *ServiceContainerSpecOptions) (swarm.ServiceSpec, error)

ServiceContainerSpec builds a Docker Swarm service spec for a service instance.

func ServiceInstanceName added in v0.7.0

func ServiceInstanceName(serviceType, databaseID, serviceID, hostID string) string

ServiceInstanceName generates a Docker Swarm service name for a service instance. It follows the same host ID hashing convention used for Postgres instance IDs (see database.InstanceIDFor), producing shorter, more readable names when host IDs are UUIDs.

func ServiceInstanceResourceIdentifier added in v0.7.0

func ServiceInstanceResourceIdentifier(serviceInstanceID string) resource.Identifier

func ServiceInstanceSpecResourceIdentifier added in v0.7.0

func ServiceInstanceSpecResourceIdentifier(serviceInstanceID string) resource.Identifier

func ServiceUserRoleIdentifier added in v0.7.0

func ServiceUserRoleIdentifier(serviceInstanceID string, mode string) resource.Identifier

func ServiceUserRolePerNodeIdentifier added in v0.7.0

func ServiceUserRolePerNodeIdentifier(serviceID, mode, nodeName string) resource.Identifier

func SwitchoverResourceIdentifier

func SwitchoverResourceIdentifier(instanceID string) resource.Identifier

Types

type Allocator

type Allocator struct {
	Prefix netip.Prefix `json:"prefix"`
	Bits   int          `json:"bits"`
}

type CheckWillRestart

type CheckWillRestart struct {
	InstanceID  string `json:"instance_id"`
	WillRestart bool   `json:"will_restart"`
}

func (*CheckWillRestart) Create

func (c *CheckWillRestart) Create(ctx context.Context, rc *resource.Context) error

func (*CheckWillRestart) Delete

func (c *CheckWillRestart) Delete(ctx context.Context, rc *resource.Context) error

func (*CheckWillRestart) Dependencies

func (c *CheckWillRestart) Dependencies() []resource.Identifier

func (*CheckWillRestart) DiffIgnore

func (c *CheckWillRestart) DiffIgnore() []string

func (*CheckWillRestart) Executor

func (c *CheckWillRestart) Executor() resource.Executor

func (*CheckWillRestart) Identifier

func (c *CheckWillRestart) Identifier() resource.Identifier

func (*CheckWillRestart) Refresh

func (c *CheckWillRestart) Refresh(ctx context.Context, rc *resource.Context) error

func (*CheckWillRestart) ResourceVersion

func (c *CheckWillRestart) ResourceVersion() string

func (*CheckWillRestart) TypeDependencies added in v0.7.0

func (c *CheckWillRestart) TypeDependencies() []resource.Type

func (*CheckWillRestart) Update

func (c *CheckWillRestart) Update(ctx context.Context, rc *resource.Context) error

type EtcdCreds

type EtcdCreds struct {
	InstanceID string `json:"instance_id"`
	DatabaseID string `json:"database_id"`
	HostID     string `json:"host_id"`
	NodeName   string `json:"node_name"`
	ParentID   string `json:"parent_id"`
	OwnerUID   int    `json:"owner_uid"`
	OwnerGID   int    `json:"owner_gid"`
	Username   string `json:"username"`
	Password   string `json:"password"`
	CaCert     []byte `json:"ca_cert"`
	ClientCert []byte `json:"server_cert"`
	ClientKey  []byte `json:"server_key"`
}

func (*EtcdCreds) Create

func (c *EtcdCreds) Create(ctx context.Context, rc *resource.Context) error

func (*EtcdCreds) Delete

func (c *EtcdCreds) Delete(ctx context.Context, rc *resource.Context) error

func (*EtcdCreds) Dependencies

func (c *EtcdCreds) Dependencies() []resource.Identifier

func (*EtcdCreds) DiffIgnore

func (c *EtcdCreds) DiffIgnore() []string

func (*EtcdCreds) Executor

func (c *EtcdCreds) Executor() resource.Executor

func (*EtcdCreds) Identifier

func (c *EtcdCreds) Identifier() resource.Identifier

func (*EtcdCreds) Refresh

func (c *EtcdCreds) Refresh(ctx context.Context, rc *resource.Context) error

func (*EtcdCreds) ResourceVersion

func (c *EtcdCreds) ResourceVersion() string

func (*EtcdCreds) TypeDependencies added in v0.7.0

func (c *EtcdCreds) TypeDependencies() []resource.Type

func (*EtcdCreds) Update

func (c *EtcdCreds) Update(ctx context.Context, rc *resource.Context) error

type HostOptions

type HostOptions struct {
	ServiceName       string
	InstanceHostname  string
	DatabaseNetworkID string
	Paths             Paths
	Images            *Images
	CohortMemberID    string
}

type Images

type Images struct {
	PgEdgeImage string
}

type Instance

type Instance struct {
	Spec *database.InstanceSpec `json:"spec"`
}

func (*Instance) Create

func (i *Instance) Create(
	ctx context.Context,
	state *resource.State,
	inj *do.Injector,
) error

func (*Instance) Dependencies

func (i *Instance) Dependencies() []resource.Identifier

func (*Instance) Identifier

func (i *Instance) Identifier() resource.Identifier

func (*Instance) Validate

func (i *Instance) Validate() error

type MCPConfigParams added in v0.7.0

type MCPConfigParams struct {
	Config             *database.MCPServiceConfig
	DatabaseName       string
	DatabaseHosts      []database.ServiceHostEntry
	TargetSessionAttrs string
	Username           string
	Password           string
}

MCPConfigParams holds all inputs needed to generate a config.yaml for the MCP server.

type MCPConfigResource added in v0.7.0

type MCPConfigResource struct {
	ServiceInstanceID  string                      `json:"service_instance_id"`
	ServiceID          string                      `json:"service_id"`
	HostID             string                      `json:"host_id"`
	DirResourceID      string                      `json:"dir_resource_id"`
	Config             *database.MCPServiceConfig  `json:"config"`
	DatabaseName       string                      `json:"database_name"`
	DatabaseHosts      []database.ServiceHostEntry `json:"database_hosts"`
	TargetSessionAttrs string                      `json:"target_session_attrs"`
	ROUsername         string                      `json:"ro_username"`
	ROPassword         string                      `json:"ro_password"`
	RWUsername         string                      `json:"rw_username"`
	RWPassword         string                      `json:"rw_password"`
}

MCPConfigResource manages the MCP server config files on the host filesystem. It follows the same pattern as PatroniConfig: generates config files and writes them to a host-side directory that is bind-mounted into the container.

Files managed:

  • config.yaml: CP-owned, overwritten on every Create/Update
  • tokens.yaml: Application-owned, written only on first Create if init_token is set
  • users.yaml: Application-owned, written only on first Create if init_users is set

func (*MCPConfigResource) Create added in v0.7.0

func (r *MCPConfigResource) Create(ctx context.Context, rc *resource.Context) error

func (*MCPConfigResource) Delete added in v0.7.0

func (r *MCPConfigResource) Delete(ctx context.Context, rc *resource.Context) error

func (*MCPConfigResource) Dependencies added in v0.7.0

func (r *MCPConfigResource) Dependencies() []resource.Identifier

func (*MCPConfigResource) DiffIgnore added in v0.7.0

func (r *MCPConfigResource) DiffIgnore() []string

func (*MCPConfigResource) Executor added in v0.7.0

func (r *MCPConfigResource) Executor() resource.Executor

func (*MCPConfigResource) Identifier added in v0.7.0

func (r *MCPConfigResource) Identifier() resource.Identifier

func (*MCPConfigResource) Refresh added in v0.7.0

func (r *MCPConfigResource) Refresh(ctx context.Context, rc *resource.Context) error

func (*MCPConfigResource) ResourceVersion added in v0.7.0

func (r *MCPConfigResource) ResourceVersion() string

func (*MCPConfigResource) TypeDependencies added in v0.7.0

func (r *MCPConfigResource) TypeDependencies() []resource.Type

func (*MCPConfigResource) Update added in v0.7.0

func (r *MCPConfigResource) Update(ctx context.Context, rc *resource.Context) error

type Network

type Network struct {
	Scope     string       `json:"scope"`
	Driver    string       `json:"driver"`
	Allocator Allocator    `json:"allocator"`
	Name      string       `json:"name"`
	NetworkID string       `json:"network_id"`
	Subnet    netip.Prefix `json:"subnet"`
	Gateway   netip.Addr   `json:"gateway"`
}

func (*Network) Create

func (n *Network) Create(ctx context.Context, rc *resource.Context) error

func (*Network) Delete

func (n *Network) Delete(ctx context.Context, rc *resource.Context) error

func (*Network) Dependencies

func (n *Network) Dependencies() []resource.Identifier

func (*Network) DiffIgnore

func (n *Network) DiffIgnore() []string

func (*Network) Executor

func (n *Network) Executor() resource.Executor

func (*Network) Identifier

func (n *Network) Identifier() resource.Identifier

func (*Network) Refresh

func (n *Network) Refresh(ctx context.Context, rc *resource.Context) error

func (*Network) ResourceVersion

func (n *Network) ResourceVersion() string

func (*Network) TypeDependencies added in v0.7.0

func (n *Network) TypeDependencies() []resource.Type

func (*Network) Update

func (n *Network) Update(ctx context.Context, rc *resource.Context) error

func (*Network) Validate

func (n *Network) Validate() error

type Orchestrator

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

func NewOrchestrator

func NewOrchestrator(
	ctx context.Context,
	cfg config.Config,
	d *docker.Docker,
	logger zerolog.Logger,
) (*Orchestrator, error)

func (*Orchestrator) CreatePgBackRestBackup

func (o *Orchestrator) CreatePgBackRestBackup(ctx context.Context, w io.Writer, instanceID string, options *pgbackrest.BackupOptions) error

func (*Orchestrator) GenerateInstanceResources

func (o *Orchestrator) GenerateInstanceResources(spec *database.InstanceSpec) (*database.InstanceResources, error)

func (*Orchestrator) GenerateInstanceRestoreResources

func (o *Orchestrator) GenerateInstanceRestoreResources(spec *database.InstanceSpec, taskID uuid.UUID) (*database.InstanceResources, error)

func (*Orchestrator) GenerateServiceInstanceResources added in v0.7.0

func (o *Orchestrator) GenerateServiceInstanceResources(spec *database.ServiceInstanceSpec) (*database.ServiceInstanceResources, error)

func (*Orchestrator) GetInstanceConnectionInfo

func (o *Orchestrator) GetInstanceConnectionInfo(ctx context.Context, databaseID, instanceID string) (*database.ConnectionInfo, error)

func (*Orchestrator) GetServiceInstanceStatus added in v0.7.0

func (o *Orchestrator) GetServiceInstanceStatus(ctx context.Context, serviceInstanceID string) (*database.ServiceInstanceStatus, error)

func (*Orchestrator) PopulateHost

func (o *Orchestrator) PopulateHost(ctx context.Context, h *host.Host) error

func (*Orchestrator) PopulateHostStatus

func (o *Orchestrator) PopulateHostStatus(ctx context.Context, status *host.HostStatus) error

func (*Orchestrator) StartInstance

func (o *Orchestrator) StartInstance(
	ctx context.Context,
	instanceID string,
) error

func (*Orchestrator) StopInstance

func (o *Orchestrator) StopInstance(
	ctx context.Context,
	instanceID string,
) error

func (*Orchestrator) ValidateInstanceSpecs

func (o *Orchestrator) ValidateInstanceSpecs(ctx context.Context, changes []*database.InstanceSpecChange) ([]*database.ValidationResult, error)

func (*Orchestrator) WorkerQueues

func (o *Orchestrator) WorkerQueues() ([]workflow.Queue, error)

type Paths

type Paths struct {
	Configs      string
	Certificates string
	Data         string
}

type PatroniCluster

type PatroniCluster struct {
	DatabaseID           string `json:"database_id"`
	NodeName             string `json:"node_name"`
	PatroniClusterPrefix string `json:"patroni_namespace"`
}

func (*PatroniCluster) Create

func (p *PatroniCluster) Create(ctx context.Context, rc *resource.Context) error

func (*PatroniCluster) Delete

func (p *PatroniCluster) Delete(ctx context.Context, rc *resource.Context) error

func (*PatroniCluster) Dependencies

func (p *PatroniCluster) Dependencies() []resource.Identifier

func (*PatroniCluster) DiffIgnore

func (p *PatroniCluster) DiffIgnore() []string

func (*PatroniCluster) Executor

func (p *PatroniCluster) Executor() resource.Executor

func (*PatroniCluster) Identifier

func (p *PatroniCluster) Identifier() resource.Identifier

func (*PatroniCluster) Refresh

func (p *PatroniCluster) Refresh(ctx context.Context, rc *resource.Context) error

func (*PatroniCluster) ResourceVersion

func (p *PatroniCluster) ResourceVersion() string

func (*PatroniCluster) TypeDependencies added in v0.7.0

func (p *PatroniCluster) TypeDependencies() []resource.Type

func (*PatroniCluster) Update

func (p *PatroniCluster) Update(ctx context.Context, rc *resource.Context) error

type PatroniConfig

type PatroniConfig struct {
	Spec                *database.InstanceSpec `json:"spec"`
	ParentID            string                 `json:"parent_id"`
	HostCPUs            float64                `json:"host_cpus"`
	HostMemoryBytes     uint64                 `json:"host_memory_bytes"`
	BridgeNetworkInfo   *docker.NetworkInfo    `json:"host_network_info"`
	DatabaseNetworkName string                 `json:"database_network_name"`
	OwnerUID            int                    `json:"owner_uid"`
	OwnerGID            int                    `json:"owner_gid"`
	InstanceHostname    string                 `json:"instance_hostname"`
}

func (*PatroniConfig) Create

func (c *PatroniConfig) Create(ctx context.Context, rc *resource.Context) error

func (*PatroniConfig) Delete

func (c *PatroniConfig) Delete(ctx context.Context, rc *resource.Context) error

func (*PatroniConfig) Dependencies

func (c *PatroniConfig) Dependencies() []resource.Identifier

func (*PatroniConfig) DiffIgnore

func (c *PatroniConfig) DiffIgnore() []string

func (*PatroniConfig) Executor

func (c *PatroniConfig) Executor() resource.Executor

func (*PatroniConfig) Identifier

func (c *PatroniConfig) Identifier() resource.Identifier

func (*PatroniConfig) Refresh

func (c *PatroniConfig) Refresh(ctx context.Context, rc *resource.Context) error

func (*PatroniConfig) ResourceVersion

func (c *PatroniConfig) ResourceVersion() string

func (*PatroniConfig) TypeDependencies added in v0.7.0

func (r *PatroniConfig) TypeDependencies() []resource.Type

func (*PatroniConfig) Update

func (c *PatroniConfig) Update(ctx context.Context, rc *resource.Context) error

type PatroniMember

type PatroniMember struct {
	DatabaseID string `json:"database_id"`
	NodeName   string `json:"node_name"`
	InstanceID string `json:"instance_id"`
}

func (*PatroniMember) Create

func (p *PatroniMember) Create(ctx context.Context, rc *resource.Context) error

func (*PatroniMember) Delete

func (p *PatroniMember) Delete(ctx context.Context, rc *resource.Context) error

func (*PatroniMember) Dependencies

func (p *PatroniMember) Dependencies() []resource.Identifier

func (*PatroniMember) DiffIgnore

func (p *PatroniMember) DiffIgnore() []string

func (*PatroniMember) Executor

func (p *PatroniMember) Executor() resource.Executor

func (*PatroniMember) Identifier

func (p *PatroniMember) Identifier() resource.Identifier

func (*PatroniMember) Refresh

func (p *PatroniMember) Refresh(ctx context.Context, rc *resource.Context) error

func (*PatroniMember) ResourceVersion

func (p *PatroniMember) ResourceVersion() string

func (*PatroniMember) TypeDependencies added in v0.7.0

func (p *PatroniMember) TypeDependencies() []resource.Type

func (*PatroniMember) Update

func (p *PatroniMember) Update(ctx context.Context, rc *resource.Context) error

type PgBackRestConfig

type PgBackRestConfig struct {
	InstanceID   string                   `json:"instance_id"`
	HostID       string                   `json:"host_id"`
	DatabaseID   string                   `json:"database_id"`
	NodeName     string                   `json:"node_name"`
	Repositories []*pgbackrest.Repository `json:"repositories"`
	ParentID     string                   `json:"parent_id"`
	Type         PgBackRestConfigType     `json:"type"`
	OwnerUID     int                      `json:"owner_uid"`
	OwnerGID     int                      `json:"owner_gid"`
}

func (*PgBackRestConfig) BaseName

func (c *PgBackRestConfig) BaseName() string

func (*PgBackRestConfig) ContainerPath

func (c *PgBackRestConfig) ContainerPath() string

func (*PgBackRestConfig) Create

func (c *PgBackRestConfig) Create(ctx context.Context, rc *resource.Context) error

func (*PgBackRestConfig) Delete

func (c *PgBackRestConfig) Delete(ctx context.Context, rc *resource.Context) error

func (*PgBackRestConfig) Dependencies

func (c *PgBackRestConfig) Dependencies() []resource.Identifier

func (*PgBackRestConfig) DiffIgnore

func (c *PgBackRestConfig) DiffIgnore() []string

func (*PgBackRestConfig) Executor

func (c *PgBackRestConfig) Executor() resource.Executor

func (*PgBackRestConfig) HostPath

func (c *PgBackRestConfig) HostPath(rc *resource.Context) (string, error)

func (*PgBackRestConfig) Identifier

func (c *PgBackRestConfig) Identifier() resource.Identifier

func (*PgBackRestConfig) Refresh

func (c *PgBackRestConfig) Refresh(ctx context.Context, rc *resource.Context) error

func (*PgBackRestConfig) ResourceVersion

func (c *PgBackRestConfig) ResourceVersion() string

func (*PgBackRestConfig) TypeDependencies added in v0.7.0

func (c *PgBackRestConfig) TypeDependencies() []resource.Type

func (*PgBackRestConfig) Update

func (c *PgBackRestConfig) Update(ctx context.Context, rc *resource.Context) error

type PgBackRestConfigType

type PgBackRestConfigType string
const (
	PgBackRestConfigTypeBackup  PgBackRestConfigType = "backup"
	PgBackRestConfigTypeRestore PgBackRestConfigType = "restore"
)

func (PgBackRestConfigType) String

func (t PgBackRestConfigType) String() string

type PgBackRestRestore

type PgBackRestRestore struct {
	DatabaseID     string            `json:"database_id"`
	HostID         string            `json:"host_id"`
	InstanceID     string            `json:"instance_id"`
	TaskID         uuid.UUID         `json:"task_id"`
	NodeName       string            `json:"node_name"`
	DataDirID      string            `json:"data_dir_id"`
	RestoreOptions map[string]string `json:"restore_options"`
}

func (*PgBackRestRestore) Create

func (p *PgBackRestRestore) Create(ctx context.Context, rc *resource.Context) error

func (*PgBackRestRestore) Delete

func (p *PgBackRestRestore) Delete(ctx context.Context, rc *resource.Context) error

func (*PgBackRestRestore) Dependencies

func (p *PgBackRestRestore) Dependencies() []resource.Identifier

func (*PgBackRestRestore) DiffIgnore

func (p *PgBackRestRestore) DiffIgnore() []string

func (*PgBackRestRestore) Executor

func (p *PgBackRestRestore) Executor() resource.Executor

func (*PgBackRestRestore) Identifier

func (p *PgBackRestRestore) Identifier() resource.Identifier

func (*PgBackRestRestore) Refresh

func (p *PgBackRestRestore) Refresh(ctx context.Context, rc *resource.Context) error

func (*PgBackRestRestore) ResourceVersion

func (p *PgBackRestRestore) ResourceVersion() string

func (*PgBackRestRestore) TypeDependencies added in v0.7.0

func (p *PgBackRestRestore) TypeDependencies() []resource.Type

func (*PgBackRestRestore) Update

func (p *PgBackRestRestore) Update(ctx context.Context, rc *resource.Context) error

type PgBackRestStanza

type PgBackRestStanza struct {
	NodeName string `json:"node_name"`
}

func (*PgBackRestStanza) Create

func (p *PgBackRestStanza) Create(ctx context.Context, rc *resource.Context) error

func (*PgBackRestStanza) Delete

func (p *PgBackRestStanza) Delete(ctx context.Context, rc *resource.Context) error

func (*PgBackRestStanza) Dependencies

func (p *PgBackRestStanza) Dependencies() []resource.Identifier

func (*PgBackRestStanza) DiffIgnore

func (p *PgBackRestStanza) DiffIgnore() []string

func (*PgBackRestStanza) Executor

func (p *PgBackRestStanza) Executor() resource.Executor

func (*PgBackRestStanza) Identifier

func (p *PgBackRestStanza) Identifier() resource.Identifier

func (*PgBackRestStanza) Refresh

func (p *PgBackRestStanza) Refresh(ctx context.Context, rc *resource.Context) error

func (*PgBackRestStanza) ResourceVersion

func (p *PgBackRestStanza) ResourceVersion() string

func (*PgBackRestStanza) TypeDependencies added in v0.7.0

func (p *PgBackRestStanza) TypeDependencies() []resource.Type

func (*PgBackRestStanza) Update

func (p *PgBackRestStanza) Update(ctx context.Context, rc *resource.Context) error

type PostgresCerts

type PostgresCerts struct {
	InstanceID        string   `json:"instance_id"`
	HostID            string   `json:"host_id"`
	InstanceAddresses []string `json:"instance_addresses"`
	ParentID          string   `json:"parent_id"`
	OwnerUID          int      `json:"owner_uid"`
	OwnerGID          int      `json:"owner_gid"`
	CaCert            []byte   `json:"ca_cert"`
	ServerCert        []byte   `json:"server_cert"`
	ServerKey         []byte   `json:"server_key"`
	SuperuserCert     []byte   `json:"superuser_cert"`
	SuperuserKey      []byte   `json:"superuser_key"`
	ReplicationCert   []byte   `json:"replication_cert"`
	ReplicationKey    []byte   `json:"replication_key"`
}

func (*PostgresCerts) Create

func (c *PostgresCerts) Create(ctx context.Context, rc *resource.Context) error

func (*PostgresCerts) Delete

func (c *PostgresCerts) Delete(ctx context.Context, rc *resource.Context) error

func (*PostgresCerts) Dependencies

func (c *PostgresCerts) Dependencies() []resource.Identifier

func (*PostgresCerts) DiffIgnore

func (c *PostgresCerts) DiffIgnore() []string

func (*PostgresCerts) Executor

func (c *PostgresCerts) Executor() resource.Executor

func (*PostgresCerts) Identifier

func (c *PostgresCerts) Identifier() resource.Identifier

func (*PostgresCerts) Refresh

func (c *PostgresCerts) Refresh(ctx context.Context, rc *resource.Context) error

func (*PostgresCerts) ResourceVersion

func (c *PostgresCerts) ResourceVersion() string

func (*PostgresCerts) TypeDependencies added in v0.7.0

func (c *PostgresCerts) TypeDependencies() []resource.Type

func (*PostgresCerts) Update

func (c *PostgresCerts) Update(ctx context.Context, rc *resource.Context) error

type PostgresService

type PostgresService struct {
	InstanceID  string `json:"instance_id"`
	ServiceName string `json:"service_name"`
	ServiceID   string `json:"service_id"`
	NeedsUpdate bool   `json:"needs_update"`
}

func (*PostgresService) Create

func (s *PostgresService) Create(ctx context.Context, rc *resource.Context) error

func (*PostgresService) Delete

func (s *PostgresService) Delete(ctx context.Context, rc *resource.Context) error

func (*PostgresService) Dependencies

func (s *PostgresService) Dependencies() []resource.Identifier

func (*PostgresService) DiffIgnore

func (s *PostgresService) DiffIgnore() []string

func (*PostgresService) Executor

func (s *PostgresService) Executor() resource.Executor

func (*PostgresService) Identifier

func (s *PostgresService) Identifier() resource.Identifier

func (*PostgresService) Refresh

func (s *PostgresService) Refresh(ctx context.Context, rc *resource.Context) error

func (*PostgresService) ResourceVersion

func (s *PostgresService) ResourceVersion() string

func (*PostgresService) TypeDependencies added in v0.7.0

func (s *PostgresService) TypeDependencies() []resource.Type

func (*PostgresService) Update

func (s *PostgresService) Update(ctx context.Context, rc *resource.Context) error

type PostgresServiceSpecResource

type PostgresServiceSpecResource struct {
	Instance            *database.InstanceSpec `json:"instance"`
	CohortMemberID      string                 `json:"cohort_member_id"`
	Images              *Images                `json:"images"`
	ServiceName         string                 `json:"service_name"`
	InstanceHostname    string                 `json:"instance_hostname"`
	Spec                swarm.ServiceSpec      `json:"spec"`
	DatabaseNetworkName string                 `json:"database_network_name"`
	DataDirID           string                 `json:"data_dir_id"`
	ConfigsDirID        string                 `json:"configs_dir_id"`
	CertificatesDirID   string                 `json:"certificates_dir_id"`
}

func (*PostgresServiceSpecResource) Create

func (*PostgresServiceSpecResource) Delete

func (*PostgresServiceSpecResource) Dependencies

func (s *PostgresServiceSpecResource) Dependencies() []resource.Identifier

func (*PostgresServiceSpecResource) DiffIgnore

func (s *PostgresServiceSpecResource) DiffIgnore() []string

func (*PostgresServiceSpecResource) Executor

func (*PostgresServiceSpecResource) Identifier

func (*PostgresServiceSpecResource) Refresh

func (*PostgresServiceSpecResource) ResourceVersion

func (s *PostgresServiceSpecResource) ResourceVersion() string

func (*PostgresServiceSpecResource) TypeDependencies added in v0.7.0

func (s *PostgresServiceSpecResource) TypeDependencies() []resource.Type

func (*PostgresServiceSpecResource) Update

type ScaleDirection

type ScaleDirection string
const (
	ScaleDirectionUP   ScaleDirection = "up"
	ScaleDirectionDOWN ScaleDirection = "down"
)

type ScaleService

type ScaleService struct {
	InstanceID     string                `json:"instance_id"`
	ScaleDirection ScaleDirection        `json:"scale_direction"`
	Deps           []resource.Identifier `json:"deps"`
}

func (*ScaleService) Create

func (s *ScaleService) Create(ctx context.Context, rc *resource.Context) error

func (*ScaleService) Delete

func (s *ScaleService) Delete(ctx context.Context, rc *resource.Context) error

func (*ScaleService) Dependencies

func (s *ScaleService) Dependencies() []resource.Identifier

func (*ScaleService) DiffIgnore

func (s *ScaleService) DiffIgnore() []string

func (*ScaleService) Executor

func (s *ScaleService) Executor() resource.Executor

func (*ScaleService) Identifier

func (s *ScaleService) Identifier() resource.Identifier

func (*ScaleService) Refresh

func (s *ScaleService) Refresh(ctx context.Context, rc *resource.Context) error

func (*ScaleService) ResourceVersion

func (s *ScaleService) ResourceVersion() string

func (*ScaleService) TypeDependencies added in v0.7.0

func (s *ScaleService) TypeDependencies() []resource.Type

func (*ScaleService) Update

func (s *ScaleService) Update(ctx context.Context, rc *resource.Context) error

type ServiceContainerSpecOptions added in v0.7.0

type ServiceContainerSpecOptions struct {
	ServiceSpec       *database.ServiceSpec
	ServiceInstanceID string
	DatabaseID        string
	DatabaseName      string
	HostID            string
	ServiceName       string
	Hostname          string
	CohortMemberID    string
	ServiceImage      *ServiceImage
	Credentials       *database.ServiceUser
	DatabaseNetworkID string
	// Service port configuration
	Port *int
	// DataPath is the host-side directory path for the bind mount
	DataPath string
}

ServiceContainerSpecOptions contains all parameters needed to build a service container spec.

type ServiceImage added in v0.7.0

type ServiceImage struct {
	Tag                string                  `json:"tag"`
	PostgresConstraint *host.VersionConstraint `json:"postgres_constraint,omitempty"`
	SpockConstraint    *host.VersionConstraint `json:"spock_constraint,omitempty"`
}

ServiceImage describes a container image for a service type+version, along with optional version constraints that restrict which Postgres and Spock versions the service is compatible with.

func (*ServiceImage) ValidateCompatibility added in v0.7.0

func (s *ServiceImage) ValidateCompatibility(postgres, spock *host.Version) error

ValidateCompatibility checks that the given Postgres and Spock versions satisfy this image's version constraints. Returns nil if compatible.

type ServiceInstanceResource added in v0.7.0

type ServiceInstanceResource struct {
	ServiceInstanceID string `json:"service_instance_id"`
	DatabaseID        string `json:"database_id"`
	ServiceName       string `json:"service_name"`
	ServiceID         string `json:"service_id"`      // Docker Swarm service ID (set by Refresh)
	ServiceSpecID     string `json:"service_spec_id"` // Logical service ID from the spec (e.g. "mcp-server")
	HostID            string `json:"host_id"`
	NeedsUpdate       bool   `json:"needs_update"`
}

func (*ServiceInstanceResource) Create added in v0.7.0

func (*ServiceInstanceResource) Delete added in v0.7.0

func (*ServiceInstanceResource) Dependencies added in v0.7.0

func (s *ServiceInstanceResource) Dependencies() []resource.Identifier

func (*ServiceInstanceResource) DiffIgnore added in v0.7.0

func (s *ServiceInstanceResource) DiffIgnore() []string

func (*ServiceInstanceResource) Executor added in v0.7.0

func (*ServiceInstanceResource) Identifier added in v0.7.0

func (*ServiceInstanceResource) Refresh added in v0.7.0

func (*ServiceInstanceResource) ResourceVersion added in v0.7.0

func (s *ServiceInstanceResource) ResourceVersion() string

func (*ServiceInstanceResource) TypeDependencies added in v0.7.0

func (s *ServiceInstanceResource) TypeDependencies() []resource.Type

func (*ServiceInstanceResource) Update added in v0.7.0

type ServiceInstanceSpecResource added in v0.7.0

type ServiceInstanceSpecResource struct {
	ServiceInstanceID  string                      `json:"service_instance_id"`
	ServiceSpec        *database.ServiceSpec       `json:"service_spec"`
	DatabaseID         string                      `json:"database_id"`
	DatabaseName       string                      `json:"database_name"`
	HostID             string                      `json:"host_id"`
	ServiceName        string                      `json:"service_name"`
	Hostname           string                      `json:"hostname"`
	CohortMemberID     string                      `json:"cohort_member_id"`
	ServiceImage       *ServiceImage               `json:"service_image"`
	Credentials        *database.ServiceUser       `json:"credentials"`
	DatabaseNetworkID  string                      `json:"database_network_id"`
	DatabaseHosts      []database.ServiceHostEntry `json:"database_hosts"`       // Ordered Postgres host:port entries
	TargetSessionAttrs string                      `json:"target_session_attrs"` // libpq target_session_attrs
	Port               *int                        `json:"port"`                 // Service published port (optional, 0 = random)
	DataDirID          string                      `json:"data_dir_id"`          // DirResource ID for the service data directory
	Spec               swarm.ServiceSpec           `json:"spec"`
}

func (*ServiceInstanceSpecResource) Create added in v0.7.0

func (*ServiceInstanceSpecResource) Delete added in v0.7.0

func (*ServiceInstanceSpecResource) Dependencies added in v0.7.0

func (s *ServiceInstanceSpecResource) Dependencies() []resource.Identifier

func (*ServiceInstanceSpecResource) DiffIgnore added in v0.7.0

func (s *ServiceInstanceSpecResource) DiffIgnore() []string

func (*ServiceInstanceSpecResource) Executor added in v0.7.0

func (*ServiceInstanceSpecResource) Identifier added in v0.7.0

func (*ServiceInstanceSpecResource) Refresh added in v0.7.0

func (*ServiceInstanceSpecResource) ResourceVersion added in v0.7.0

func (s *ServiceInstanceSpecResource) ResourceVersion() string

func (*ServiceInstanceSpecResource) TypeDependencies added in v0.7.0

func (s *ServiceInstanceSpecResource) TypeDependencies() []resource.Type

func (*ServiceInstanceSpecResource) Update added in v0.7.0

type ServiceUserRole added in v0.7.0

type ServiceUserRole struct {
	ServiceID        string               `json:"service_id"`
	DatabaseID       string               `json:"database_id"`
	DatabaseName     string               `json:"database_name"`
	NodeName         string               `json:"node_name"` // Database node name for PrimaryExecutor routing
	Mode             string               `json:"mode"`      // ServiceUserRoleRO or ServiceUserRoleRW
	Username         string               `json:"username"`
	Password         string               `json:"password"` // Generated on Create, persisted in state
	CredentialSource *resource.Identifier `json:"credential_source,omitempty"`
}

ServiceUserRole manages the lifecycle of a database user for a service.

Two ServiceUserRole resources are created per service: one with Mode set to ServiceUserRoleRO (read-only) and one with Mode set to ServiceUserRoleRW (read-write). Mode determines which group role the user is granted membership in: pgedge_application_read_only for RO, or pgedge_application for RW. All permissions are inherited via the group role — no custom grants are applied.

On Create, a deterministic username (incorporating the mode) and a random password are generated, the Postgres role is created with the appropriate group role membership, and the credentials are stored in the resource state. On subsequent reconciliation cycles, credentials are reused from the persisted state (no password regeneration).

When CredentialSource is nil, this is the canonical resource: it generates credentials and runs on the first node. When CredentialSource is non-nil, this is a per-node resource: it reads credentials from the canonical resource and runs on its own node's primary.

func (*ServiceUserRole) Create added in v0.7.0

func (r *ServiceUserRole) Create(ctx context.Context, rc *resource.Context) error

func (*ServiceUserRole) Delete added in v0.7.0

func (r *ServiceUserRole) Delete(ctx context.Context, rc *resource.Context) error

func (*ServiceUserRole) Dependencies added in v0.7.0

func (r *ServiceUserRole) Dependencies() []resource.Identifier

func (*ServiceUserRole) DiffIgnore added in v0.7.0

func (r *ServiceUserRole) DiffIgnore() []string

func (*ServiceUserRole) Executor added in v0.7.0

func (r *ServiceUserRole) Executor() resource.Executor

func (*ServiceUserRole) Identifier added in v0.7.0

func (r *ServiceUserRole) Identifier() resource.Identifier

func (*ServiceUserRole) Refresh added in v0.7.0

func (r *ServiceUserRole) Refresh(ctx context.Context, rc *resource.Context) error

func (*ServiceUserRole) ResourceVersion added in v0.7.0

func (r *ServiceUserRole) ResourceVersion() string

func (*ServiceUserRole) TypeDependencies added in v0.7.0

func (r *ServiceUserRole) TypeDependencies() []resource.Type

func (*ServiceUserRole) Update added in v0.7.0

func (r *ServiceUserRole) Update(ctx context.Context, rc *resource.Context) error

type ServiceVersions added in v0.7.0

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

func NewServiceVersions added in v0.7.0

func NewServiceVersions(cfg config.Config) *ServiceVersions

func (*ServiceVersions) GetServiceImage added in v0.7.0

func (sv *ServiceVersions) GetServiceImage(serviceType string, version string) (*ServiceImage, error)

GetServiceImage returns the full ServiceImage for the given service type and version.

func (*ServiceVersions) SupportedServiceVersions added in v0.7.0

func (sv *ServiceVersions) SupportedServiceVersions(serviceType string) ([]string, error)

type Switchover

type Switchover struct {
	HostID     string `json:"host_id"`
	InstanceID string `json:"instance_id"`
}

func (*Switchover) Create

func (s *Switchover) Create(ctx context.Context, rc *resource.Context) error

func (*Switchover) Delete

func (s *Switchover) Delete(ctx context.Context, rc *resource.Context) error

func (*Switchover) Dependencies

func (s *Switchover) Dependencies() []resource.Identifier

func (*Switchover) DiffIgnore

func (s *Switchover) DiffIgnore() []string

func (*Switchover) Executor

func (s *Switchover) Executor() resource.Executor

func (*Switchover) Identifier

func (s *Switchover) Identifier() resource.Identifier

func (*Switchover) Refresh

func (s *Switchover) Refresh(ctx context.Context, rc *resource.Context) error

func (*Switchover) ResourceVersion

func (s *Switchover) ResourceVersion() string

func (*Switchover) TypeDependencies added in v0.7.0

func (s *Switchover) TypeDependencies() []resource.Type

func (*Switchover) Update

func (s *Switchover) Update(ctx context.Context, rc *resource.Context) error

type Versions

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

func NewVersions

func NewVersions(cfg config.Config) *Versions

func (*Versions) Default

func (v *Versions) Default() *host.PgEdgeVersion

func (*Versions) GetImages

func (v *Versions) GetImages(version *host.PgEdgeVersion) (*Images, error)

func (*Versions) Supported

func (v *Versions) Supported() []*host.PgEdgeVersion

Jump to

Keyboard shortcuts

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