mirror of
https://github.com/vmware-tanzu/velero.git
synced 2025-12-23 14:25:22 +00:00
data path for vgdp ms pvb
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
This commit is contained in:
@@ -113,3 +113,9 @@ func (b *PodVolumeBackupBuilder) UploaderType(uploaderType string) *PodVolumeBac
|
|||||||
b.object.Spec.UploaderType = uploaderType
|
b.object.Spec.UploaderType = uploaderType
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Annotations sets the PodVolumeBackup's Annotations.
|
||||||
|
func (b *PodVolumeBackupBuilder) Annotations(annotations map[string]string) *PodVolumeBackupBuilder {
|
||||||
|
b.object.Annotations = annotations
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
v1 "k8s.io/api/core/v1"
|
corev1api "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/fields"
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
@@ -128,7 +128,7 @@ func newPodVolumeBackup(logger logrus.FieldLogger, factory client.Factory, confi
|
|||||||
return nil, errors.Wrap(err, "error to add velero v1 scheme")
|
return nil, errors.Wrap(err, "error to add velero v1 scheme")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := v1.AddToScheme(scheme); err != nil {
|
if err := corev1api.AddToScheme(scheme); err != nil {
|
||||||
cancelFunc()
|
cancelFunc()
|
||||||
return nil, errors.Wrap(err, "error to add core v1 scheme")
|
return nil, errors.Wrap(err, "error to add core v1 scheme")
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ func newPodVolumeBackup(logger logrus.FieldLogger, factory client.Factory, confi
|
|||||||
cacheOption := ctlcache.Options{
|
cacheOption := ctlcache.Options{
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
ByObject: map[ctlclient.Object]ctlcache.ByObject{
|
ByObject: map[ctlclient.Object]ctlcache.ByObject{
|
||||||
&v1.Pod{}: {
|
&corev1api.Pod{}: {
|
||||||
Field: fields.Set{"spec.nodeName": nodeName}.AsSelector(),
|
Field: fields.Set{"spec.nodeName": nodeName}.AsSelector(),
|
||||||
},
|
},
|
||||||
&velerov1api.PodVolumeBackup{}: {
|
&velerov1api.PodVolumeBackup{}: {
|
||||||
|
|||||||
@@ -300,7 +300,7 @@ func (r *BackupMicroService) closeDataPath(ctx context.Context, duName string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *BackupMicroService) cancelPodVolumeBackup(pvb *velerov1api.PodVolumeBackup) {
|
func (r *BackupMicroService) cancelPodVolumeBackup(pvb *velerov1api.PodVolumeBackup) {
|
||||||
r.logger.WithField("pvb", pvb.Name).Info("PVB is being canceled")
|
r.logger.WithField("PVB", pvb.Name).Info("PVB is being canceled")
|
||||||
|
|
||||||
r.eventRecorder.Event(pvb, false, datapath.EventReasonCancelling, "Canceling for PVB %s", pvb.Name)
|
r.eventRecorder.Event(pvb, false, datapath.EventReasonCancelling, "Canceling for PVB %s", pvb.Name)
|
||||||
|
|
||||||
|
|||||||
@@ -300,3 +300,34 @@ func TestVolumeHasNonRestorableSource(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetRealSource(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
pvb *velerov1api.PodVolumeBackup
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "pvb with empty annotation",
|
||||||
|
pvb: builder.ForPodVolumeBackup("fake-ns", "fake-name").PodNamespace("fake-pod-ns").PodName("fake-pod-name").Volume("fake-volume").Result(),
|
||||||
|
expected: "fake-pod-ns/fake-pod-name/fake-volume",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pvb without pvc name annotation",
|
||||||
|
pvb: builder.ForPodVolumeBackup("fake-ns", "fake-name").PodNamespace("fake-pod-ns").PodName("fake-pod-name").Volume("fake-volume").Annotations(map[string]string{}).Result(),
|
||||||
|
expected: "fake-pod-ns/fake-pod-name/fake-volume",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pvb with pvc name annotation",
|
||||||
|
pvb: builder.ForPodVolumeBackup("fake-ns", "fake-name").PodNamespace("fake-pod-ns").PodName("fake-pod-name").Volume("fake-volume").Annotations(map[string]string{"velero.io/pvc-name": "fake-pvc-name"}).Result(),
|
||||||
|
expected: "fake-pod-ns/fake-pod-name/fake-pvc-name",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
actual := GetRealSource(tc.pvb)
|
||||||
|
assert.Equal(t, tc.expected, actual)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user