cluster

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package cluster holds the cluster CRD logic and definitions A cluster is comprised of a primary service, replica service, primary deployment, and replica deployment

Package cluster holds the cluster CRD logic and definitions A cluster is comprised of a primary service, replica service, primary deployment, and replica deployment

Package cluster holds the cluster CRD logic and definitions A cluster is comprised of a primary service, replica service, primary deployment, and replica deployment

Index

Constants

View Source
const ReplicaSuffix = "-replica"

ReplicaSuffix is the suffix of the replica Service name

Variables

View Source
var (
	// ErrStandbyNotAllowed contains the error message returned when an API call is not
	// permitted because it involves a cluster that is in standby mode
	ErrStandbyNotAllowed = errors.New("Action not permitted because standby mode is enabled")
	// ErrStandbyNotEnabled defines the error that is thrown when
	// standby mode is not enabled but a standby action was attempted
	ErrStandbyNotEnabled = errors.New("Standby mode not enabled")
	// ErrClusterNotShutdown defines the error that is thrown when an action cannot
	// proceed because the cluster is not in standby mode
	ErrClusterNotShutdown = errors.New("Cluster not in shutdown status")
)

Functions

func AddBootstrapRepo

func AddBootstrapRepo(clientset kubernetes.Interface, cluster *crv1.Pgcluster) (repoCreated bool, err error)

AddBootstrapRepo creates a pgBackRest repository and associated service to use when bootstrapping a cluster from an existing data source. If an existing repo is detected and is being used to bootstrap another cluster, then an error is returned. If an existing repo is detected and is not associated with a bootstrap job (but rather an active cluster), then no action is taken and the function resturns. Also, in addition to returning an error in the event an error is encountered, the function also returns a 'repoCreated' bool that specifies whether or not a repo was actually created.

func AddClusterBase

func AddClusterBase(clientset kubeapi.Interface, cl *crv1.Pgcluster, namespace string)

func AddClusterBootstrap

func AddClusterBootstrap(clientset kubeapi.Interface, cluster *crv1.Pgcluster) error

AddClusterBootstrap creates the resources needed to bootstrap a new cluster from an existing data source. Specifically, this function creates the bootstrap job that will be run to bootstrap the cluster, along with supporting resources (e.g. ConfigMaps and volumes).

func AddExporter

func AddExporter(clientset kubernetes.Interface, restconfig *rest.Config, cluster *crv1.Pgcluster) error

AddExporter ensures that a PostgreSQL cluster is able to undertake the actions required by the "crunchy-postgres-exporter", i.e.

  • enable a service port so scrapers can access the metrics
  • it can authenticate as the "ccp_monitoring" user; manages the Secret as well
  • all of the monitoring views and functions are available

func AddPGBadger

func AddPGBadger(clientset kubernetes.Interface, restconfig *rest.Config, cluster *crv1.Pgcluster) error

AddPGBadger ensures that a PostgreSQL cluster is able to undertake the actions required by the "crunchy-badger", i.e. updating the Service. This executes regardless if this is a standby cluster.

This does not modify the Deployment that has the pgBadger sidecar. That is handled by the "UpdatePGBadgerSidecar" function, so it can be handled as part of a rolling update.

func AddPgAdmin

func AddPgAdmin(
	clientset kubeapi.Interface,
	restconfig *rest.Config,
	cluster *crv1.Pgcluster,
	storageClass *crv1.PgStorageSpec) error

AddPgAdmin contains the various functions that are used to add a pgAdmin Deployment to a PostgreSQL cluster

Any returned error is logged in the calling function

func AddPgAdminFromPgTask

func AddPgAdminFromPgTask(clientset kubeapi.Interface, restconfig *rest.Config, task *crv1.Pgtask)

AddPgAdminFromPgTask is a method that helps to bring up the pgAdmin deployment that sits alongside a PostgreSQL cluster

func AddPgbouncer

