specs

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package specs contains the specification of the K8s resources generated by the CloudNativePG operator

Index

Constants

View Source
const (
	// ClusterSerialAnnotationName is the name of the annotation containing the
	// serial number of the node
	ClusterSerialAnnotationName = utils.ClusterSerialAnnotationName

	// ClusterRestartAnnotationName is the name of the annotation containing the
	// latest required restart time
	ClusterRestartAnnotationName = utils.ClusterRestartAnnotationName

	// ClusterReloadAnnotationName is the name of the annotation containing the
	// latest required restart time
	ClusterReloadAnnotationName = utils.ClusterReloadAnnotationName

	// ClusterRoleLabelName label is applied to Pods to mark primary ones
	// Deprecated: Use utils.ClusterInstanceRoleLabelName
	ClusterRoleLabelName = utils.ClusterRoleLabelName

	// WatchedLabelName label is for Secrets or ConfigMaps that needs to be reloaded
	WatchedLabelName = utils.WatchedLabelName

	// ClusterRoleLabelPrimary is written in labels to represent primary servers
	ClusterRoleLabelPrimary = "primary"

	// ClusterRoleLabelReplica is written in labels to represent replica servers
	ClusterRoleLabelReplica = "replica"

	// PostgresContainerName is the name of the container executing PostgreSQL
	// inside one Pod
	PostgresContainerName = "postgres"

	// BootstrapControllerContainerName is the name of the container copying the bootstrap
	// controller inside the Pod file system
	BootstrapControllerContainerName = "bootstrap-controller"

	// PgDataPath is the path to PGDATA variable
	PgDataPath = "/var/lib/postgresql/data/pgdata"

	// PgWalPath is the path to the pg_wal directory
	PgWalPath = PgDataPath + "/pg_wal"

	// PgWalArchiveStatusPath is the path to the archive status directory
	PgWalArchiveStatusPath = PgWalPath + "/archive_status"

	// ReadinessProbePeriod is the period set for the postgres instance readiness probe
	ReadinessProbePeriod = 10

	// StartupProbePeriod is the period set for the postgres instance startup probe
	StartupProbePeriod = 10

	// LivenessProbePeriod is the period set for the postgres instance liveness probe
	LivenessProbePeriod = 10
)
View Source
const PgTablespaceVolumePath = "/var/lib/postgresql/tablespaces"

PgTablespaceVolumePath is the base path used by tablespace when present

View Source
const PgWalVolumePath = "/var/lib/postgresql/wal"

PgWalVolumePath is the path used by the WAL volume when present

View Source
const PgWalVolumePgWalPath = "/var/lib/postgresql/wal/pg_wal"

PgWalVolumePgWalPath is the path of pg_wal directory inside the WAL volume when present

Variables

This section is empty.

Functions

func AddBarmanEndpointCAToPodSpec added in v1.16.1

func AddBarmanEndpointCAToPodSpec(
	podSpec *corev1.PodSpec,
	caSecret *apiv1.SecretKeySelector,
	credentials apiv1.BarmanCredentials,
)

AddBarmanEndpointCAToPodSpec adds the required volumes and env variables needed by barman to work correctly

func BuildPrimaryPodDisruptionBudget

func BuildPrimaryPodDisruptionBudget(cluster *apiv1.Cluster) *policyv1.PodDisruptionBudget

BuildPrimaryPodDisruptionBudget creates a pod disruption budget, telling K8s to avoid removing more than one primary instance at a time

func BuildReplicasPodDisruptionBudget

func BuildReplicasPodDisruptionBudget(cluster *apiv1.Cluster) *policyv1.PodDisruptionBudget

BuildReplicasPodDisruptionBudget creates a pod disruption budget telling K8s to avoid removing more than one replica at a time

func ComparePodSpecs added in v1.19.5

func ComparePodSpecs(
	currentPodSpec, targetPodSpec corev1.PodSpec,
) (bool, string)

ComparePodSpecs compares two pod specs, returns true iff they are equivalent, and if they are not, points out the first discrepancy. This function matches CreateClusterPodSpec, specifically it looks in more detail and ignores reordering of volume mounts and containers

func CreateAffinitySection

func CreateAffinitySection(clusterName string, config apiv1.AffinityConfiguration) *corev1.Affinity

CreateAffinitySection creates the affinity sections for Pods, given the configuration from the user

func CreateClusterAnyService

func CreateClusterAnyService(cluster apiv1.Cluster) *corev1.Service

CreateClusterAnyService create a service insisting on all the pods

func CreateClusterPodSpec added in v1.19.5

func CreateClusterPodSpec(
	podName string,
	cluster apiv1.Cluster,
	envConfig EnvConfig,
	gracePeriod int64,
) corev1.PodSpec

