util

package
v4.2.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateBackrestPVCSnippet

func CreateBackrestPVCSnippet(backRestPVCName string) string

CreateBackrestPVCSnippet

func CreateBackrestRepoSecrets

func CreateBackrestRepoSecrets(clientset *kubernetes.Clientset,
	backrestRepoConfig BackrestRepoConfig) error

CreateBackrestRepoSecrets creates the secrets required to manage the pgBackRest repo container

func CreateBackupPVCSnippet

func CreateBackupPVCSnippet(backupPVCName string) string

CreateBackupPVCSnippet generates the PVC definition fragment

func CreatePVCSnippet

func CreatePVCSnippet(storageType string, PVCName string) string

CreatePVCSnippet generates the PVC json snippet

func CreateSecContext

func CreateSecContext(fsGroup string, suppGroup string) string

CreateSecContext will generate the JSON security context fragment for a storage type

func CreateSecret

func CreateSecret(clientset *kubernetes.Clientset, db, secretName, username, password, namespace string) error

CreateSecret create the secret, user, and primary secrets

func CreateUserSecret

func CreateUserSecret(clientset *kubernetes.Clientset, clustername, username, password, namespace string, passwordLength int) error

CreateUserSecret will create a new secret holding a user credential

func DrainDeployment

func DrainDeployment(clientset *kubernetes.Clientset, name string, namespace string) error

DrainDeployment will drain a deployment to 0 pods

func ExecPolicy

func ExecPolicy(clientset *kubernetes.Clientset, restclient *rest.RESTClient, restconfig *rest.Config, namespace string, policyName string, serviceName string) error

ExecPolicy execute a sql policy against a cluster

func GeneratePassword

func GeneratePassword(length int) string

GeneratePassword generate a password of a given length

func GenerateRandString

func GenerateRandString(length int) string

GenerateRandString generate a rand lowercase string of a given length

func GetLabels

func GetLabels(name, clustername string, replica bool) string

GetLabels ...

func GetMD5HashForAuthFile

func GetMD5HashForAuthFile(text string) string

Generates an Md5Hash

func GetPasswordFromSecret

func GetPasswordFromSecret(clientset *kubernetes.Clientset, namespace string, secretName string) (string, string, error)

GetPasswordFromSecret will fetch the username, password from a user secret

func GetPod

func GetPod(clientset *kubernetes.Clientset, deploymentName, namespace string) (*v1.Pod, error)

GetPod determines the best target to fail to

func GetPolicySQL

func GetPolicySQL(restclient *rest.RESTClient, namespace, policyName string) (string, error)

GetPolicySQL returns the SQL string from a policy

func GetPreferredNodes

func GetPreferredNodes(clientset *kubernetes.Clientset, selector, namespace string) ([]string, error)

func GetSecretPassword

func GetSecretPassword(clientset *kubernetes.Clientset, db, suffix, Namespace string) (string, error)

GetSecretPassword ...

func IsAutofailEnabled

func IsAutofailEnabled(cluster *crv1.Pgcluster) bool

IsAutofailEnabled - returns true if autofail label is set to true, false if not.

func IsStringOneOf

func IsStringOneOf(testVal string, acceptedVals ...string) bool

IsStringOneOf tests to see string testVal is included in the list of strings provided using acceptedVals

func IsValidBackrestStorageType

func IsValidBackrestStorageType(storageType string) bool

IsValidBackrestStorageType determines if the storage source string contains valid pgBackRest storage type values

func NewClient

func NewClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error)

NewClient gets a REST connection to Kube

func Patch

func Patch(restclient *rest.RESTClient, path string, value string, resource string, name string, namespace string) error

Patch will patch a particular resource

func PatchClusterCRD

func PatchClusterCRD(restclient *rest.RESTClient, labelMap map[string]string, oldCrd *crv1.Pgcluster, namespace string) error

PatchClusterCRD patches the pgcluster CRD

func RandStringBytesRmndr

func RandStringBytesRmndr(n int) string

RandStringBytesRmndr ...

func ScaleDeployment

func ScaleDeployment(clientset *kubernetes.Clientset, deploymentName, namespace string, replicaCount int) error

ScaleDeployment will increase the number of pods in a deployment

func ToggleAutoFailover