func AddPgbouncer(clientset kubernetes.Interface, restconfig *rest.Config, cluster *crv1.Pgcluster) error

AddPgbouncer contains the various functions that are used to add a pgBouncer Deployment to a PostgreSQL cluster

Any returned error is logged in the calling function

func AddUpgrade

func AddUpgrade(clientset kubeapi.Interface, upgrade *crv1.Pgtask, namespace string)

AddUpgrade implements the upgrade workflow in accordance with the received pgtask the general process is outlined below: 1) get the existing pgcluster CRD instance that matches the name provided in the pgtask 2) Patch the existing services 3) Determine the current Primary PVC 4) Scale down existing replicas and store the number for recreation 5) Delete the various resources that will need to be recreated 6) Recreate the BackrestRepo secret, since the key encryption algorithm has been updated 7) Update the existing pgcluster CRD instance to match the current version 8) Submit the pgcluster CRD for recreation

func BootstrapPgAdminUsers

func BootstrapPgAdminUsers(
	clientset kubernetes.Interface,
	restconfig *rest.Config,
	cluster *crv1.Pgcluster) error

func CreateExporterSecret

func CreateExporterSecret(clientset kubernetes.Interface, cluster *crv1.Pgcluster) (string, error)

CreateExporterSecret create a secret used by the exporter containing the user credientials. Sees if a Secret already exists and if it does, uses that. Otherwise, it will generate the password. Returns an error if it fails.

func CreateService

func CreateService(clientset kubernetes.Interface, fields *ServiceTemplateFields, namespace string) error

CreateService ...

func DeletePgAdmin

func DeletePgAdmin(clientset kubeapi.Interface, restconfig *rest.Config, cluster *crv1.Pgcluster) error

DeletePgAdmin contains the various functions that are used to delete a pgAdmin Deployment for a PostgreSQL cluster

Any errors that are returned should be logged in the calling function, though some logging occurs in this function as well

func DeletePgAdminFromPgTask

func DeletePgAdminFromPgTask(clientset kubeapi.Interface, restconfig *rest.Config, task *crv1.Pgtask)

DeletePgAdminFromPgTask is effectively a legacy method that helps to delete the pgAdmin deployment that sits alongside a PostgreSQL cluster

func DeletePgbouncer

func DeletePgbouncer(clientset kubernetes.Interface, restconfig *rest.Config, cluster *crv1.Pgcluster) error

DeletePgbouncer contains the various functions that are used to delete a pgBouncer Deployment for a PostgreSQL cluster

Note that "uninstall" deletes all of the objects that are added to the PostgreSQL database, such as the "pgbouncer" user. This is not normally neded to be done as pgbouncer user is disabled, but if the user wishes to be thorough they can do this

Any errors that are returned should be logged in the calling function, though some logging occurs in this function as well

func DeleteReplica

func DeleteReplica(clientset kubernetes.Interface, cl *crv1.Pgreplica, namespace string) error

DeleteReplica ...

func DisableStandby

func DisableStandby(clientset kubernetes.Interface, cluster crv1.Pgcluster) error

DisableStandby disables standby mode for the cluster

func EnableStandby

func EnableStandby(clientset kubernetes.Interface, cluster crv1.Pgcluster) error

EnableStandby enables standby mode for the cluster

func PublishUpgradeEvent

func PublishUpgradeEvent(eventType string, namespace string, task *crv1.Pgtask, errorMessage string)

PublishUpgradeEvent lets one publish an event related to the upgrade process

func RemoveExporter

func RemoveExporter(clientset kubernetes.Interface, restconfig *rest.Config, cluster *crv1.Pgcluster) error

RemoveExporter disables the ability for a PostgreSQL cluster to use the exporter functionality. In particular this function:

  • disallows the login of the monitoring user (ccp_monitoring)
  • removes the Secret that contains the ccp_monitoring user credentials
  • removes the port on the cluster Service

This does not modify the Deployment that has the exporter sidecar. That is handled by the "UpdateExporter" function, so it can be handled as part of a rolling update