CreateClusterPodSpec computes the PodSpec corresponding to a cluster

func CreateClusterReadOnlyService

func CreateClusterReadOnlyService(cluster apiv1.Cluster) *corev1.Service

CreateClusterReadOnlyService create a service insisting on all the ready pods

func CreateClusterReadService

func CreateClusterReadService(cluster apiv1.Cluster) *corev1.Service

CreateClusterReadService create a service insisting on all the ready pods

func CreateClusterReadWriteService

func CreateClusterReadWriteService(cluster apiv1.Cluster) *corev1.Service

CreateClusterReadWriteService create a service insisting on the primary pod

func CreateContainerSecurityContext

func CreateContainerSecurityContext(seccompProfile *corev1.SeccompProfile) *corev1.SecurityContext

CreateContainerSecurityContext initializes container security context. It applies the seccomp profile if supported.

func CreateGeneratedAntiAffinity

func CreateGeneratedAntiAffinity(clusterName string, config apiv1.AffinityConfiguration) *corev1.Affinity

CreateGeneratedAntiAffinity generates the affinity terms the operator is in charge for if enabled, return nil if disabled or an error occurred, as invalid values should be validated before this method is called

func CreateManagedSecretsAnnotationValue

func CreateManagedSecretsAnnotationValue(imagePullSecretsNames []string) (string, error)

CreateManagedSecretsAnnotationValue creates the value of the annotations that stores the names of the secrets managed by the operator inside a ServiceAccount

func CreatePodSecurityContext added in v1.15.3

func CreatePodSecurityContext(seccompProfile *corev1.SeccompProfile, user, group int64) *corev1.PodSecurityContext

CreatePodSecurityContext defines the security context under which the containers are running

func CreatePrimaryJobViaInitdb

func CreatePrimaryJobViaInitdb(cluster apiv1.Cluster, nodeSerial int) *batchv1.Job

CreatePrimaryJobViaInitdb creates a new primary instance in a Pod

func CreatePrimaryJobViaPgBaseBackup

func CreatePrimaryJobViaPgBaseBackup(cluster apiv1.Cluster, nodeSerial int) *batchv1.Job

CreatePrimaryJobViaPgBaseBackup creates a new primary instance in a Pod

func CreatePrimaryJobViaRecovery

func CreatePrimaryJobViaRecovery(cluster apiv1.Cluster, nodeSerial int, backup *apiv1.Backup) *batchv1.Job

CreatePrimaryJobViaRecovery creates a new primary instance in a Pod, restoring from a Backup

func CreatePrimaryJobViaRestoreSnapshot added in v1.20.3

func CreatePrimaryJobViaRestoreSnapshot(
	cluster apiv1.Cluster,
	nodeSerial int,
	snapshot storagesnapshotv1.VolumeSnapshot,
	backup *apiv1.Backup,
) *batchv1.Job

CreatePrimaryJobViaRestoreSnapshot creates a new primary instance in a Pod, restoring from a volumeSnapshot

func CreateRole

func CreateRole(cluster apiv1.Cluster, backupOrigin *apiv1.Backup) rbacv1.Role

CreateRole create a role with the permissions needed by the instance manager

func CreateRoleBinding

func CreateRoleBinding(objectMeta metav1.ObjectMeta) rbacv1.RoleBinding

CreateRoleBinding is the binding between the permissions that the instance manager can use and the ServiceAccount used by the Pod

func CreateSecret

func CreateSecret(
	name string,
	namespace string,
	hostname string,
	dbname string,
	username string,
	password string,
) *corev1.Secret

CreateSecret create a secret with the PostgreSQL and the owner passwords

func GetBootstrapControllerImageName

func GetBootstrapControllerImageName(pod corev1.Pod) (string, error)

GetBootstrapControllerImageName get the controller image name used to bootstrap a Pod

func GetContainerImageName

func GetContainerImageName(pod corev1.Pod, containerName string) (string, error)

GetContainerImageName get the name of the image used in a container

func GetInitContainerImageName

func GetInitContainerImageName(pod corev1.Pod, containerName string) (string, error)

GetInitContainerImageName get the name of the image used in an init container

func GetInstanceName added in v1.18.0

func GetInstanceName(clusterName string, nodeSerial int) string

GetInstanceName returns a string indicating the instance name

func GetNodeSerial

func GetNodeSerial(object metav1.ObjectMeta) (int, error)

GetNodeSerial get the serial number of an object created by the operator for a Cluster

func GetPossibleJobNames added in v1.18.4

func GetPossibleJobNames(instanceName string) []string

GetPossibleJobNames get all the possible job names for a given instance