func ToggleAutoFailover(clientset *kubernetes.Clientset, 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 UpdatePolicyLabels

func UpdatePolicyLabels(clientset *kubernetes.Clientset, clusterName string, namespace string, newLabels map[string]string) error

UpdatePolicyLabels ...

func UpdateUserSecret

func UpdateUserSecret(clientset *kubernetes.Clientset, clustername, username, password, namespace string, passwordLength int) error

UpdateUserSecret updates a user secret with a new password

func ValidateBackrestStorageTypeOnBackupRestore

func ValidateBackrestStorageTypeOnBackupRestore(newBackRestStorageType,
	currentBackRestStorageType string, restore bool) error

ValidateBackrestStorageTypeOnBackupRestore checks to see if the pgbackrest storage type provided when performing either pgbackrest backup or restore is valid. This includes ensuring the value provided is a valid storage type (e.g. "s3" and/or "local"). This also includes ensuring the storage type specified (e.g. "s3" or "local") is enabled in the current cluster. And finally, validation is ocurring for a restore, the ensure only one storage type is selected.

func ValidatePolicy

func ValidatePolicy(restclient *rest.RESTClient, namespace string, policyName string) error

ValidatePolicy tests to see if a policy exists

func WaitUntilDeploymentIsDeleted

func WaitUntilDeploymentIsDeleted(clientset *kubernetes.Clientset, depname string, timeout time.Duration, namespace string) error

WaitUntilDeploymentIsDeleted timeout := time.Minute

func WaitUntilPod

func WaitUntilPod(clientset *kubernetes.Clientset, lo meta_v1.ListOptions, podPhase v1.PodPhase, timeout time.Duration, namespace string) error

WaitUntilPod ... podPhase is v1.PodRunning timeout := time.Minute

func WaitUntilPodIsDeleted

func WaitUntilPodIsDeleted(clientset *kubernetes.Clientset, podname string, timeout time.Duration, namespace string) error

WaitUntilPodIsDeleted timeout := time.Minute

Types

type AWSS3Secret

type AWSS3Secret struct {
	AWSS3Key       string `yaml:"aws-s3-key"`
	AWSS3KeySecret string `yaml:"aws-s3-key-secret"`
}

AWSS3Secret is a representation of the yaml structure found in aws-s3-credentials.yaml for providing an AWS S3 key and key secret

func GetS3CredsFromBackrestRepoSecret

func GetS3CredsFromBackrestRepoSecret(clientset *kubernetes.Clientset, clusterName,
	namespace string) (s3Secret AWSS3Secret, err 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 {
	BackrestS3Key       string
	BackrestS3KeySecret string
	ClusterName         string
	ClusterNamespace    string
	OperatorNamespace   string
}

BackrestRepoConfig represents the configuration required to created backrest repo secrets

type CloneClusterSecrets

type CloneClusterSecrets struct {
	// any additional selectors that can be added to the query that is made
	AdditionalSelectors []string
	// The Kubernetes Clientset used to make API calls to Kubernetes`
	ClientSet *kubernetes.Clientset
	// The Namespace that the clusters are in
	Namespace string
	// The name of the PostgreSQL cluster that the secrets are originating from
	SourceClusterName string
	// The name of the PostgreSQL cluster that we are copying the secrets to
	TargetClusterName string
}

CloneClusterSecrets will copy the secrets from a cluster into the secrets of another cluster

func (CloneClusterSecrets) Clone

func (cs CloneClusterSecrets) Clone() error

Clone performs the actual clone of the secrets between PostgreSQL clusters

type CloneTask

type CloneTask struct {
	PGOUser               string
	SourceClusterName     string
	TargetClusterName     string
	TaskStepLabel         string
	TaskType              string
	Timestamp             time.Time
	WorkflowID            string
	BackrestStorageSource string
}

CloneTask allows you to create a Pgtask CRD with the appropriate options

func (CloneTask) Create

func (clone CloneTask) Create() *crv1.Pgtask

newCloneTask returns a new instance of a Pgtask CRD

type InstanceReplicationInfo

type InstanceReplicationInfo struct {
	Name           string
	Node           string
	ReplicationLag int
	Status         string
	Timeline       int
}

InstanceReplicationInfo is the user friendly information for the current status of key replication metrics for a PostgreSQL instance

type ReplicationStatusRequest

type ReplicationStatusRequest struct {
	RESTConfig  *rest.Config
	Clientset   *kubernetes.Clientset
	Namespace   string
	ClusterName string
}

type ReplicationStatusResponse

type ReplicationStatusResponse struct {
	Instances []InstanceReplicationInfo
}

func ReplicationStatus

func ReplicationStatus(request ReplicationStatusRequest) (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.

type ThingSpec

type ThingSpec struct {
	Op    string `json:"op"`
	Path  string `json:"path"`
	Value string `json:"value"`
}

ThingSpec is a json patch structure

Jump to

Keyboard shortcuts

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