Documentation ¶
Index ¶
- Constants
- Variables
- func CreateBackrestRepoSecrets(clientset kubernetes.Interface, backrestRepoConfig BackrestRepoConfig) (*v1.Secret, error)
- func CreatePerconaRMDataTask(clientset kubeapi.Interface, cluster *crv1.PerconaPGCluster, ...) error
- func CreateRMDataTask(clientset kubeapi.Interface, cluster *crv1.Pgcluster, replicaName string, ...) error
- func CreateSecret(clientset kubernetes.Interface, ...) error
- func CreateUserSecret(clientset kubernetes.Interface, cluster *crv1.Pgcluster, ...) error
- func CurrentPrimaryUpdate(clientset pgo.Interface, cluster *crv1.Pgcluster, ...) error
- func ExecPolicy(clientset kubeapi.Interface, restconfig *rest.Config, ...) error
- func GenerateExporterSecretName(clusterName string) string
- func GenerateNodeAffinity(affinityType crv1.NodeAffinityType, key string, values []string) *v1.NodeAffinity
- func GeneratePassword(length int) (string, error)
- func GeneratePgBouncerConfigMapName(clusterName string) string
- func GeneratePgBouncerSecretName(clusterName string) string
- func GeneratePgBouncerUsersFileBytes(hashedPassword string) []byte
- func GeneratedPasswordLength(configuredPasswordLength string) int
- func GeneratedPasswordValidUntilDays(configuredValidUntilDays string) int
- func GetCustomLabels(cluster *crv1.Pgcluster) map[string]string
- func GetLabels(name, clustername string, replica bool) string
- func GetPasswordFromSecret(clientset kubernetes.Interface, namespace, secretName string) (string, error)
- func GetPolicySQL(clientset pgo.Interface, namespace, policyName string) (string, error)
- func GetPrimaryPod(clientset kubernetes.Interface, cluster *crv1.Pgcluster) (*v1.Pod, error)
- func GetSecretPassword(clientset kubernetes.Interface, db, suffix, Namespace string) (string, error)
- func GetStandardImageTag(imageName, imageTag string) string
- func GetTolerations(tolerations []v1.Toleration) string
- func GetValueOrDefault(value, defaultValue string) string
- func IsPostgreSQLUserSystemAccount(username string) bool
- func IsStringOneOf(testVal string, acceptedVals ...string) bool
- func PatchClusterCRD(clientset pgo.Interface, labelMap map[string]string, oldCrd *crv1.Pgcluster, ...) error
- func RandStringBytesRmndr(n int) string
- func SQLQuoteIdentifier(identifier string) string
- func SQLQuoteLiteral(literal string) string
- func SetPostgreSQLPassword(clientset kubernetes.Interface, restconfig *rest.Config, pod *v1.Pod, ...) error
- func StopPostgreSQLInstance(clientset kubernetes.Interface, restconfig *rest.Config, pod *v1.Pod, ...) error
- func ToggleAutoFailover(clientset kubernetes.Interface, enable bool, pghaScope, namespace string) error
- func UpdateUserSecret(clientset kubernetes.Interface, cluster *crv1.Pgcluster, ...) error
- func ValidateLabels(labels map[string]string) error
- func ValidatePVCResize(oldSize, newSize string) error
- func ValidatePolicy(clientset pgo.Interface, namespace string, policyName string) error
- type AWSS3Secret
- type BackrestRepoConfig
- type GCSSecret
- type InstanceReplicationInfo
- type ReplicationStatusRequest
- type ReplicationStatusResponse
- type SSHKey
Constants ¶
const ( BackrestRepoDeploymentName = "%s-backrest-shared-repo" BackrestRepoServiceName = "%s-backrest-shared-repo" BackrestRepoPVCName = "%s-pgbr-repo" // #nosec: G101 BackrestRepoSecretName = "%s-backrest-repo-config" )
const ( // DefaultGeneratedPasswordLength is the length of what a generated password // is if it's not set in the pgo.yaml file, and to create some semblance of // consistency DefaultGeneratedPasswordLength = 24 // DefaultPasswordValidUntilDays is the number of days until a PostgreSQL user's // password expires. If it is not set in the pgo.yaml file, we will use a // default of "0" which means that a password will never expire DefaultPasswordValidUntilDays = 0 )
const ( // three of these are exported, as they are used to help add the information // into the templates. Say the last one 10 times fast // #nosec: G101 BackRestRepoSecretKeyAWSS3KeyAWSS3CACert = "aws-s3-ca.crt" // #nosec: G101 BackRestRepoSecretKeyAWSS3KeyAWSS3Key = "aws-s3-key" // #nosec: G101 BackRestRepoSecretKeyAWSS3KeyAWSS3KeySecret = "aws-s3-key-secret" // #nosec: G101 BackRestRepoSecretKeyAWSS3KeyGCSKey = "gcs-key" )
values for the keys used to access the pgBackRest repository Secret
const ( // SQLValidUntilAlways uses a special PostgreSQL value to ensure a password // is always valid SQLValidUntilAlways = "infinity" // SQLValidUntilNever uses a special PostgreSQL value to ensure a password // is never valid. This is exportable and used in other places SQLValidUntilNever = "-infinity" )
const ( // InstanceRolePrimary indicates that an instance is a primary InstanceRolePrimary = "primary" // InstanceRoleReplica indicates that an instance is a replica InstanceRoleReplica = "replica" )
const BootstrapConfigPrefix = "%s-bootstrap-%s"
BootstrapConfigPrefix is the format of the prefix used for the Secret containing the pgBackRest configuration required to bootstrap a new cluster using a pgBackRest backup
Variables ¶
var ( // ErrLabelInvalid indicates that a label is invalid ErrLabelInvalid = errors.New("invalid label") // ErrMissingConfigAnnotation represents an error thrown when the 'config' annotation is found // to be missing from the 'config' configMap created to store cluster-wide configuration ErrMissingConfigAnnotation error = errors.New("'config' annotation missing from cluster " + "configutation") )
Functions ¶
func CreateBackrestRepoSecrets ¶
func CreateBackrestRepoSecrets(clientset kubernetes.Interface, backrestRepoConfig BackrestRepoConfig) (*v1.Secret, error)
CreateBackrestRepoSecrets creates the secrets required to manage the pgBackRest repo container
func CreatePerconaRMDataTask ¶ added in v0.2.0
func CreatePerconaRMDataTask(clientset kubeapi.Interface, cluster *crv1.PerconaPGCluster, replicaName string, deleteBackups, deleteData, isReplica, isBackup bool) error
CreatePerconaRMDataTask is a legacy method that was moved into this file. This spawns the "pgo-rmdata" task which cleans up assets related to removing an individual instance or a cluster. I cleaned up the code slightly.
func CreateRMDataTask ¶
func CreateRMDataTask(clientset kubeapi.Interface, cluster *crv1.Pgcluster, replicaName string, deleteBackups, deleteData, isReplica, isBackup bool) error
CreateRMDataTask is a legacy method that was moved into this file. This spawns the "pgo-rmdata" task which cleans up assets related to removing an individual instance or a cluster. I cleaned up the code slightly.
func CreateSecret ¶
func CreateSecret(clientset kubernetes.Interface, db, secretName, username, password, namespace string, labels map[string]string) error
CreateSecret create the secret, user, and primary secrets
func CreateUserSecret ¶
func CreateUserSecret(clientset kubernetes.Interface, cluster *crv1.Pgcluster, username, password string) error
CreateUserSecret will create a new secret holding a user credential
func CurrentPrimaryUpdate ¶
func CurrentPrimaryUpdate(clientset pgo.Interface, cluster *crv1.Pgcluster, currentPrimary, namespace string) error
CurrentPrimaryUpdate prepares the needed data structures with the correct current primary value before passing them along to be patched into the current pgcluster CRD's annotations
func ExecPolicy ¶
func ExecPolicy(clientset kubeapi.Interface, restconfig *rest.Config, namespace, policyName, clusterName, port string) error
ExecPolicy execute a sql policy against a cluster
func GenerateExporterSecretName ¶
GenerateExporterSecretName returns the name of the secret that contains information around a monitoring user
func GenerateNodeAffinity ¶
func GenerateNodeAffinity(affinityType crv1.NodeAffinityType, key string, values []string) *v1.NodeAffinity
GenerateNodeAffinity creates a Kubernetes node affinity object suitable for storage on our custom resource. For now, it only supports preferred affinity, though can be expanded to support more complex rules
func GeneratePassword ¶
GeneratePassword generate random password
func GeneratePgBouncerConfigMapName ¶
GeneratePgBouncerConfigMapName generates the name of the configmap file associated with the pgBouncer Deployment
func GeneratePgBouncerSecretName ¶
GeneratePgBouncerSecretName returns the name of the secret that contains information around a pgBouncer deployment
func GeneratePgBouncerUsersFileBytes ¶
GeneratePgBouncerUsersFileBytes generates the byte string that is used by the pgBouncer secret to authenticate a user into pgBouncer that is acting as the pgBouncer "service user" (aka PgBouncerUser).
The format of this file is `"username "hashed-password"`
where "hashed-password" is a MD5 or SCRAM hashed password
This is ultimately moutned by the pgBouncer Pod via the secret
func GeneratedPasswordLength ¶
GeneratedPasswordLength returns the value for what the length of a randomly generated password should be. It first determines if the user provided this value via a configuration file, and if not and/or the value is invalid, uses the default value
func GeneratedPasswordValidUntilDays ¶
GeneratedPasswordValidUntilDays returns the value for the number of days that a password is valid for, which is used as part of PostgreSQL's VALID UNTIL directive on a user. It first determines if the user provided this value via a configuration file, and if not and/or the value is invalid, uses the default value
func GetCustomLabels ¶ added in v0.2.0
GetCustomLabels gets a list of the custom labels that a user set so they can be applied to any non-Postgres cluster instance objects. This removes some of the "system labels" that get stuck in the "UserLabels" area.
Do **not** use this for the Postgres instance Deployments. Some of those labels are needed there.
Returns a map.
func GetPasswordFromSecret ¶
func GetPasswordFromSecret(clientset kubernetes.Interface, namespace, secretName string) (string, error)
GetPasswordFromSecret will fetch the password from a user secret
func GetPolicySQL ¶
GetPolicySQL returns the SQL string from a policy
func GetPrimaryPod ¶
GetPrimaryPod gets the Pod of the primary PostgreSQL instance. If somehow the query gets multiple pods, then the first one in the list is returned
func GetSecretPassword ¶
func GetSecretPassword(clientset kubernetes.Interface, db, suffix, Namespace string) (string, error)
GetSecretPassword ...
func GetStandardImageTag ¶
GetStandardImageTag takes the current image name and the image tag value stored in the pgcluster CRD and, if the image being used is the crunchy-postgres-gis-ha container with the corresponding tag, it returns the tag without the addition of the GIS version. This tag value can then be used when provisioning containers using the standard containers tag.
func GetTolerations ¶
func GetTolerations(tolerations []v1.Toleration) string
GetTolerations returns any tolerations that may be defined in a tolerations in JSON format. Otherwise, it returns an empty string
func GetValueOrDefault ¶
GetValueOrDefault checks whether the first value given is set. If it is, that value is returned. If not, the second, default value is returned instead
func IsPostgreSQLUserSystemAccount ¶
IsPostgreSQLUserSystemAccount determines whether or not this is a system PostgreSQL user account, as if this returns true, one likely may not want to allow a user to directly access the account Normalizes the lookup by downcasing it
func IsStringOneOf ¶
IsStringOneOf tests to see string testVal is included in the list of strings provided using acceptedVals
func PatchClusterCRD ¶
func PatchClusterCRD(clientset pgo.Interface, labelMap map[string]string, oldCrd *crv1.Pgcluster, currentPrimary, namespace string) error
PatchClusterCRD patches the pgcluster CRD with any updated labels, or an updated current primary annotation value. As this uses a JSON merge patch, it will only updates those values that are different between the old and new CRD values.
func SQLQuoteIdentifier ¶
SQLQuoteIdentifier quotes an "identifier" (e.g. a table or a column name) to be used as part of an SQL statement.
Any double quotes in name will be escaped. The quoted identifier will be case sensitive when used in a query. If the input string contains a zero byte, the result will be truncated immediately before it.
Implementation borrowed from lib/pq: https://github.com/lib/pq which is licensed under the MIT License
func SQLQuoteLiteral ¶
SQLQuoteLiteral quotes a 'literal' (e.g. a parameter, often used to pass literal to DDL and other statements that do not accept parameters) to be used as part of an SQL statement.
Any single quotes in name will be escaped. Any backslashes (i.e. "\") will be replaced by two backslashes (i.e. "\\") and the C-style escape identifier that PostgreSQL provides ('E') will be prepended to the string.
Implementation borrowed from lib/pq: https://github.com/lib/pq which is licensed under the MIT License. Curiously, @jkatz and @cbandy were the ones who worked on the patch to add this, prior to being at Crunchy Data
func SetPostgreSQLPassword ¶
func SetPostgreSQLPassword(clientset kubernetes.Interface, restconfig *rest.Config, pod *v1.Pod, port, username, password, sqlCustom string) error
SetPostgreSQLPassword updates the password for a PostgreSQL role in the PostgreSQL cluster by executing into the primary Pod and changing it
Note: it is recommended to pre-hash the password (e.g. md5, SCRAM) so that way the plaintext password is not logged anywhere. This also avoids potential SQL injections
func StopPostgreSQLInstance ¶
func StopPostgreSQLInstance(clientset kubernetes.Interface, restconfig *rest.Config, pod *v1.Pod, instanceName string) error
StopPostgreSQLInstance issues a "fast" shutdown command to the PostgreSQL instance. This will immediately terminate any connections and safely shut down PostgreSQL so it does not have to start up in crash recovery mode
func ToggleAutoFailover ¶
func ToggleAutoFailover(clientset kubernetes.Interface, enable bool, pghaScope, namespace string) error
ToggleAutoFailover enables or disables autofailover for a cluster. Disabling autofailover means "pausing" Patroni, which will result in Patroni stepping aside from managing the cluster. This will effectively cause Patroni to stop responding to failures or other database activities, e.g. it will not attempt to start the database when stopped to perform maintenance
func UpdateUserSecret ¶
func UpdateUserSecret(clientset kubernetes.Interface, cluster *crv1.Pgcluster, username, password string) error
UpdateUserSecret updates a user secret with a new password. It follows the following method:
1. If the Secret exists, it updates the value of the Secret 2. If the Secret does not exist, it creates the secret
func ValidateLabels ¶
ValidateLabels validates if the input is a valid Kubernetes label.
A label is composed of a key and value.
The key can either be a name or have an optional prefix that i terminated by a "/", e.g. "prefix/name"
The name must be a valid DNS 1123 value THe prefix must be a valid DNS 1123 subdomain
The value can be validated by machinery provided by Kubernetes ¶
Ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
func ValidatePVCResize ¶ added in v0.2.0
ValidatePVCResize ensures that the quantities being used in a PVC resize are valid, and the resize is moving in an increasing direction
Types ¶
type AWSS3Secret ¶
AWSS3Secret is a structured representation for providing an AWS S3 key and key secret
func GetS3CredsFromBackrestRepoSecret ¶
func GetS3CredsFromBackrestRepoSecret(clientset kubernetes.Interface, namespace, clusterName string) (AWSS3Secret, error)
GetS3CredsFromBackrestRepoSecret retrieves the AWS S3 credentials, i.e. the key and key secret, from a specific cluster's backrest repo secret
type BackrestRepoConfig ¶
type BackrestRepoConfig struct { // BackrestS3CA is the byte string value of the CA that should be used for the // S3 inerfacd pgBackRest repository BackrestS3CA []byte BackrestS3Key string BackrestS3KeySecret string BackrestGCSKey []byte ClusterName string ClusterNamespace string CustomLabels map[string]string OperatorNamespace string }
BackrestRepoConfig represents the configuration required to created backrest repo secrets
type GCSSecret ¶ added in v0.2.0
type GCSSecret struct {
Key []byte
}
GCSSecret is a structured representation for providing the GCS key
func GetGCSCredsFromBackrestRepoSecret ¶ added in v0.2.0
func GetGCSCredsFromBackrestRepoSecret(clientset kubernetes.Interface, namespace, clusterName string) (GCSSecret, error)
GetGCSCredsFromBackrestRepoSecret retrieves the GCS credentials, i.e. the key "file" from the pgBackRest Secret
type InstanceReplicationInfo ¶
type InstanceReplicationInfo struct { Name string Node string ReplicationLag int Status string Timeline int PendingRestart bool PodName string Role string }
InstanceReplicationInfo is the user friendly information for the current status of key replication metrics for a PostgreSQL instance
type ReplicationStatusResponse ¶
type ReplicationStatusResponse struct {
Instances []InstanceReplicationInfo
}
func ReplicationStatus ¶
func ReplicationStatus(request ReplicationStatusRequest, includePrimary, includeBusted bool) (ReplicationStatusResponse, error)
ReplicationStatus is responsible for retrieving and returning the replication information about the status of the replicas in a PostgreSQL cluster. It executes into a single replica pod and leverages the functionality of Patroni for getting the key metrics that are appropriate to help the user understand the current state of their replicas.
Statistics include: the current node the replica is on, if it is up, the replication lag, etc.
By default information is only returned for replicas within the cluster. However, if primary information is also needed, the inlcudePrimary flag can set set to true and primary information will will also be included in the ReplicationStatusResponse.
Also by default we do not include any "busted" Pods, e.g. a Pod that is not in a happy phase. That Pod may be lacking a "role" label. From there, we zero out the statistics and apply an error