persistence

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package persistence contains helpers for resolving Temporal persistence configuration, including datastore credentials sourced from Secrets.

Index

Constants

View Source
const VisibilityIndexTemplate = "temporal_visibility_v1_template"

VisibilityIndexTemplate is the name of the Temporal visibility index template.

Variables

This section is empty.

Functions

func BuildPostgresDSN

func BuildPostgresDSN(spec *temporalv1alpha1.SQLDatastoreSpec, password, dbName string) string

BuildPostgresDSN builds a Postgres connection string from a SQL datastore spec and a resolved password. The database name can be overridden (e.g. to target the visibility database) via dbName; when empty, spec.Database is used.

func CompareSchemaVersions

func CompareSchemaVersions(a, b string) int

CompareSchemaVersions compares two dotted numeric schema versions. It returns -1 if a < b, 0 if equal, and 1 if a > b. Non-numeric or missing components are treated as zero. An empty string is treated as the lowest possible version.

func NormalizeSchemaVersion

func NormalizeSchemaVersion(v string) string

NormalizeSchemaVersion strips an optional leading "v" from a schema version string (e.g. "v1.12" -> "1.12").

func SchemaSatisfies

func SchemaSatisfies(current, required string) bool

SchemaSatisfies reports whether a current schema version meets or exceeds the required minimum. An empty current version never satisfies the requirement.

Types

type Backend

type Backend interface {
	// Probe verifies the datastore is reachable.
	Probe(ctx context.Context) error
	// SchemaVersion returns the current schema (or index-template) version. An
	// empty string means no schema is present yet.
	SchemaVersion(ctx context.Context) (string, error)
	// EnsureSchema applies schema inline when the backend manages schema itself
	// (Elasticsearch index templates). It returns inline=true when it handled
	// the schema; Job-based backends (SQL, Cassandra) return inline=false and do
	// nothing, leaving Job orchestration to the caller.
	EnsureSchema(ctx context.Context, minVersion string) (inline bool, err error)
	// Kind returns "sql", "cassandra", or "elasticsearch".
	Kind() string
}

Backend abstracts a Temporal datastore (SQL, Cassandra, or Elasticsearch) for reachability probing and schema management.

func DefaultBackendFactory

func DefaultBackendFactory(store temporalv1alpha1.DatastoreSpec, cred ResolvedCredential, dbName string) (Backend, error)

DefaultBackendFactory dispatches on the configured datastore backend.

type BackendFactory

type BackendFactory func(store temporalv1alpha1.DatastoreSpec, cred ResolvedCredential, dbName string) (Backend, error)

BackendFactory builds a Backend for a datastore spec and resolved credential.

type Prober

type Prober interface {
	// Probe opens a connection described by dsn, performs a trivial liveness
	// query, and returns an error if the datastore is unreachable.
	Probe(ctx context.Context, dsn string) error
}

Prober verifies that a datastore is reachable.

type ResolvedCredential

type ResolvedCredential struct {
	// Password is a static password (password-auth).
	Password string
	// PasswordCommand is a command that emits a short-lived credential
	// (Temporal 1.31+ IAM auth). When set, Password is empty.
	PasswordCommand string
}

ResolvedCredential is the resolved authentication material for a datastore. Exactly one of Password or PasswordCommand is set.

type SQLProber

type SQLProber struct {
	// Timeout bounds each probe/query. Defaults to 5s when zero.
	Timeout time.Duration
}

SQLProber is the default database/sql-backed Prober and SchemaInspector for Postgres.

func (SQLProber) CurrentSchemaVersion

func (p SQLProber) CurrentSchemaVersion(ctx context.Context, dsn, dbName string) (string, error)

CurrentSchemaVersion implements SchemaInspector for Postgres. It reads the Temporal schema_version table; if that table does not exist, it returns an empty version to signal that a bootstrap (setup-schema) is required.

func (SQLProber) Probe

func (p SQLProber) Probe(ctx context.Context, dsn string) error

Probe implements Prober for Postgres.

type SchemaInspector

type SchemaInspector interface {
	// CurrentSchemaVersion returns the current schema version recorded for the
	// given logical database. An empty string means no schema is present yet
	// (bootstrap required).
	CurrentSchemaVersion(ctx context.Context, dsn, dbName string) (string, error)
}

SchemaInspector reports the current schema version of a datastore.

type SecretResolver

type SecretResolver struct {
	Client    client.Client
	Namespace string
}

SecretResolver resolves datastore password references from Secrets in the cluster's namespace.

func NewSecretResolver

func NewSecretResolver(c client.Client, namespace string) *SecretResolver

NewSecretResolver returns a SecretResolver bound to a namespace.

func (*SecretResolver) ResolveCassandra

ResolveCassandra resolves the credential for a Cassandra datastore.

func (*SecretResolver) ResolveElasticsearch

ResolveElasticsearch resolves the credential for an Elasticsearch datastore.

func (*SecretResolver) ResolveSQL

ResolveSQL resolves the credential for a SQL datastore. The passwordCommand reference takes precedence over a static password when both are set.

func (*SecretResolver) ResolveStore

ResolveStore resolves the credential for whichever backend a DatastoreSpec uses.

Jump to

Keyboard shortcuts

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