controller

package
v1.26.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: Apache-2.0 Imports: 60 Imported by: 0

Documentation

Overview

Package controller contains the functions in PostgreSQL instance manager that reacts to changes to the Cluster resource.

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedDatabaseObjectReconciliation = fmt.Errorf("database object reconciliation failed")

ErrFailedDatabaseObjectReconciliation is raised when a database object failed to reconcile

View Source
var RetryUntilWalReceiverDown = wait.Backoff{
	Duration: 1 * time.Second,

	Steps: math.MaxInt32,
}

RetryUntilWalReceiverDown is the default retry configuration that is used to wait for the WAL receiver process to be down

Functions

This section is empty.

Types

type DatabaseReconciler added in v1.25.0

type DatabaseReconciler struct {
	client.Client
	Scheme *runtime.Scheme
	// contains filtered or unexported fields
}

DatabaseReconciler reconciles a Database object

func NewDatabaseReconciler added in v1.25.0

func NewDatabaseReconciler(
	mgr manager.Manager,
	instance *postgres.Instance,
) *DatabaseReconciler

NewDatabaseReconciler creates a new database reconciler

func (*DatabaseReconciler) GetCluster added in v1.25.0

func (r *DatabaseReconciler) GetCluster(ctx context.Context) (*apiv1.Cluster, error)

GetCluster gets the managed cluster through the client

func (*DatabaseReconciler) Reconcile added in v1.25.0

