Skip to content

Commit

Permalink
Merge pull request #6 from catalogicsoftware/KUBEDR-5960_David
Browse files Browse the repository at this point in the history
KUBEDR-5960: Allow changing the backup method per PVC
  • Loading branch information
dzaninovic authored Sep 4, 2024
2 parents 1d2bd1c + a9ed888 commit abf68fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ HUGO_IMAGE := hugo-builder
local : ARCH ?= $(shell go env GOOS)-$(shell go env GOARCH)
ARCH ?= linux-amd64

VERSION ?= v1.14.0.1
VERSION ?= v1.14.0.2

TAG_LATEST ?= false

Expand Down
26 changes: 20 additions & 6 deletions pkg/backup/actions/csi/pvc_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package csi
import (
"context"
"fmt"
"slices"
"strings"

snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
Expand Down Expand Up @@ -642,23 +643,36 @@ func (p *pvcBackupItemAction) shouldSkipSnapshot(pvc *corev1api.PersistentVolume
}
}

if backupMethod, found := config.StorageClassBackupMethodMap[*pvc.Spec.StorageClassName]; found {
if backupMethod == "SNAPSHOT" {
setBackupMethod, isBackupMethodSet := config.StorageClassBackupMethodMap[*pvc.Spec.StorageClassName]

annotations := pvc.GetAnnotations()
if backupMethod, found := annotations["cloudcasa.io/backup-method"]; found {
backupMethod = strings.ToUpper(strings.TrimSpace(backupMethod))
if slices.Contains([]string{"SNAPSHOT", "LIVE_FROM_PVC", "LIVE_FROM_HOST_POD_VOL", "LIVE", "SKIP"}, backupMethod) {
setBackupMethod = backupMethod
isBackupMethodSet = true
} else {
p.log.Infof("Ignoring invalid backup method %s for PVC %s/%s", backupMethod, pvc.Namespace, pvc.Name)
}
}

if isBackupMethodSet {
if setBackupMethod == "SNAPSHOT" {
return false, nil
}

if backupMethod == "SKIP" {
if setBackupMethod == "SKIP" {
p.log.Infof("Skipping snapshot of PVC %s/%s because backupMethod is set to SKIP", pvc.Namespace, pvc.Name)
return true, nil
}

if strings.HasPrefix(backupMethod, "LIVE") {
if strings.HasPrefix(setBackupMethod, "LIVE") {
if *pvc.Spec.VolumeMode != corev1api.PersistentVolumeBlock {
p.log.Infof("Skipping snapshot of PVC %s/%s with storage class %s and backup method %s", pvc.Namespace, pvc.Name,
*pvc.Spec.StorageClassName, backupMethod)
*pvc.Spec.StorageClassName, setBackupMethod)
return true, nil
} else {
p.log.Infof("Ignoring PVC %s/%s backup method %s because it is a block volume", pvc.Namespace, pvc.Name, backupMethod)
p.log.Infof("Ignoring PVC %s/%s backup method %s because it is a block volume", pvc.Namespace, pvc.Name, setBackupMethod)
}
}
}
Expand Down

0 comments on commit abf68fa

Please sign in to comment.