patroni

package
v5.1.2-bit Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package patroni provides clients, utilities and resources for configuring and interacting with Patroni inside of a PostgreSQL cluster

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClusterBootstrapped

func ClusterBootstrapped(postgresCluster *v1beta1.PostgresCluster) bool

ClusterBootstrapped returns a bool indicating whether or not Patroni has successfully bootstrapped the PostgresCluster

func ClusterConfigMap

func ClusterConfigMap(ctx context.Context,
	inCluster *v1beta1.PostgresCluster,
	inHBAs postgres.HBAs,
	inParameters postgres.Parameters,
	outClusterConfigMap *corev1.ConfigMap,
) error

ClusterConfigMap populates the shared ConfigMap with fields needed to run Patroni.

func DynamicConfiguration

func DynamicConfiguration(
	cluster *v1beta1.PostgresCluster,
	configuration map[string]interface{},
	pgHBAs postgres.HBAs, pgParameters postgres.Parameters,
) map[string]interface{}

DynamicConfiguration combines configuration with some PostgreSQL settings and returns a value that can be marshaled to JSON.

func InstanceCertificates

func InstanceCertificates(ctx context.Context,
	inRoot pki.Certificate, inDNS pki.Certificate,
	inDNSKey pki.PrivateKey, outInstanceCertificates *corev1.Secret,
) error

InstanceCertificates populates the shared Secret with certificates needed to run Patroni.

func InstanceConfigMap

func InstanceConfigMap(ctx context.Context,
	inCluster *v1beta1.PostgresCluster,
	inInstanceSpec *v1beta1.PostgresInstanceSetSpec,
	outInstanceConfigMap *corev1.ConfigMap,
) error

InstanceConfigMap populates the shared ConfigMap with fields needed to run Patroni.

func InstancePod

func InstancePod(ctx context.Context,
	inCluster *v1beta1.PostgresCluster,
	inClusterConfigMap *corev1.ConfigMap,
	inClusterPodService *corev1.Service,
	inPatroniLeaderService *corev1.Service,
	inInstanceSpec *v1beta1.PostgresInstanceSetSpec,
	inInstanceCertificates *corev1.Secret,
	inInstanceConfigMap *corev1.ConfigMap,
	outInstancePod *corev1.PodTemplateSpec,
) error

InstancePod populates a PodTemplateSpec with the fields needed to run Patroni. The database container must already be in the template.

func Permissions

func Permissions(cluster *v1beta1.PostgresCluster) []rbacv1.PolicyRule

Permissions returns the RBAC rules Patroni needs for cluster.

func PodIsStandbyLeader

func PodIsStandbyLeader(pod metav1.Object) bool

PodIsStandbyLeader returns whether or not pod is currently acting as a "standby_leader".

func PodRequiresRestart

func PodRequiresRestart(pod metav1.Object) bool

PodRequiresRestart returns whether or not PostgreSQL inside pod has (pending) parameter changes that require a PostgreSQL restart.

Types

type API

type API interface {
	// ChangePrimaryAndWait tries to demote the current Patroni leader. It
	// returns true when an election completes successfully. When Patroni is
	// paused, next cannot be blank.
	ChangePrimaryAndWait(ctx context.Context, current, next string) (bool, error)

	// ReplaceConfiguration replaces Patroni's entire dynamic configuration.
	ReplaceConfiguration(ctx context.Context, configuration map[string]interface{}) error
}

API defines a general interface for interacting with the Patroni API.

type Executor

type Executor func(
	ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error

Executor implements API by calling "patronictl".

Example (ExecCmd)

This example demonstrates how Executor can work with exec.Cmd.

_ = Executor(func(
	ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
	// #nosec G204 Nothing calls the function defined in this example.
	cmd := exec.CommandContext(ctx, command[0], command[1:]...)
	cmd.Stdin, cmd.Stdout, cmd.Stderr = stdin, stdout, stderr
	return cmd.Run()
})
Output:

func (Executor) ChangePrimaryAndWait

func (exec Executor) ChangePrimaryAndWait(
	ctx context.Context, current, next string,
) (bool, error)

ChangePrimaryAndWait tries to demote the current Patroni leader by calling "patronictl". It returns true when an election completes successfully. It waits up to two "loop_wait" or until an error occurs. When Patroni is paused, next cannot be blank. Similar to the "POST /switchover" REST endpoint.

func (Executor) FailoverAndWait

func (exec Executor) FailoverAndWait(
	ctx context.Context, target string,
) (bool, error)

FailoverAndWait tries to change the current Patroni leader by calling "patronictl". It returns true when an election completes successfully. It waits up to two "loop_wait" or until an error occurs. When Patroni is paused, next cannot be blank. Similar to the "POST /switchover" REST endpoint. The "patronictl failover" variant does not require the current master to be passed as a flag.

func (Executor) GetTimeline

func (exec Executor) GetTimeline(ctx context.Context) (int64, error)

GetTimeline gets the patronictl status and returns the timeline, currently the only information required by PGO. Returns zero if it runs into errors or cannot find a running Leader pod to get the up-to-date timeline from.

func (Executor) ReplaceConfiguration

func (exec Executor) ReplaceConfiguration(
	ctx context.Context, configuration map[string]interface{},
) error

ReplaceConfiguration replaces Patroni's entire dynamic configuration by calling "patronictl". Similar to the "POST /switchover" REST endpoint.

func (Executor) RestartPendingMembers

func (exec Executor) RestartPendingMembers(ctx context.Context, role, scope string) error

RestartPendingMembers looks up Patroni members with role in scope and restarts those that have a pending restart.

func (Executor) SwitchoverAndWait

func (exec Executor) SwitchoverAndWait(
	ctx context.Context, target string,
) (bool, error)

SwitchoverAndWait tries to change the current Patroni leader by calling "patronictl". It returns true when an election completes successfully. It waits up to two "loop_wait" or until an error occurs. When Patroni is paused, next cannot be blank. Similar to the "POST /switchover" REST endpoint. The "patronictl switchover" variant does not require the current master to be passed as a flag.

Jump to

Keyboard shortcuts

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