Skip to content

Commit

Permalink
pkg/podvolume/configs/configs.go
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kaovilai committed Sep 12, 2024
1 parent ee57542 commit f232642
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion pkg/podvolume/backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions pkg/podvolume/configs/configs.go
Original file line number Diff line number Diff line change
@@ -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
)
8 changes: 0 additions & 8 deletions pkg/podvolume/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {

Check warning on line 2024 in pkg/restore/restore.go

View check run for this annotation

Codecov / codecov/patch

pkg/restore/restore.go#L2024

Added line #L2024 was not covered by tests
found = true
break
}
Expand Down

0 comments on commit f232642

Please sign in to comment.