func RemovePGBadger

func RemovePGBadger(clientset kubernetes.Interface, restconfig *rest.Config, cluster *crv1.Pgcluster) error

RemovePGBadger disables the ability for a PostgreSQL cluster to run a pgBadger cluster.

This does not modify the Deployment that has the pgBadger sidecar. That is handled by the "UpdatePGBadgerSidecar" function, so it can be handled as part of a rolling update.

func ResizeClusterPVC added in v0.2.0

func ResizeClusterPVC(clientset kubeapi.Interface, cluster *crv1.Pgcluster, deployment *apps_v1.Deployment) error

ResizeClusterPVC allows for the resizing of all the PVCs across the cluster. This draws a distinction from PVCs in the cluster that may be sized independently, e.g. replicas.

If there are instances that are sized differently than the primary, we ensure that the size is kept consistent. In other words:

  • If instance is sized consistently with the cluster, we will resize it.
  • If the instance has its size set independently, we will check to see if that size is smaller than the cluster PVC resize. if it is smaller, then we will size it to match the cluster PVC

func ResizePGAdminPVC added in v0.2.0

func ResizePGAdminPVC(clientset kubeapi.Interface, cluster *crv1.Pgcluster) error

ResizePGAdminPVC resizes the pgAdmin PVC. To do this, the pgAdmin Deployment is scaled down to ensure the PVC unmounted, and then scaled back up. This will ensure that the new PVC size is applied to pgAdmin.

func ResizeWALPVC added in v0.2.0

func ResizeWALPVC(clientset kubeapi.Interface, cluster *crv1.Pgcluster, deployment *apps_v1.Deployment) error

ResizeWALPVC allows for the resizing of the PVCs where WAL are stored.

func RollingUpdate

func RollingUpdate(clientset kubeapi.Interface, restConfig *rest.Config,
	cluster *crv1.Pgcluster, rescale bool,
	updateFunc func(kubeapi.Interface, *crv1.Pgcluster, *appsv1.Deployment) error) error

RollingUpdate performs a type of "rolling update" on a series of Deployments of a PostgreSQL cluster in an attempt to minimize downtime.

The functions take a function that serves to update the contents of a Deployment.

The rolling update is performed as such:

  1. Each replica is updated. A replica is shut down and changes are applied The Operator waits until the replica is back online (and/or a time period) And moves on to the next one
  2. A controlled switchover is performed. The Operator chooses the best candidate replica for the switch over.
  3. The former primary is then shut down and updated.

If this is not a HA cluster, then the Deployment is just singly restarted

If "rescale" is selected, then each Deployment is scaled to 0 after the Postgres cluster is shut down, but before the changes are applied. This is normally not needed, but invoked on operations where an object must be completely unconsumed by a resource (e.g. during a change to a PVC).

Erroring during this process can be fun. If an error occurs within the middle of a rolling update, in order to avoid placing the cluster in an indeterminate state, most errors are just logged for later troubleshooting

func RotateExporterPassword

func RotateExporterPassword(clientset kubernetes.Interface, restconfig *rest.Config, cluster *crv1.Pgcluster) error

RotateExporterPassword rotates the password for the monitoring PostgreSQL user

func RotatePgBouncerPassword

func RotatePgBouncerPassword(clientset kubernetes.Interface, restconfig *rest.Config, cluster *crv1.Pgcluster) error

RotatePgBouncerPassword rotates the password for a pgBouncer PostgreSQL user, which involves updating the password in the PostgreSQL cluster as well as the users secret that is available in the pgbouncer Pod

func ScaleBase

func ScaleBase(clientset kubeapi.Interface, replica *crv1.Pgreplica, namespace string)

ScaleBase ...

func ScaleDownBase

func ScaleDownBase(clientset kubeapi.Interface, replica *crv1.Pgreplica, namespace string)

ScaleDownBase ...

func SetReplicaNumber