func GetPostgresImageName

func GetPostgresImageName(pod corev1.Pod) (string, error)

GetPostgresImageName get the PostgreSQL image name used in this Pod

func IsPodPrimary

func IsPodPrimary(pod corev1.Pod) bool

IsPodPrimary check if a certain pod belongs to a primary

func IsPodStandby

func IsPodStandby(pod corev1.Pod) bool

IsPodStandby check if a certain pod belongs to a standby

func IsPrimary added in v1.19.5

func IsPrimary(meta metav1.ObjectMeta) bool

IsPrimary check if a certain resource belongs to a primary

func IsServiceAccountAligned

func IsServiceAccountAligned(
	ctx context.Context,
	sa *corev1.ServiceAccount,
	imagePullSecretsNames []string,
	updatedMetadata metav1.ObjectMeta,
) bool

IsServiceAccountAligned compares the given list of pull secrets with the ones managed by the operator inside the given ServiceAccount and returns true when everything is aligned

func JoinReplicaInstance

func JoinReplicaInstance(cluster apiv1.Cluster, nodeSerial int) *batchv1.Job

JoinReplicaInstance create a new PostgreSQL node, copying the contents from another Pod

func LocationForTablespace added in v1.22.0

func LocationForTablespace(tablespaceName string) string

LocationForTablespace returns the data location for tablespace on a cluster pod

func MountForTablespace added in v1.22.0

func MountForTablespace(tablespaceName string) string

MountForTablespace returns the normalized tablespace volume name for a given tablespace, on a cluster pod

func PodWithExistingStorage

func PodWithExistingStorage(cluster apiv1.Cluster, nodeSerial int) *corev1.Pod

PodWithExistingStorage create a new instance with an existing storage

func PvcNameForTablespace added in v1.22.0

func PvcNameForTablespace(podName, tablespaceName string) string

PvcNameForTablespace returns the normalized tablespace volume name for a given tablespace, on a cluster pod

func RestoreReplicaInstance added in v1.21.0

func RestoreReplicaInstance(cluster apiv1.Cluster, nodeSerial int) *batchv1.Job

RestoreReplicaInstance creates a new PostgreSQL replica starting from a volume snapshot backup

func SnapshotBackupNameForTablespace added in v1.22.0

func SnapshotBackupNameForTablespace(backupName, tablespaceName string) string

SnapshotBackupNameForTablespace returns the volume snapshot backup name for the tablespace

func UpdateServiceAccount

func UpdateServiceAccount(imagePullSecretsNames []string, serviceAccount *corev1.ServiceAccount) error

UpdateServiceAccount sets the needed values in the ServiceAccount that will be used in every Pod

func VolumeMountNameForTablespace added in v1.22.0

func VolumeMountNameForTablespace(tablespaceName string) string

VolumeMountNameForTablespace returns the normalized tablespace volume name for a given tablespace, on a cluster pod

Types

type ClusterPodMonitorManager added in v1.18.5

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

ClusterPodMonitorManager builds the PodMonitor for the cluster resource

func NewClusterPodMonitorManager added in v1.18.5

func NewClusterPodMonitorManager(cluster *apiv1.Cluster) *ClusterPodMonitorManager

NewClusterPodMonitorManager returns a new instance of ClusterPodMonitorManager

func (ClusterPodMonitorManager) BuildPodMonitor added in v1.18.5

func (c ClusterPodMonitorManager) BuildPodMonitor() *monitoringv1.PodMonitor

BuildPodMonitor builds a new PodMonitor object

func (ClusterPodMonitorManager) IsPodMonitorEnabled added in v1.18.5

func (c ClusterPodMonitorManager) IsPodMonitorEnabled() bool

IsPodMonitorEnabled returns a boolean indicating if the PodMonitor should exists or not

type EnvConfig added in v1.18.2

type EnvConfig struct {
	EnvVars []corev1.EnvVar
	EnvFrom []corev1.EnvFromSource
	Hash    string
}

EnvConfig carries the environment configuration of a container

func CreatePodEnvConfig added in v1.18.2

func CreatePodEnvConfig(cluster apiv1.Cluster, podName string) EnvConfig

CreatePodEnvConfig returns the hash of pod env configuration

func (EnvConfig) IsEnvEqual added in v1.18.2

func (c EnvConfig) IsEnvEqual(container corev1.Container) bool

IsEnvEqual detects if the environment of a container matches

Directories

Path Synopsis
Package pgbouncer contains the specification of the K8s resources generated by the CloudNativePG operator related to pgbouncer poolers
Package pgbouncer contains the specification of the K8s resources generated by the CloudNativePG operator related to pgbouncer poolers

Jump to

Keyboard shortcuts

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