From f232642fb78a533a452511359ae0da8c1553a25e Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Wed, 11 Sep 2024 23:01:15 -0400 Subject: [PATCH] pkg/podvolume/configs/configs.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit before ```go ❯ find ./pkg/cmd/server/config -maxdepth 1 -type f | grep .go | xargs -I {} sh -c "echo && echo && echo {} && go list -f {{.Deps}} {} | sed 's/ /\n/g' | grep -E 'github.com/vmware-tanzu/velero/pkg/podvolume'" ./pkg/cmd/server/config/config.go github.com/vmware-tanzu/velero/pkg/podvolume ./pkg/cmd/server/config/config_test.go ``` after ```go ~/git/velero refactor-pluginframeworkdep ❯ find ./pkg/cmd/server/config -maxdepth 1 -type f | grep .go | xargs -I {} sh -c "echo && echo && echo {} && go list -f {{.Deps}} {} | sed 's/ /\n/g' | grep -E 'github.com/vmware-tanzu/velero/pkg/podvolume'" ./pkg/cmd/server/config/config.go github.com/vmware-tanzu/velero/pkg/podvolume/configs ./pkg/cmd/server/config/config_test.go ``` Signed-off-by: Tiger Kaovilai --- pkg/cmd/server/config/config.go | 4 ++-- pkg/podvolume/backupper.go | 3 ++- pkg/podvolume/configs/configs.go | 11 +++++++++++ pkg/podvolume/util.go | 8 -------- pkg/restore/restore.go | 3 ++- 5 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 pkg/podvolume/configs/configs.go diff --git a/pkg/cmd/server/config/config.go b/pkg/cmd/server/config/config.go index 032cfdd763..ac9fe69df5 100644 --- a/pkg/cmd/server/config/config.go +++ b/pkg/cmd/server/config/config.go @@ -10,7 +10,7 @@ import ( "github.com/vmware-tanzu/velero/pkg/cmd/util/flag" "github.com/vmware-tanzu/velero/pkg/constant" - "github.com/vmware-tanzu/velero/pkg/podvolume" + podvolumeconfigs "github.com/vmware-tanzu/velero/pkg/podvolume/configs" "github.com/vmware-tanzu/velero/pkg/types" "github.com/vmware-tanzu/velero/pkg/uploader" "github.com/vmware-tanzu/velero/pkg/util/kube" @@ -198,7 +198,7 @@ func GetDefaultConfig() *Config { ResourceTerminatingTimeout: defaultResourceTerminatingTimeout, LogLevel: logging.LogLevelFlag(logrus.InfoLevel), LogFormat: logging.NewFormatFlag(), - DefaultVolumesToFsBackup: podvolume.DefaultVolumesToFsBackup, + DefaultVolumesToFsBackup: podvolumeconfigs.DefaultVolumesToFsBackup, UploaderType: uploader.ResticType, MaxConcurrentK8SConnections: defaultMaxConcurrentK8SConnections, DefaultSnapshotMoveData: false, diff --git a/pkg/podvolume/backupper.go b/pkg/podvolume/backupper.go index 5576f4e407..0a0c63eff1 100644 --- a/pkg/podvolume/backupper.go +++ b/pkg/podvolume/backupper.go @@ -35,6 +35,7 @@ import ( veleroclient "github.com/vmware-tanzu/velero/pkg/client" "github.com/vmware-tanzu/velero/pkg/label" "github.com/vmware-tanzu/velero/pkg/nodeagent" + "github.com/vmware-tanzu/velero/pkg/podvolume/configs" "github.com/vmware-tanzu/velero/pkg/repository" "github.com/vmware-tanzu/velero/pkg/uploader" uploaderutil "github.com/vmware-tanzu/velero/pkg/uploader/util" @@ -419,7 +420,7 @@ func newPodVolumeBackup(backup *velerov1api.Backup, pod *corev1api.Pod, volume c // this annotation is used in pkg/restore to identify if a PVC // has a pod volume backup. pvb.Annotations = map[string]string{ - PVCNameAnnotation: pvc.Name, + configs.PVCNameAnnotation: pvc.Name, } // this label is used by the pod volume backup controller to tell diff --git a/pkg/podvolume/configs/configs.go b/pkg/podvolume/configs/configs.go new file mode 100644 index 0000000000..17d57671c9 --- /dev/null +++ b/pkg/podvolume/configs/configs.go @@ -0,0 +1,11 @@ +package configs + +const ( + // PVCNameAnnotation is the key for the annotation added to + // pod volume backups when they're for a PVC. + PVCNameAnnotation = "velero.io/pvc-name" + + // DefaultVolumesToFsBackup specifies whether pod volume backup should be used, by default, to + // take backup of all pod volumes. + DefaultVolumesToFsBackup = false +) diff --git a/pkg/podvolume/util.go b/pkg/podvolume/util.go index 5c953e9f98..e9bb3075cc 100644 --- a/pkg/podvolume/util.go +++ b/pkg/podvolume/util.go @@ -28,18 +28,10 @@ import ( ) const ( - // PVCNameAnnotation is the key for the annotation added to - // pod volume backups when they're for a PVC. - PVCNameAnnotation = "velero.io/pvc-name" - // Deprecated. // // TODO(2.0): remove podAnnotationPrefix = "snapshot.velero.io/" - - // DefaultVolumesToFsBackup specifies whether pod volume backup should be used, by default, to - // take backup of all pod volumes. - DefaultVolumesToFsBackup = false ) // volumeBackupInfo describes the backup info of a volume backed up by PodVolumeBackups diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index f0ef01573f..010dcf99cb 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -67,6 +67,7 @@ import ( vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1" "github.com/vmware-tanzu/velero/pkg/podexec" "github.com/vmware-tanzu/velero/pkg/podvolume" + "github.com/vmware-tanzu/velero/pkg/podvolume/configs" "github.com/vmware-tanzu/velero/pkg/types" "github.com/vmware-tanzu/velero/pkg/util/boolptr" "github.com/vmware-tanzu/velero/pkg/util/collections" @@ -2020,7 +2021,7 @@ func hasPodVolumeBackup(unstructuredPV *unstructured.Unstructured, ctx *restoreC var found bool for _, pvb := range ctx.podVolumeBackups { - if pvb.Spec.Pod.Namespace == pv.Spec.ClaimRef.Namespace && pvb.GetAnnotations()[podvolume.PVCNameAnnotation] == pv.Spec.ClaimRef.Name { + if pvb.Spec.Pod.Namespace == pv.Spec.ClaimRef.Namespace && pvb.GetAnnotations()[configs.PVCNameAnnotation] == pv.Spec.ClaimRef.Name { found = true break }