func SetReplicaNumber(pgcluster *crv1.Pgcluster, numReplicas string)

SetReplicaNumber sets the pgcluster's replica value based off of the number of pgreplicas discovered during the deletion process. This is necessary because the pgcluser will only include the number of replicas created when the pgcluster was first generated (e.g. pgo create cluster hippo --replica-count=2) but will not included any replicas created using the 'pgo scale' command

func ShutdownCluster

func ShutdownCluster(clientset kubeapi.Interface, cluster crv1.Pgcluster) error

ShutdownCluster is responsible for shutting down a cluster that is currently running. This includes changing the replica count for all clusters to 0, and then updating the pgcluster with a shutdown status.

func StartupCluster

func StartupCluster(clientset kubernetes.Interface, cluster crv1.Pgcluster) error

StartupCluster is responsible for starting a cluster that was previsouly shutdown. This includes changing the replica count for all clusters to 1, and then updating the pgcluster with a shutdown status.

func StopPostgreSQLInstance added in v0.2.0

func StopPostgreSQLInstance(clientset kubernetes.Interface, restConfig *rest.Config, deployment apps_v1.Deployment) error

stopPostgreSQLInstance is a proxy function for the main StopPostgreSQLInstance function, as it preps a Deployment to have its PostgreSQL instance shut down. This helps to ensure that a PostgreSQL instance will launch and not be in crash recovery mode

func ToggleTLS added in v0.2.0

func ToggleTLS(clientset kubeapi.Interface, cluster *crv1.Pgcluster) error

ToggleTLS will toggle the appropriate Postgres configuration in a DCS file around the TLS settings

func UninstallPgBouncer

func UninstallPgBouncer(clientset kubernetes.Interface, restconfig *rest.Config, cluster *crv1.Pgcluster) error

UninstallPgBouncer uninstalls the "pgbouncer" user and other management objects from the PostgreSQL cluster

func UpdateAnnotations

func UpdateAnnotations(clientset kubeapi.Interface, cluster *crv1.Pgcluster, deployment *apps_v1.Deployment) error

UpdateAnnotations updates the annotations in the "template" portion of a PostgreSQL deployment

func UpdateBackrestS3 added in v0.2.0

func UpdateBackrestS3(clientset kubeapi.Interface, cluster *crv1.Pgcluster, deployment *apps_v1.Deployment) error

UpdateBackrestS3 updates any pgBackRest settings that may have been updated. Presently this is just the bucket name.

func UpdateClusterService

func UpdateClusterService(clientset kubernetes.Interface, cluster *crv1.Pgcluster) error

UpdateClusterService updates parameters (really just one) on a Service that represents a PostgreSQL cluster

func UpdateExporterSidecar

func UpdateExporterSidecar(clientset kubeapi.Interface, cluster *crv1.Pgcluster, deployment *appsv1.Deployment) error

UpdateExporterSidecar either adds or emoves the metrics sidcar from the cluster. This is meant to be used as a rolling update callback function

func UpdateLabels added in v0.2.0

func UpdateLabels(clientset kubeapi.Interface, cluster *crv1.Pgcluster, deployment *apps_v1.Deployment) error

UpdateLabels updates the labels on the template to match those of the custom labels

func UpdatePGAdminImage

func UpdatePGAdminImage(clientset kubernetes.Interface, cluster *crv1.Pgcluster) error

func UpdatePGBadgerSidecar

func UpdatePGBadgerSidecar(clientset kubeapi.Interface, cluster *crv1.Pgcluster, deployment *appsv1.Deployment) error

UpdatePGBadgerSidecar either adds or emoves the pgBadger sidcar from the cluster. This is meant to be used as a rolling update callback function

func UpdatePGImage

func UpdatePGImage(clientset kubernetes.Interface, cluster *crv1.Pgcluster) error

func UpdatePgBouncerAnnotations

func UpdatePgBouncerAnnotations(clientset kubernetes.Interface, cluster *crv1.Pgcluster,
	annotations map[string]string) error

