Documentation
¶
Overview ¶
Package persistence contains helpers for resolving Temporal persistence configuration, including datastore credentials sourced from Secrets.
Index ¶
- Constants
- Variables
- func BuildPostgresDSN(spec *temporalv1alpha1.SQLDatastoreSpec, password, dbName string) string
- func CompareSchemaVersions(a, b string) int
- func NormalizeSchemaVersion(v string) string
- func SchemaSatisfies(current, required string) bool
- type Backend
- type BackendFactory
- type InspectResult
- type JobInspectorBackend
- type Prober
- type ResolvedCredential
- type SQLProber
- type SchemaInspector
- type SecretResolver
- func (r *SecretResolver) ResolveCassandra(ctx context.Context, spec *temporalv1alpha1.CassandraDatastoreSpec) (ResolvedCredential, error)
- func (r *SecretResolver) ResolveElasticsearch(ctx context.Context, spec *temporalv1alpha1.ElasticsearchDatastoreSpec) (ResolvedCredential, error)
- func (r *SecretResolver) ResolveSQL(ctx context.Context, spec *temporalv1alpha1.SQLDatastoreSpec) (ResolvedCredential, error)
- func (r *SecretResolver) ResolveStore(ctx context.Context, store temporalv1alpha1.DatastoreSpec) (ResolvedCredential, error)
Constants ¶
const DefaultAzureOSSRDBMSScope = "https://ossrdbms-aad.database.windows.net/.default"
DefaultAzureOSSRDBMSScope is the default Entra token scope for Azure Database for PostgreSQL / MySQL Flexible Server.
const (
// KindSQL identifies a SQL backend.
KindSQL = "sql"
)
const VisibilityIndexTemplate = "temporal_visibility_v1_template"
VisibilityIndexTemplate is the name of the Temporal visibility index template.
Variables ¶
var ErrInspecting = errors.New("schema inspection in progress")
ErrInspecting is returned when schema inspection is still in progress.
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 ¶
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 ¶
NormalizeSchemaVersion strips an optional leading "v" from a schema version string (e.g. "v1.12" -> "1.12").
func SchemaSatisfies ¶
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 InspectResult ¶ added in v0.9.0
type InspectResult struct {
Reachable bool `json:"reachable"`
Version string `json:"version,omitempty"`
Error string `json:"error,omitempty"`
}
InspectResult is the JSON the inspector subcommand writes to the pod termination message: reachability + current schema version for one store.
func InspectSQL ¶ added in v0.9.0
func InspectSQL(ctx context.Context, spec *temporalv1alpha1.SQLDatastoreSpec, password, dbName string) InspectResult
InspectSQL probes a SQL store with the given password and reads its schema version, returning a structured result (never an error — failures are encoded in the result so the subcommand can emit them).
func (InspectResult) JSON ¶ added in v0.9.0
func (r InspectResult) JSON() string
type JobInspectorBackend ¶ added in v0.9.0
type JobInspectorBackend struct {
// contains filtered or unexported fields
}
JobInspectorBackend is a Backend implementation that ensures an inspector Job runs in the cluster and reads reachability + schema version from the Job's pod termination message.
func NewJobInspectorBackend ¶ added in v0.9.0
func NewJobInspectorBackend(c client.Client, dbName string, ensureJob func(ctx context.Context) (*batchv1.Job, error)) *JobInspectorBackend
NewJobInspectorBackend creates a Backend that uses a Job to inspect the datastore. The ensureJob closure is provided by the controller to avoid an import cycle.
func (*JobInspectorBackend) EnsureSchema ¶ added in v0.9.0
EnsureSchema returns (false, nil) for Job-based backends; the controller orchestrates setup/update.
func (*JobInspectorBackend) Kind ¶ added in v0.9.0
func (b *JobInspectorBackend) Kind() string
Kind returns "sql".
func (*JobInspectorBackend) Probe ¶ added in v0.9.0
func (b *JobInspectorBackend) Probe(ctx context.Context) error
Probe verifies the datastore is reachable.
func (*JobInspectorBackend) SchemaVersion ¶ added in v0.9.0
func (b *JobInspectorBackend) SchemaVersion(ctx context.Context) (string, error)
SchemaVersion returns the current schema version.
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. Password or PasswordCommand may be set for the server / schema Job.
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 ¶
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.
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 ¶
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 ¶
func (r *SecretResolver) ResolveCassandra(ctx context.Context, spec *temporalv1alpha1.CassandraDatastoreSpec) (ResolvedCredential, error)
ResolveCassandra resolves the credential for a Cassandra datastore.
func (*SecretResolver) ResolveElasticsearch ¶
func (r *SecretResolver) ResolveElasticsearch(ctx context.Context, spec *temporalv1alpha1.ElasticsearchDatastoreSpec) (ResolvedCredential, error)
ResolveElasticsearch resolves the credential for an Elasticsearch datastore.
func (*SecretResolver) ResolveSQL ¶
func (r *SecretResolver) ResolveSQL(ctx context.Context, spec *temporalv1alpha1.SQLDatastoreSpec) (ResolvedCredential, error)
ResolveSQL resolves the credential for a SQL datastore. PasswordCommand takes precedence over a static password when both password refs are set.
func (*SecretResolver) ResolveStore ¶
func (r *SecretResolver) ResolveStore(ctx context.Context, store temporalv1alpha1.DatastoreSpec) (ResolvedCredential, error)
ResolveStore resolves the credential for whichever backend a DatastoreSpec uses.