lib

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePVCManifestFromVolumeSnapshot added in v0.2.0

func CreatePVCManifestFromVolumeSnapshot(namespace, vsName, pvcName, storageClass string) (map[string]interface{}, error)

CreatePVCManifestFromVolumeSnapshot creates a PVC manifest from a VolumeSnapshot

func CreatePreProvisionedVSC

func CreatePreProvisionedVSC(vscObject map[string]interface{}, postfix string) (map[string]interface{}, error)

func CreateVolumeSnapshot

func CreateVolumeSnapshot(namespace string, dryRun bool, vsName string, vsObject map[string]interface{}, wait bool, waitTimeout string) error

func DeleteVolumeSnapshotContent added in v0.1.1

func DeleteVolumeSnapshotContent(volumeSnapshotContentName string) error

func DumpMySQL added in v0.2.0

func DumpMySQL(namespace string, dryRun bool, config MySQLConfig) error

func DumpPostgres added in v0.2.0

func DumpPostgres(namespace string, dryRun bool, config PostgresConfig) error

func EnsureFreeSpace

func EnsureFreeSpace(namespace, resource, container, dir string, thresholdSpaceUsedPercent int) error

func EnsureMySQLAvailable

func EnsureMySQLAvailable(namespace string, config MySQLConfig) error

func EnsurePVCAvailable

func EnsurePVCAvailable(namespace, pvcName string) error

func EnsurePostgresAvailable

func EnsurePostgresAvailable(namespace string, config PostgresConfig) error

func EnsureResourceAvailable

func EnsureResourceAvailable(namespace, resource string) error

func FlockLock

func FlockLock(lockFile string, timeout time.Duration, dryRun bool) (func() error, error)

func FlockShuffleLockFile

func FlockShuffleLockFile(dir string, count int) string

func GenerateRandomStringOrPanic

func GenerateRandomStringOrPanic(n int) string

func GenerateVSAnnotations

func GenerateVSAnnotations(bakEnvVars map[string]string) map[string]string

typically we'll only save the used safe env vars inside the env-config annotation

func GenerateVSLabels

func GenerateVSLabels(namespace, pvcName string, config LabelVSConfig, now time.Time) map[string]string

func GenerateVSName

func GenerateVSName(vsNameTemplate string, pvcName string, vsRand string) (string, error)

func GenerateVSObject

func GenerateVSObject(namespace, vsClassName, pvcName, vsName string, labels, annotations map[string]string) map[string]interface{}

func GenerateVSObjectFromVSC

func GenerateVSObjectFromVSC(vscName string, vscObject map[string]interface{}) (map[string]interface{}, error)

func GetBAKEnvVars

func GetBAKEnvVars() map[string]string

GetBAKEnvVars returns all environment variables starting with "BAK_", excluding secrets

func GetBackupNsLabelMap

func GetBackupNsLabelMap(namespace, kind, name string) (map[string]string, error)

func GetCurrentNamespace

func GetCurrentNamespace() (string, error)

func GetPodFromResource added in v0.2.0

func GetPodFromResource(namespace, resource string) (string, error)

func GetRemoteFileTimestamp added in v0.2.0

func GetRemoteFileTimestamp(namespace, execResource, execContainer, absolutePathToFile string) (time.Time, error)

func GetSelectorFromResource added in v0.2.0

func GetSelectorFromResource(namespace, resource string) (string, error)

Returns a --selector compatible string (e.g. app=postgres) from a resource in the format kind/name

func GetVolumeSnapshotContentName

func GetVolumeSnapshotContentName(namespace, volumeSnapshotName string) (string, error)

func GetVolumeSnapshotContentObject

func GetVolumeSnapshotContentObject(vscName string) (map[string]interface{}, error)

func KubectlExecCommand added in v0.2.0

func KubectlExecCommand(namespace, execResource, execContainer, command string) error

func KubectlExecTemplate added in v0.2.0

func KubectlExecTemplate(namespace, execResource, execContainer string, tmpl *template.Template, templateData any) error

func PrintConfig

func PrintConfig(config Config)

func PrintTimeZone

func PrintTimeZone()

Prints the current timezone and the current date and time

func PruneVolumeSnapshot

func PruneVolumeSnapshot(namespace, volumeSnapshotName string, wait bool) error

Dangerous! Delete a VolumeSnapshot, its associated VolumeSnapshotContent and the underlying storage! This is a destructive operation and should be used with caution! This function will set the deletionPolicy of the VolumeSnapshotContent to "Delete" before deleting the VolumeSnapshot, thus ensuring the underlying storage is also deleted.

func RebindVsc added in v0.1.1

func RebindVsc(oldVSCName, vsRand string, wait bool, waitTimeout string) error

func RestoreMySQL added in v0.2.0

func RestoreMySQL(namespace string, dryRun bool, config MySQLConfig) error