UpdatePgBouncerAnnotations updates the annotations in the "template" portion of a pgBouncer deployment

func UpdatePgBouncerService

func UpdatePgBouncerService(clientset kubernetes.Interface, cluster *crv1.Pgcluster) error

UpdatePgBouncerService updates the information on the pgBouncer Service. Specifically, it determines if it should use the information from the parent PostgreSQL cluster or any specific overrides that are available in the pgBouncer spec.

func UpdatePgbouncer

func UpdatePgbouncer(clientset kubernetes.Interface, restconfig *rest.Config, oldCluster, newCluster *crv1.Pgcluster) error

UpdatePgbouncer contains the various functions that are used to perform updates to the pgBouncer deployment for a cluster, such as rotating a password

Any errors that are returned should be logged in the calling function, though some logging occurs in this function as well

func UpdateReplicaService

func UpdateReplicaService(clientset kubernetes.Interface, cluster *crv1.Pgcluster, replica *crv1.Pgreplica) error

UpdateClusterService updates parameters (really just one) on a Service that represents a PostgreSQL replca instance

func UpdateResources

func UpdateResources(clientset kubeapi.Interface, cluster *crv1.Pgcluster, deployment *apps_v1.Deployment) error

UpdateResources updates the PostgreSQL instance Deployments to reflect the update resources (i.e. CPU, memory)

func UpdateTLS added in v0.2.0

func UpdateTLS(clientset kubeapi.Interface, cluster *crv1.Pgcluster, deployment *apps_v1.Deployment) error

UpdateTLS updates whether or not TLS is enabled, and if certain attributes are set (i.e. TLSOnly), ensures that the changes are properly reflected on the containers

func UpdateTablespaces

func UpdateTablespaces(clientset kubeapi.Interface, cluster *crv1.Pgcluster, deployment *apps_v1.Deployment) error

UpdateTablespaces updates the PostgreSQL instance Deployments to update what tablespaces are mounted.

func UpdateTolerations

func UpdateTolerations(clientset kubeapi.Interface, cluster *crv1.Pgcluster, deployment *apps_v1.Deployment) error

UpdateTolerations updates the Toleration definition for a Deployment. However, we have to check if the Deployment is based on a pgreplica Spec -- if it is, we need to determine if there are any instance specific tolerations defined on that

Types

type PgbouncerConfFields

type PgbouncerConfFields struct {
	PG_PRIMARY_SERVICE_NAME string
	PG_PORT                 string
	TLSEnabled              bool
}

type PgbouncerPasswdFields

type PgbouncerPasswdFields struct {
	Username string
	Password string
}

type ScaleClusterInfo

type ScaleClusterInfo struct {
	PrimaryDeployment        string
	ReplicaDeployments       []string
	PGBackRestRepoDeployment string
	PGBouncerDeployment      string
}

ScaleClusterInfo contains information about a cluster obtained when scaling the various deployments for a cluster. This includes the name of the primary deployment, all replica deployments, along with the names of the services enabled for the cluster.

func ScaleClusterDeployments

func ScaleClusterDeployments(clientset kubernetes.Interface, cluster crv1.Pgcluster, replicas int,
	scalePrimary, scaleReplicas, scaleBackRestRepo,
	scalePGBouncer bool) (clusterInfo ScaleClusterInfo, err error)

ScaleClusterDeployments scales all deployments for a cluster to the number of replicas specified using the 'replicas' parameter. This is typically used to scale-up or down the primary deployment and any supporting services (pgBackRest and pgBouncer) when shutting down or starting up the cluster due to a scale or scale-down request.

type ServiceTemplateFields

type ServiceTemplateFields struct {
	Name         string
	ServiceName  string
	ClusterName  string
	CustomLabels string
	Port         string
	PGBadgerPort string
	ExporterPort string
	ServiceType  v1.ServiceType
}

ServiceTemplateFields ...

Jump to

Keyboard shortcuts

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