Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KUBEDR-5960: Allow changing the backup method per PVC #6

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
import (
"context"
"fmt"
"slices"
"strings"

snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
Expand Down Expand Up @@ -308,7 +309,7 @@
}

if storageClass.Provisioner == "file.csi.azure.com" {
catalogic.SetStaticAzureAnotation(&pvc, labels, storageClass, p.log)

Check failure on line 312 in pkg/backup/actions/csi/pvc_action.go

View workflow job for this annotation

GitHub Actions / Run Linter Check

Error return value of `catalogic.SetStaticAzureAnotation` is not checked (errcheck)
}

annotations := labels
Expand Down Expand Up @@ -642,23 +643,36 @@
}
}

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
Loading