func (r *DatabaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile is the database reconciliation loop

func (*DatabaseReconciler) SetupWithManager added in v1.25.0

func (r *DatabaseReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

type InstanceReconciler

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

InstanceReconciler reconciles the status of the Cluster resource with the one of this PostgreSQL instance. Also, the configuration in the ConfigMap is applied when needed

func NewInstanceReconciler

func NewInstanceReconciler(
	instance *postgres.Instance,
	client ctrl.Client,
	metricsExporter *metricserver.Exporter,
) *InstanceReconciler

NewInstanceReconciler creates a new instance reconciler

func (*InstanceReconciler) GetClient

func (r *InstanceReconciler) GetClient() ctrl.Client

GetClient returns the dynamic client that is being used for a certain reconciler

func (*InstanceReconciler) GetCluster

func (r *InstanceReconciler) GetCluster(ctx context.Context) (*apiv1.Cluster, error)

GetCluster gets the managed cluster through the client

func (*InstanceReconciler) GetExecutedCondition

func (r *InstanceReconciler) GetExecutedCondition() *concurrency.Executed

GetExecutedCondition returns the condition that can be checked in order to be sure initialization has been done

func (*InstanceReconciler) GetSecret

func (r *InstanceReconciler) GetSecret(ctx context.Context, name string) (*corev1.Secret, error)

GetSecret will get a named secret in the instance namespace

func (*InstanceReconciler) Instance

func (r *InstanceReconciler) Instance() *postgres.Instance

Instance get the PostgreSQL instance that this reconciler is working on

func (*InstanceReconciler) IsDBUp

func (r *InstanceReconciler) IsDBUp(ctx context.Context) error

IsDBUp checks whether the superuserdb is reachable and returns an error if that's not the case

func (*InstanceReconciler) Reconcile

Reconcile is the main reconciliation loop for the instance TODO this function needs to be refactor

func (*InstanceReconciler) ReconcileTablespaces added in v1.22.0

func (r *InstanceReconciler) ReconcileTablespaces(
	ctx context.Context,
	cluster *apiv1.Cluster,
) error

ReconcileTablespaces ensures the mount points created for the tablespaces are there, and creates a subdirectory in each of them, which will therefore be owned by the `postgres` user (rather than `root` as the mount point), as required in order to hold PostgreSQL Tablespaces

func (*InstanceReconciler) ReconcileWalStorage added in v1.18.2

func (r *InstanceReconciler) ReconcileWalStorage(ctx context.Context) error

ReconcileWalStorage moves the files from PGDATA/pg_wal to the volume attached, if exists, and creates a symlink for it

func (*InstanceReconciler) RefreshSecrets

func (r *InstanceReconciler) RefreshSecrets(
	ctx context.Context,
	cluster *apiv1.Cluster,
) bool

RefreshSecrets is called when the PostgreSQL secrets are changed and will refresh the contents of the file inside the Pod, without reloading the actual PostgreSQL instance.

It returns a boolean flag telling if something changed. Usually the invoker will check that flag and reload the PostgreSQL instance it is up.

This function manages its own errors by logging them, so the user cannot easily tell if the operation has been done completely. The rationale behind this is:

  1. when invoked at the startup of the instance manager, PostgreSQL is not up. If this raise an error, then PostgreSQL won't be able to start correctly (TLS certs are missing, i.e.), making no difference between returning an error or not

  2. when invoked inside the reconciliation loop, if the operation raise an error, it's pointless to retry. The only way to recover from such an error is wait for the CNPG operator to refresh the resource version of the secrets to be used, and in that case a reconciliation loop will be started again.

type PublicationReconciler added in v1.25.0

type PublicationReconciler struct {
	client.Client
	Scheme *runtime.Scheme
	// contains filtered or unexported fields
}

PublicationReconciler reconciles a Publication object

func NewPublicationReconciler added in v1.25.0

func NewPublicationReconciler(
	mgr manager.Manager,
	instance *postgres.Instance,
) *PublicationReconciler

NewPublicationReconciler creates a new publication reconciler

func (*PublicationReconciler) GetCluster added in v1.25.0

func (r *PublicationReconciler) GetCluster(ctx context.Context) (*apiv1.Cluster, error)

GetCluster gets the managed cluster through the client

func (*PublicationReconciler) Reconcile added in v1.25.0

func (r *PublicationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile is part of the main kubernetes reconciliation loop which aims to move the current state of the cluster closer to the desired state. TODO(user): Modify the Reconcile function to compare the state specified by the Publication object against the actual cluster state, and then perform operations to make the cluster state reflect the state specified by the user.

For more details, check Reconcile and its Result here: - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.18.4/pkg/reconcile

func (*PublicationReconciler) SetupWithManager added in v1.25.0

func (r *PublicationReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

type SubscriptionReconciler added in v1.25.0

type SubscriptionReconciler struct {
	client.Client
	Scheme *runtime.Scheme
	// contains filtered or unexported fields
}

SubscriptionReconciler reconciles a Subscription object

func NewSubscriptionReconciler added in v1.25.0

func NewSubscriptionReconciler(
	mgr manager.Manager,
	instance *postgres.Instance,
) *SubscriptionReconciler

NewSubscriptionReconciler creates a new subscription reconciler

func (*SubscriptionReconciler) GetCluster added in v1.25.0

func (r *SubscriptionReconciler) GetCluster(ctx context.Context) (*apiv1.Cluster, error)

GetCluster gets the managed cluster through the client

func (*SubscriptionReconciler) Reconcile added in v1.25.0

func (r *SubscriptionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile is the subscription reconciliation loop

func (*SubscriptionReconciler) SetupWithManager added in v1.25.0

func (r *SubscriptionReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager

Directories

Path Synopsis
Package externalservers contains the reconciler of external servers, taking care of enabling connectivity to every server defined in the relative section of the CR
Package externalservers contains the reconciler of external servers, taking care of enabling connectivity to every server defined in the relative section of the CR
Package roles contains the code needed to reconcile roles with PostgreSQL
Package roles contains the code needed to reconcile roles with PostgreSQL
slots
infrastructure
Package infrastructure contains the structs and interfaces needed to manage replication slots
Package infrastructure contains the structs and interfaces needed to manage replication slots
reconciler
Package reconciler contains all the logic needed to reconcile replication slots
Package reconciler contains all the logic needed to reconcile replication slots
runner
Package runner contains the runner that replicates slots from the primary to the replicas
Package runner contains the runner that replicates slots from the primary to the replicas
Package tablespaces contains the runner to declarative tablespace
Package tablespaces contains the runner to declarative tablespace
infrastructure
Package infrastructure contains the structs and interfaces needed to manage declarative tablespace
Package infrastructure contains the structs and interfaces needed to manage declarative tablespace

Jump to

Keyboard shortcuts

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