pg

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const A8sPGBackupAPIGroup = "backups.anynines.com"

Backup

View Source
const A8sPGBackupKind = "Backup"
View Source
const A8sPGBackupKindPlural = "backups"
View Source
const A8sPGLabelPrimary = "a8s.a9s/replication-role=master"
View Source
const A8sPGRestoreKind = "Restore"

Restore

View Source
const A8sPGServiceBindingAPIGroup = "servicebindings.anynines.com"
View Source
const A8sPGServiceBindingKind = "ServiceBinding"

Service Binding

View Source
const A8sPGServiceInstanceAPIGroup = "postgresql.anynines.com"

Instance

View Source
const A8sPGServiceInstanceAPIGroupLabel = "a8s.a9s/dsi-group=" + A8sPGServiceInstanceAPIGroup
View Source
const A8sPGServiceInstanceKind = "Postgresql"
View Source
const A8sPGServiceInstanceKindLabel = "a8s.a9s/dsi-kind=" + A8sPGServiceInstanceKind
View Source
const A8sPGServiceInstanceKindPlural = "postgresqls"
View Source
const A8sPGServiceInstanceNameLabelKey = "a8s.a9s/dsi-name"
View Source
const DefaultPGAPIVersion = "v1beta3"
View Source
const RemoteUploadContainerName = "postgres"

Name of the container within the target pod to upload the file to.

View Source
const RemoteUploadDir = "/tmp"

Variables

View Source
var SQLFilename = ""

Filename when used with option --file or -f

Functions

func ApplySQLFileToPGServiceInstance

func ApplySQLFileToPGServiceInstance(unattendedMode bool, namespace, serviceInstanceName, sqlFileToUpload string, noDelete bool)

Upload and execute psql for the given file on the primary of the given service instance.

If noDelete is set to true, the uploaded file won't be deleted after a successful apply. Not that, if errors occur, the process will be stopped and hence, an uploaded file will remain in the pod and not be deleted, in case its execution failed.

Example kubectl command: kubectl exec -n default clustered-0 -c postgres -- psql -U postgres -d a9s_apps_default_db -f demo_data.sql

func ApplySQLStatementToPGServiceInstance

func ApplySQLStatementToPGServiceInstance(unattendedMode bool, namespace, serviceInstanceName, sqlStatement string)

TODO Reduce code duplication with ApplySQLFileToPGServiceInstance

func BackupToYAML

func BackupToYAML(backup Backup) string

Creates a backup YAML manifest for the given service instance name.

Returns a string.

func DoesBackupExist

func DoesBackupExist(namespace, backupName string) bool

func DoesServiceInstanceExist

func DoesServiceInstanceExist(namespace, name string) bool

func ExecuteSQLFileWithinPod

func ExecuteSQLFileWithinPod(unattendedMode bool, namespace, serviceInstanceName, remoteSQLFilePath string) error

Executes a SQL file within a Pod using PSQL. Both the sql file and the psql command must be present in the target pod.

Example: kubectl exec -n default clustered-0 -c postgres -- psql -U postgres -d a9s_apps_default_db -f demo_data.sql

func ExecuteSQLStatementWithinPod

func ExecuteSQLStatementWithinPod(unattendedMode bool, namespace, serviceInstanceName, sqlStatement string) (*exec.Cmd, []byte, error)

TODO Remove code duplication with ExecuteSQLFileWithinPod

func FindPrimaryPodOfServiceInstance

func FindPrimaryPodOfServiceInstance(namespace, serviceInstanceName string) string

Identifies the current primary of the given PG service instance.

Executes: kubectl get pods -n default -l 'a8s.a9s/replication-role=master,a8s.a9s/dsi-group=postgresql.anynines.com,a8s.a9s/dsi-kind=Postgresql,a8s.a9s/dsi-name=clustered' -o=jsonpath='{.items[*].metadata.name}'

func RestoreToYAML

func RestoreToYAML(restore Restore) string

Creates a restore YAML manifest to restore a backup.

func ServiceBindingToYAML

func ServiceBindingToYAML(binding ServiceBinding) string

func ServiceInstanceToYAML

func ServiceInstanceToYAML(instance ServiceInstance) string

func WaitForPGBackupResourceToBecomeReady

func WaitForPGBackupResourceToBecomeReady(namespace, name string, resource string) error

Similar to kubectl watch ... Needed: Namespace and name of the resource to be observed.

func WaitForPGBackupToBecomeReady

func WaitForPGBackupToBecomeReady(namespace, name string)

func WaitForPGRestoreToBecomeReady

func WaitForPGRestoreToBecomeReady(namespace, name string)

func WaitForPGServiceBindingToBecomeReady

func WaitForPGServiceBindingToBecomeReady(binding ServiceBinding) error

Types

type Backup

type Backup struct {
	ApiVersion          string
	Name                string
	Namespace           string
	ServiceInstanceName string
}

type Restore

type Restore struct {
	ApiVersion          string
	Name                string
	BackupName          string
	Namespace           string
	ServiceInstanceName string
}

type ServiceBinding

type ServiceBinding struct {
	ApiVersion          string
	Name                string
	Namespace           string
	ServiceInstanceName string
	ServiceInstanceKind string
}

type ServiceInstance

type ServiceInstance struct {
	Kind         string
	ApiVersion   string
	Name         string
	Namespace    string
	Replicas     int
	VolumeSize   string
	Version      string
	RequestsCPU  string
	LimitsMemory string
}

Jump to

Keyboard shortcuts

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