Documentation
¶
Overview ¶
Package persistence contains helpers for resolving Temporal persistence configuration, including datastore credentials sourced from Secrets.
Index ¶
- Constants
- 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 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 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 ¶
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 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 ¶
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. The passwordCommand reference takes precedence over a static password when both 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.