func RestorePostgres added in v0.2.0

func RestorePostgres(namespace string, dryRun bool, config PostgresConfig) error

func RestoreVolumeSnapshot added in v0.2.0

func RestoreVolumeSnapshot(namespace string, vsName string, pvcName string, storageClass string, wait bool, waitTimeout string) error

RestoreVolumeSnapshot creates a new PVC from a VolumeSnapshot (applies the PVC manifest)

func SyncVSLabelsToVsc

func SyncVSLabelsToVsc(namespace, vsName string) error

Types

type Config

type Config struct {
	DryRun                    bool   `json:"BAK_DRY_RUN"`
	Namespace                 string `json:"BAK_NAMESPACE"`
	PVCName                   string `json:"BAK_PVC_NAME"`
	VSRand                    string `json:"BAK_VS_RAND"`
	LabelVS                   LabelVSConfig
	VSNameTemplate            string `json:"BAK_VS_NAME_TEMPLATE"`
	VSClassName               string `json:"BAK_VS_CLASS_NAME"`
	VSWaitUntilReady          bool   `json:"BAK_VS_WAIT_UNTIL_READY"`
	VSWaitUntilReadyTimeout   string `json:"BAK_VS_WAIT_UNTIL_READY_TIMEOUT"`
	ThresholdSpaceUsedPercent int    `json:"BAK_THRESHOLD_SPACE_USED_PERCENTAGE"`
	DBSkip                    bool   `json:"BAK_DB_SKIP"`
	Postgres                  PostgresConfig
	MySQL                     MySQLConfig
	Flock                     FlockConfig
}

Config holds all the configuration options

func LoadConfig

func LoadConfig() Config

type FlockConfig

type FlockConfig struct {
	Enabled    bool   `json:"BAK_FLOCK"`
	Count      int    `json:"BAK_FLOCK_COUNT"`
	Dir        string `json:"BAK_FLOCK_DIR"`
	TimeoutSec int    `json:"BAK_FLOCK_TIMEOUT_SEC"`
}

type LabelVSConfig

type LabelVSConfig struct {
	Type       string `json:"BAK_LABEL_VS_TYPE"`
	Pod        string `json:"BAK_LABEL_VS_POD"`
	Retain     string `json:"BAK_LABEL_VS_RETAIN"`
	RetainDays int    `json:"BAK_LABEL_VS_RETAIN_DAYS"`
}

type MySQLConfig

type MySQLConfig struct {
	Enabled             bool   `json:"BAK_DB_MYSQL"`
	ExecResource        string `json:"BAK_DB_MYSQL_EXEC_RESOURCE"`
	ExecContainer       string `json:"BAK_DB_MYSQL_EXEC_CONTAINER"`
	DumpFile            string `json:"BAK_DB_MYSQL_DUMP_FILE"`
	Host                string `json:"BAK_DB_MYSQL_HOST"`
	Port                string `json:"BAK_DB_MYSQL_PORT"`
	User                string `json:"BAK_DB_MYSQL_USER"`
	Password            string `json:"-"` // sensitive
	DB                  string `json:"BAK_DB_MYSQL_DB"`
	DefaultCharacterSet string `json:"BAK_DB_MYSQL_DEFAULT_CHARACTER_SET"`
}

type NamespacedK8sObject

type NamespacedK8sObject struct {
	Namespace string
	Name      string
}

func GetManagedVolumeSnapshots

func GetManagedVolumeSnapshots() ([]NamespacedK8sObject, error)

We expect all VS that we manage to have to "backup-ns.sh/type" label key.

type PostgresConfig

type PostgresConfig struct {
	Enabled       bool   `json:"BAK_DB_POSTGRES"`
	ExecResource  string `json:"BAK_DB_POSTGRES_EXEC_RESOURCE"`
	ExecContainer string `json:"BAK_DB_POSTGRES_EXEC_CONTAINER"`
	DumpFile      string `json:"BAK_DB_POSTGRES_DUMP_FILE"`
	Host          string `json:"BAK_DB_POSTGRES_HOST"`
	Port          string `json:"BAK_DB_POSTGRES_PORT"`
	User          string `json:"BAK_DB_POSTGRES_USER"`
	Password      string `json:"-"` // sensitive
	DB            string `json:"BAK_DB_POSTGRES_DB"`
}

type TemplateAtlas added in v0.2.0

type TemplateAtlas struct {
	MySQLCheck      *template.Template
	MySQLDump       *template.Template
	MySQLRestore    *template.Template
	PostgresCheck   *template.Template
	PostgresDump    *template.Template
	PostgresRestore *template.Template
	TestTrap        *template.Template
}

func GetTemplateAtlas added in v0.2.0

func GetTemplateAtlas() TemplateAtlas

Jump to

Keyboard shortcuts

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