Rename Ark to Velero!!!

Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
This commit is contained in:
Nolan Brubaker
2019-01-24 22:33:07 -05:00
committed by Andy Goldstein
parent bbc6caf7fe
commit 43714caaec
411 changed files with 12857 additions and 3522 deletions

View File

@@ -37,19 +37,19 @@ import (
kerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/cache"
api "github.com/heptio/ark/pkg/apis/ark/v1"
pkgbackup "github.com/heptio/ark/pkg/backup"
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/metrics"
"github.com/heptio/ark/pkg/persistence"
"github.com/heptio/ark/pkg/plugin"
"github.com/heptio/ark/pkg/util/collections"
"github.com/heptio/ark/pkg/util/encode"
kubeutil "github.com/heptio/ark/pkg/util/kube"
"github.com/heptio/ark/pkg/util/logging"
"github.com/heptio/ark/pkg/volume"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
pkgbackup "github.com/heptio/velero/pkg/backup"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/metrics"
"github.com/heptio/velero/pkg/persistence"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/util/collections"
"github.com/heptio/velero/pkg/util/encode"
kubeutil "github.com/heptio/velero/pkg/util/kube"
"github.com/heptio/velero/pkg/util/logging"
"github.com/heptio/velero/pkg/volume"
)
type backupController struct {
@@ -57,7 +57,7 @@ type backupController struct {
backupper pkgbackup.Backupper
lister listers.BackupLister
client arkv1client.BackupsGetter
client velerov1client.BackupsGetter
clock clock.Clock
backupLogLevel logrus.Level
newPluginManager func(logrus.FieldLogger) plugin.Manager
@@ -67,12 +67,12 @@ type backupController struct {
snapshotLocationLister listers.VolumeSnapshotLocationLister
defaultSnapshotLocations map[string]string
metrics *metrics.ServerMetrics
newBackupStore func(*api.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error)
newBackupStore func(*velerov1api.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error)
}
func NewBackupController(
backupInformer informers.BackupInformer,
client arkv1client.BackupsGetter,
client velerov1client.BackupsGetter,
backupper pkgbackup.Backupper,
logger logrus.FieldLogger,
backupLogLevel logrus.Level,
@@ -112,10 +112,10 @@ func NewBackupController(
backupInformer.Informer().AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
backup := obj.(*api.Backup)
backup := obj.(*velerov1api.Backup)
switch backup.Status.Phase {
case "", api.BackupPhaseNew:
case "", velerov1api.BackupPhaseNew:
// only process new backups
default:
c.logger.WithFields(logrus.Fields{
@@ -162,7 +162,7 @@ func (c *backupController) processBackup(key string) error {
// InProgress, we still need this check so we can return nil to indicate we've finished processing
// this key (even though it was a no-op).
switch original.Status.Phase {
case "", api.BackupPhaseNew:
case "", velerov1api.BackupPhaseNew:
// only process new backups
default:
return nil
@@ -172,9 +172,9 @@ func (c *backupController) processBackup(key string) error {
request := c.prepareBackupRequest(original)
if len(request.Status.ValidationErrors) > 0 {
request.Status.Phase = api.BackupPhaseFailedValidation
request.Status.Phase = velerov1api.BackupPhaseFailedValidation
} else {
request.Status.Phase = api.BackupPhaseInProgress
request.Status.Phase = velerov1api.BackupPhaseInProgress
}
// update status
@@ -186,7 +186,7 @@ func (c *backupController) processBackup(key string) error {
original = updatedBackup
request.Backup = updatedBackup.DeepCopy()
if request.Status.Phase == api.BackupPhaseFailedValidation {
if request.Status.Phase == velerov1api.BackupPhaseFailedValidation {
return nil
}
@@ -195,12 +195,12 @@ func (c *backupController) processBackup(key string) error {
log.Debug("Running backup")
// execution & upload of backup
backupScheduleName := request.GetLabels()["ark-schedule"]
backupScheduleName := request.GetLabels()[velerov1api.ScheduleNameLabel]
c.metrics.RegisterBackupAttempt(backupScheduleName)
if err := c.runBackup(request); err != nil {
log.WithError(err).Error("backup failed")
request.Status.Phase = api.BackupPhaseFailed
request.Status.Phase = velerov1api.BackupPhaseFailed
c.metrics.RegisterBackupFailed(backupScheduleName)
} else {
c.metrics.RegisterBackupSuccess(backupScheduleName)
@@ -214,7 +214,7 @@ func (c *backupController) processBackup(key string) error {
return nil
}
func patchBackup(original, updated *api.Backup, client arkv1client.BackupsGetter) (*api.Backup, error) {
func patchBackup(original, updated *velerov1api.Backup, client velerov1client.BackupsGetter) (*velerov1api.Backup, error) {
origBytes, err := json.Marshal(original)
if err != nil {
return nil, errors.Wrap(err, "error marshalling original backup")
@@ -238,7 +238,7 @@ func patchBackup(original, updated *api.Backup, client arkv1client.BackupsGetter
return res, nil
}
func (c *backupController) prepareBackupRequest(backup *api.Backup) *pkgbackup.Request {
func (c *backupController) prepareBackupRequest(backup *velerov1api.Backup) *pkgbackup.Request {
request := &pkgbackup.Request{
Backup: backup.DeepCopy(), // don't modify items in the cache
}
@@ -260,7 +260,7 @@ func (c *backupController) prepareBackupRequest(backup *api.Backup) *pkgbackup.R
if request.Labels == nil {
request.Labels = make(map[string]string)
}
request.Labels[api.StorageLocationLabel] = request.Spec.StorageLocation
request.Labels[velerov1api.StorageLocationLabel] = request.Spec.StorageLocation
// validate the included/excluded resources and namespaces
for _, err := range collections.ValidateIncludesExcludes(request.Spec.IncludedResources, request.Spec.ExcludedResources) {
@@ -304,9 +304,9 @@ func (c *backupController) prepareBackupRequest(backup *api.Backup) *pkgbackup.R
// - a given provider's default location name is added to .spec.volumeSnapshotLocations if one
// is not explicitly specified for the provider (if there's only one location for the provider,
// it will automatically be used)
func (c *backupController) validateAndGetSnapshotLocations(backup *api.Backup) (map[string]*api.VolumeSnapshotLocation, []string) {
func (c *backupController) validateAndGetSnapshotLocations(backup *velerov1api.Backup) (map[string]*velerov1api.VolumeSnapshotLocation, []string) {
errors := []string{}
providerLocations := make(map[string]*api.VolumeSnapshotLocation)
providerLocations := make(map[string]*velerov1api.VolumeSnapshotLocation)
for _, locationName := range backup.Spec.VolumeSnapshotLocations {
// validate each locationName exists as a VolumeSnapshotLocation
@@ -344,7 +344,7 @@ func (c *backupController) validateAndGetSnapshotLocations(backup *api.Backup) (
}
// build a map of provider->list of all locations for the provider
allProviderLocations := make(map[string][]*api.VolumeSnapshotLocation)
allProviderLocations := make(map[string][]*velerov1api.VolumeSnapshotLocation)
for i := range allLocations {
loc := allLocations[i]
allProviderLocations[loc.Spec.Provider] = append(allProviderLocations[loc.Spec.Provider], loc)
@@ -434,9 +434,9 @@ func (c *backupController) runBackup(backup *pkgbackup.Request) error {
// Do the actual backup
if err := c.backupper.Backup(log, backup, backupFile, actions, pluginManager); err != nil {
errs = append(errs, err)
backup.Status.Phase = api.BackupPhaseFailed
backup.Status.Phase = velerov1api.BackupPhaseFailed
} else {
backup.Status.Phase = api.BackupPhaseCompleted
backup.Status.Phase = velerov1api.BackupPhaseCompleted
}
if err := gzippedLogFile.Close(); err != nil {
@@ -462,8 +462,8 @@ func (c *backupController) runBackup(backup *pkgbackup.Request) error {
return kerrors.NewAggregate(errs)
}
func recordBackupMetrics(backup *api.Backup, backupFile *os.File, serverMetrics *metrics.ServerMetrics) error {
backupScheduleName := backup.GetLabels()["ark-schedule"]
func recordBackupMetrics(backup *velerov1api.Backup, backupFile *os.File, serverMetrics *metrics.ServerMetrics) error {
backupScheduleName := backup.GetLabels()[velerov1api.ScheduleNameLabel]
var backupSizeBytes int64
var err error

View File

@@ -33,17 +33,17 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/clock"
"github.com/heptio/ark/pkg/apis/ark/v1"
pkgbackup "github.com/heptio/ark/pkg/backup"
"github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions"
"github.com/heptio/ark/pkg/metrics"
"github.com/heptio/ark/pkg/persistence"
persistencemocks "github.com/heptio/ark/pkg/persistence/mocks"
"github.com/heptio/ark/pkg/plugin"
pluginmocks "github.com/heptio/ark/pkg/plugin/mocks"
"github.com/heptio/ark/pkg/util/logging"
arktest "github.com/heptio/ark/pkg/util/test"
v1 "github.com/heptio/velero/pkg/apis/velero/v1"
pkgbackup "github.com/heptio/velero/pkg/backup"
"github.com/heptio/velero/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions"
"github.com/heptio/velero/pkg/metrics"
"github.com/heptio/velero/pkg/persistence"
persistencemocks "github.com/heptio/velero/pkg/persistence/mocks"
"github.com/heptio/velero/pkg/plugin"
pluginmocks "github.com/heptio/velero/pkg/plugin/mocks"
"github.com/heptio/velero/pkg/util/logging"
velerotest "github.com/heptio/velero/pkg/util/test"
)
type fakeBackupper struct {
@@ -70,27 +70,27 @@ func TestProcessBackupNonProcessedItems(t *testing.T) {
{
name: "backup not found in lister returns error",
key: "nonexistent/backup",
expectedErr: "error getting backup: backup.ark.heptio.com \"backup\" not found",
expectedErr: "error getting backup: backup.velero.io \"backup\" not found",
},
{
name: "FailedValidation backup is not processed",
key: "heptio-ark/backup-1",
backup: arktest.NewTestBackup().WithName("backup-1").WithPhase(v1.BackupPhaseFailedValidation).Backup,
key: "velero/backup-1",
backup: velerotest.NewTestBackup().WithName("backup-1").WithPhase(v1.BackupPhaseFailedValidation).Backup,
},
{
name: "InProgress backup is not processed",
key: "heptio-ark/backup-1",
backup: arktest.NewTestBackup().WithName("backup-1").WithPhase(v1.BackupPhaseInProgress).Backup,
key: "velero/backup-1",
backup: velerotest.NewTestBackup().WithName("backup-1").WithPhase(v1.BackupPhaseInProgress).Backup,
},
{
name: "Completed backup is not processed",
key: "heptio-ark/backup-1",
backup: arktest.NewTestBackup().WithName("backup-1").WithPhase(v1.BackupPhaseCompleted).Backup,
key: "velero/backup-1",
backup: velerotest.NewTestBackup().WithName("backup-1").WithPhase(v1.BackupPhaseCompleted).Backup,
},
{
name: "Failed backup is not processed",
key: "heptio-ark/backup-1",
backup: arktest.NewTestBackup().WithName("backup-1").WithPhase(v1.BackupPhaseFailed).Backup,
key: "velero/backup-1",
backup: velerotest.NewTestBackup().WithName("backup-1").WithPhase(v1.BackupPhaseFailed).Backup,
},
}
@@ -103,11 +103,11 @@ func TestProcessBackupNonProcessedItems(t *testing.T) {
c := &backupController{
genericController: newGenericController("backup-test", logger),
lister: sharedInformers.Ark().V1().Backups().Lister(),
lister: sharedInformers.Velero().V1().Backups().Lister(),
}
if test.backup != nil {
require.NoError(t, sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(test.backup))
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(test.backup))
}
err := c.processBackup(test.key)
@@ -127,7 +127,7 @@ func TestProcessBackupNonProcessedItems(t *testing.T) {
}
func TestProcessBackupValidationFailures(t *testing.T) {
defaultBackupLocation := arktest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation
defaultBackupLocation := velerotest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation
tests := []struct {
name string
@@ -137,20 +137,20 @@ func TestProcessBackupValidationFailures(t *testing.T) {
}{
{
name: "invalid included/excluded resources fails validation",
backup: arktest.NewTestBackup().WithName("backup-1").WithIncludedResources("foo").WithExcludedResources("foo").Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").WithIncludedResources("foo").WithExcludedResources("foo").Backup,
backupLocation: defaultBackupLocation,
expectedErrs: []string{"Invalid included/excluded resource lists: excludes list cannot contain an item in the includes list: foo"},
},
{
name: "invalid included/excluded namespaces fails validation",
backup: arktest.NewTestBackup().WithName("backup-1").WithIncludedNamespaces("foo").WithExcludedNamespaces("foo").Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").WithIncludedNamespaces("foo").WithExcludedNamespaces("foo").Backup,
backupLocation: defaultBackupLocation,
expectedErrs: []string{"Invalid included/excluded namespace lists: excludes list cannot contain an item in the includes list: foo"},
},
{
name: "non-existent backup location fails validation",
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("nonexistent").Backup,
expectedErrs: []string{"a BackupStorageLocation CRD with the name specified in the backup spec needs to be created before this backup can be executed. Error: backupstoragelocation.ark.heptio.com \"nonexistent\" not found"},
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("nonexistent").Backup,
expectedErrs: []string{"a BackupStorageLocation CRD with the name specified in the backup spec needs to be created before this backup can be executed. Error: backupstoragelocation.velero.io \"nonexistent\" not found"},
},
}
@@ -164,26 +164,26 @@ func TestProcessBackupValidationFailures(t *testing.T) {
c := &backupController{
genericController: newGenericController("backup-test", logger),
client: clientset.ArkV1(),
lister: sharedInformers.Ark().V1().Backups().Lister(),
backupLocationLister: sharedInformers.Ark().V1().BackupStorageLocations().Lister(),
snapshotLocationLister: sharedInformers.Ark().V1().VolumeSnapshotLocations().Lister(),
client: clientset.VeleroV1(),
lister: sharedInformers.Velero().V1().Backups().Lister(),
backupLocationLister: sharedInformers.Velero().V1().BackupStorageLocations().Lister(),
snapshotLocationLister: sharedInformers.Velero().V1().VolumeSnapshotLocations().Lister(),
defaultBackupLocation: defaultBackupLocation.Name,
}
require.NotNil(t, test.backup)
require.NoError(t, sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(test.backup))
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(test.backup))
if test.backupLocation != nil {
_, err := clientset.ArkV1().BackupStorageLocations(test.backupLocation.Namespace).Create(test.backupLocation)
_, err := clientset.VeleroV1().BackupStorageLocations(test.backupLocation.Namespace).Create(test.backupLocation)
require.NoError(t, err)
require.NoError(t, sharedInformers.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(test.backupLocation))
require.NoError(t, sharedInformers.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(test.backupLocation))
}
require.NoError(t, c.processBackup(fmt.Sprintf("%s/%s", test.backup.Namespace, test.backup.Name)))
res, err := clientset.ArkV1().Backups(test.backup.Namespace).Get(test.backup.Name, metav1.GetOptions{})
res, err := clientset.VeleroV1().Backups(test.backup.Namespace).Get(test.backup.Name, metav1.GetOptions{})
require.NoError(t, err)
assert.Equal(t, v1.BackupPhaseFailedValidation, res.Status.Phase)
@@ -198,7 +198,7 @@ func TestProcessBackupValidationFailures(t *testing.T) {
}
func TestProcessBackupCompletions(t *testing.T) {
defaultBackupLocation := arktest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation
defaultBackupLocation := velerotest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation
now, err := time.Parse(time.RFC1123Z, time.RFC1123Z)
require.NoError(t, err)
@@ -212,14 +212,14 @@ func TestProcessBackupCompletions(t *testing.T) {
}{
{
name: "backup with no backup location gets the default",
backup: arktest.NewTestBackup().WithName("backup-1").Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").Backup,
backupLocation: defaultBackupLocation,
expectedResult: &v1.Backup{
ObjectMeta: metav1.ObjectMeta{
Namespace: v1.DefaultNamespace,
Name: "backup-1",
Labels: map[string]string{
"ark.heptio.com/storage-location": "loc-1",
"velero.io/storage-location": "loc-1",
},
},
Spec: v1.BackupSpec{
@@ -235,14 +235,14 @@ func TestProcessBackupCompletions(t *testing.T) {
},
{
name: "backup with a specific backup location keeps it",
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("alt-loc").Backup,
backupLocation: arktest.NewTestBackupStorageLocation().WithName("alt-loc").BackupStorageLocation,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("alt-loc").Backup,
backupLocation: velerotest.NewTestBackupStorageLocation().WithName("alt-loc").BackupStorageLocation,
expectedResult: &v1.Backup{
ObjectMeta: metav1.ObjectMeta{
Namespace: v1.DefaultNamespace,
Name: "backup-1",
Labels: map[string]string{
"ark.heptio.com/storage-location": "alt-loc",
"velero.io/storage-location": "alt-loc",
},
},
Spec: v1.BackupSpec{
@@ -258,14 +258,14 @@ func TestProcessBackupCompletions(t *testing.T) {
},
{
name: "backup with a TTL has expiration set",
backup: arktest.NewTestBackup().WithName("backup-1").WithTTL(10 * time.Minute).Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").WithTTL(10 * time.Minute).Backup,
backupLocation: defaultBackupLocation,
expectedResult: &v1.Backup{
ObjectMeta: metav1.ObjectMeta{
Namespace: v1.DefaultNamespace,
Name: "backup-1",
Labels: map[string]string{
"ark.heptio.com/storage-location": "loc-1",
"velero.io/storage-location": "loc-1",
},
},
Spec: v1.BackupSpec{
@@ -296,10 +296,10 @@ func TestProcessBackupCompletions(t *testing.T) {
c := &backupController{
genericController: newGenericController("backup-test", logger),
client: clientset.ArkV1(),
lister: sharedInformers.Ark().V1().Backups().Lister(),
backupLocationLister: sharedInformers.Ark().V1().BackupStorageLocations().Lister(),
snapshotLocationLister: sharedInformers.Ark().V1().VolumeSnapshotLocations().Lister(),
client: clientset.VeleroV1(),
lister: sharedInformers.Velero().V1().Backups().Lister(),
backupLocationLister: sharedInformers.Velero().V1().BackupStorageLocations().Lister(),
snapshotLocationLister: sharedInformers.Velero().V1().VolumeSnapshotLocations().Lister(),
defaultBackupLocation: defaultBackupLocation.Name,
backupTracker: NewBackupTracker(),
metrics: metrics.NewServerMetrics(),
@@ -325,26 +325,26 @@ func TestProcessBackupCompletions(t *testing.T) {
// add the test's backup to the informer/lister store
require.NotNil(t, test.backup)
require.NoError(t, sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(test.backup))
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(test.backup))
// add the default backup storage location to the clientset and the informer/lister store
_, err := clientset.ArkV1().BackupStorageLocations(defaultBackupLocation.Namespace).Create(defaultBackupLocation)
_, err := clientset.VeleroV1().BackupStorageLocations(defaultBackupLocation.Namespace).Create(defaultBackupLocation)
require.NoError(t, err)
require.NoError(t, sharedInformers.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(defaultBackupLocation))
require.NoError(t, sharedInformers.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(defaultBackupLocation))
// add the test's backup storage location to the clientset and the informer/lister store
// if it's different than the default
if test.backupLocation != nil && test.backupLocation != defaultBackupLocation {
_, err := clientset.ArkV1().BackupStorageLocations(test.backupLocation.Namespace).Create(test.backupLocation)
_, err := clientset.VeleroV1().BackupStorageLocations(test.backupLocation.Namespace).Create(test.backupLocation)
require.NoError(t, err)
require.NoError(t, sharedInformers.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(test.backupLocation))
require.NoError(t, sharedInformers.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(test.backupLocation))
}
require.NoError(t, c.processBackup(fmt.Sprintf("%s/%s", test.backup.Namespace, test.backup.Name)))
res, err := clientset.ArkV1().Backups(test.backup.Namespace).Get(test.backup.Name, metav1.GetOptions{})
res, err := clientset.VeleroV1().Backups(test.backup.Namespace).Get(test.backup.Name, metav1.GetOptions{})
require.NoError(t, err)
assert.Equal(t, test.expectedResult, res)
@@ -355,8 +355,8 @@ func TestProcessBackupCompletions(t *testing.T) {
func TestValidateAndGetSnapshotLocations(t *testing.T) {
tests := []struct {
name string
backup *arktest.TestBackup
locations []*arktest.TestVolumeSnapshotLocation
backup *velerotest.TestBackup
locations []*velerotest.TestVolumeSnapshotLocation
defaultLocations map[string]string
expectedVolumeSnapshotLocationNames []string // adding these in the expected order will allow to test with better msgs in case of a test failure
expectedErrors string
@@ -364,76 +364,76 @@ func TestValidateAndGetSnapshotLocations(t *testing.T) {
}{
{
name: "location name does not correspond to any existing location",
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithVolumeSnapshotLocations("random-name"),
locations: []*arktest.TestVolumeSnapshotLocation{
arktest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-east-1"),
arktest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-west-1"),
arktest.NewTestVolumeSnapshotLocation().WithProvider("fake-provider").WithName("some-name"),
backup: velerotest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithVolumeSnapshotLocations("random-name"),
locations: []*velerotest.TestVolumeSnapshotLocation{
velerotest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-east-1"),
velerotest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-west-1"),
velerotest.NewTestVolumeSnapshotLocation().WithProvider("fake-provider").WithName("some-name"),
},
expectedErrors: "a VolumeSnapshotLocation CRD for the location random-name with the name specified in the backup spec needs to be created before this snapshot can be executed. Error: volumesnapshotlocation.ark.heptio.com \"random-name\" not found", expectedSuccess: false,
expectedErrors: "a VolumeSnapshotLocation CRD for the location random-name with the name specified in the backup spec needs to be created before this snapshot can be executed. Error: volumesnapshotlocation.velero.io \"random-name\" not found", expectedSuccess: false,
},
{
name: "duplicate locationName per provider: should filter out dups",
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithVolumeSnapshotLocations("aws-us-west-1", "aws-us-west-1"),
locations: []*arktest.TestVolumeSnapshotLocation{
arktest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-east-1"),
arktest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-west-1"),
backup: velerotest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithVolumeSnapshotLocations("aws-us-west-1", "aws-us-west-1"),
locations: []*velerotest.TestVolumeSnapshotLocation{
velerotest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-east-1"),
velerotest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-west-1"),
},
expectedVolumeSnapshotLocationNames: []string{"aws-us-west-1"},
expectedSuccess: true,
},
{
name: "multiple non-dupe location names per provider should error",
backup: arktest.NewTestBackup().WithName("backup1").WithVolumeSnapshotLocations("aws-us-east-1", "aws-us-west-1"),
locations: []*arktest.TestVolumeSnapshotLocation{
arktest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-east-1"),
arktest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-west-1"),
arktest.NewTestVolumeSnapshotLocation().WithProvider("fake-provider").WithName("some-name"),
backup: velerotest.NewTestBackup().WithName("backup1").WithVolumeSnapshotLocations("aws-us-east-1", "aws-us-west-1"),
locations: []*velerotest.TestVolumeSnapshotLocation{
velerotest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-east-1"),
velerotest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-west-1"),
velerotest.NewTestVolumeSnapshotLocation().WithProvider("fake-provider").WithName("some-name"),
},
expectedErrors: "more than one VolumeSnapshotLocation name specified for provider aws: aws-us-west-1; unexpected name was aws-us-east-1",
expectedSuccess: false,
},
{
name: "no location name for the provider exists, only one VSL for the provider: use it",
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew),
locations: []*arktest.TestVolumeSnapshotLocation{
arktest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-east-1"),
backup: velerotest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew),
locations: []*velerotest.TestVolumeSnapshotLocation{
velerotest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-east-1"),
},
expectedVolumeSnapshotLocationNames: []string{"aws-us-east-1"},
expectedSuccess: true,
},
{
name: "no location name for the provider exists, no default, more than one VSL for the provider: error",
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew),
locations: []*arktest.TestVolumeSnapshotLocation{
arktest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-east-1"),
arktest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-west-1"),
backup: velerotest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew),
locations: []*velerotest.TestVolumeSnapshotLocation{
velerotest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-east-1"),
velerotest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-west-1"),
},
expectedErrors: "provider aws has more than one possible volume snapshot location, and none were specified explicitly or as a default",
},
{
name: "no location name for the provider exists, more than one VSL for the provider: the provider's default should be added",
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew),
backup: velerotest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew),
defaultLocations: map[string]string{"aws": "aws-us-east-1"},
locations: []*arktest.TestVolumeSnapshotLocation{
arktest.NewTestVolumeSnapshotLocation().WithName("aws-us-east-1").WithProvider("aws"),
arktest.NewTestVolumeSnapshotLocation().WithName("aws-us-west-1").WithProvider("aws"),
locations: []*velerotest.TestVolumeSnapshotLocation{
velerotest.NewTestVolumeSnapshotLocation().WithName("aws-us-east-1").WithProvider("aws"),
velerotest.NewTestVolumeSnapshotLocation().WithName("aws-us-west-1").WithProvider("aws"),
},
expectedVolumeSnapshotLocationNames: []string{"aws-us-east-1"},
expectedSuccess: true,
},
{
name: "no existing location name and no default location name given",
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew),
backup: velerotest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew),
expectedSuccess: true,
},
{
name: "multiple location names for a provider, default location name for another provider",
backup: arktest.NewTestBackup().WithName("backup1").WithVolumeSnapshotLocations("aws-us-west-1", "aws-us-west-1"),
backup: velerotest.NewTestBackup().WithName("backup1").WithVolumeSnapshotLocations("aws-us-west-1", "aws-us-west-1"),
defaultLocations: map[string]string{"fake-provider": "some-name"},
locations: []*arktest.TestVolumeSnapshotLocation{
arktest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-west-1"),
arktest.NewTestVolumeSnapshotLocation().WithProvider("fake-provider").WithName("some-name"),
locations: []*velerotest.TestVolumeSnapshotLocation{
velerotest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-west-1"),
velerotest.NewTestVolumeSnapshotLocation().WithProvider("fake-provider").WithName("some-name"),
},
expectedVolumeSnapshotLocationNames: []string{"aws-us-west-1", "some-name"},
expectedSuccess: true,
@@ -448,7 +448,7 @@ func TestValidateAndGetSnapshotLocations(t *testing.T) {
)
c := &backupController{
snapshotLocationLister: sharedInformers.Ark().V1().VolumeSnapshotLocations().Lister(),
snapshotLocationLister: sharedInformers.Velero().V1().VolumeSnapshotLocations().Lister(),
defaultSnapshotLocations: test.defaultLocations,
}
@@ -456,7 +456,7 @@ func TestValidateAndGetSnapshotLocations(t *testing.T) {
backup := test.backup.DeepCopy()
backup.Spec.VolumeSnapshotLocations = test.backup.Spec.VolumeSnapshotLocations
for _, location := range test.locations {
require.NoError(t, sharedInformers.Ark().V1().VolumeSnapshotLocations().Informer().GetStore().Add(location.VolumeSnapshotLocation))
require.NoError(t, sharedInformers.Velero().V1().VolumeSnapshotLocations().Informer().GetStore().Add(location.VolumeSnapshotLocation))
}
providerLocations, errs := c.validateAndGetSnapshotLocations(backup)

View File

@@ -32,16 +32,16 @@ import (
kubeerrs "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/cache"
"github.com/heptio/ark/pkg/apis/ark/v1"
pkgbackup "github.com/heptio/ark/pkg/backup"
"github.com/heptio/ark/pkg/cloudprovider"
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/persistence"
"github.com/heptio/ark/pkg/plugin"
"github.com/heptio/ark/pkg/restic"
"github.com/heptio/ark/pkg/util/kube"
v1 "github.com/heptio/velero/pkg/apis/velero/v1"
pkgbackup "github.com/heptio/velero/pkg/backup"
"github.com/heptio/velero/pkg/cloudprovider"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/persistence"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/restic"
"github.com/heptio/velero/pkg/util/kube"
)
const resticTimeout = time.Minute
@@ -49,11 +49,11 @@ const resticTimeout = time.Minute
type backupDeletionController struct {
*genericController
deleteBackupRequestClient arkv1client.DeleteBackupRequestsGetter
deleteBackupRequestClient velerov1client.DeleteBackupRequestsGetter
deleteBackupRequestLister listers.DeleteBackupRequestLister
backupClient arkv1client.BackupsGetter
backupClient velerov1client.BackupsGetter
restoreLister listers.RestoreLister
restoreClient arkv1client.RestoresGetter
restoreClient velerov1client.RestoresGetter
backupTracker BackupTracker
resticMgr restic.RepositoryManager
podvolumeBackupLister listers.PodVolumeBackupLister
@@ -69,10 +69,10 @@ type backupDeletionController struct {
func NewBackupDeletionController(
logger logrus.FieldLogger,
deleteBackupRequestInformer informers.DeleteBackupRequestInformer,
deleteBackupRequestClient arkv1client.DeleteBackupRequestsGetter,
backupClient arkv1client.BackupsGetter,
deleteBackupRequestClient velerov1client.DeleteBackupRequestsGetter,
backupClient velerov1client.BackupsGetter,
restoreInformer informers.RestoreInformer,
restoreClient arkv1client.RestoresGetter,
restoreClient velerov1client.RestoresGetter,
backupTracker BackupTracker,
resticMgr restic.RepositoryManager,
podvolumeBackupInformer informers.PodVolumeBackupInformer,

View File

@@ -32,16 +32,16 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
core "k8s.io/client-go/testing"
"github.com/heptio/ark/pkg/apis/ark/v1"
pkgbackup "github.com/heptio/ark/pkg/backup"
"github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions"
"github.com/heptio/ark/pkg/persistence"
persistencemocks "github.com/heptio/ark/pkg/persistence/mocks"
"github.com/heptio/ark/pkg/plugin"
pluginmocks "github.com/heptio/ark/pkg/plugin/mocks"
arktest "github.com/heptio/ark/pkg/util/test"
"github.com/heptio/ark/pkg/volume"
v1 "github.com/heptio/velero/pkg/apis/velero/v1"
pkgbackup "github.com/heptio/velero/pkg/backup"
"github.com/heptio/velero/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions"
"github.com/heptio/velero/pkg/persistence"
persistencemocks "github.com/heptio/velero/pkg/persistence/mocks"
"github.com/heptio/velero/pkg/plugin"
pluginmocks "github.com/heptio/velero/pkg/plugin/mocks"
velerotest "github.com/heptio/velero/pkg/util/test"
"github.com/heptio/velero/pkg/volume"
)
func TestBackupDeletionControllerProcessQueueItem(t *testing.T) {
@@ -49,17 +49,17 @@ func TestBackupDeletionControllerProcessQueueItem(t *testing.T) {
sharedInformers := informers.NewSharedInformerFactory(client, 0)
controller := NewBackupDeletionController(
arktest.NewLogger(),
sharedInformers.Ark().V1().DeleteBackupRequests(),
client.ArkV1(), // deleteBackupRequestClient
client.ArkV1(), // backupClient
sharedInformers.Ark().V1().Restores(),
client.ArkV1(), // restoreClient
velerotest.NewLogger(),
sharedInformers.Velero().V1().DeleteBackupRequests(),
client.VeleroV1(), // deleteBackupRequestClient
client.VeleroV1(), // backupClient
sharedInformers.Velero().V1().Restores(),
client.VeleroV1(), // restoreClient
NewBackupTracker(),
nil, // restic repository manager
sharedInformers.Ark().V1().PodVolumeBackups(),
sharedInformers.Ark().V1().BackupStorageLocations(),
sharedInformers.Ark().V1().VolumeSnapshotLocations(),
sharedInformers.Velero().V1().PodVolumeBackups(),
sharedInformers.Velero().V1().BackupStorageLocations(),
sharedInformers.Velero().V1().VolumeSnapshotLocations(),
nil, // new plugin manager func
).(*backupDeletionController)
@@ -84,7 +84,7 @@ func TestBackupDeletionControllerProcessQueueItem(t *testing.T) {
for _, phase := range []v1.DeleteBackupRequestPhase{"", v1.DeleteBackupRequestPhaseNew, v1.DeleteBackupRequestPhaseInProgress} {
t.Run(fmt.Sprintf("phase=%s", phase), func(t *testing.T) {
req.Status.Phase = phase
sharedInformers.Ark().V1().DeleteBackupRequests().Informer().GetStore().Add(req)
sharedInformers.Velero().V1().DeleteBackupRequests().Informer().GetStore().Add(req)
var errorToReturn error
var actual *v1.DeleteBackupRequest
@@ -113,7 +113,7 @@ func TestBackupDeletionControllerProcessQueueItem(t *testing.T) {
type backupDeletionControllerTestData struct {
client *fake.Clientset
sharedInformers informers.SharedInformerFactory
blockStore *arktest.FakeBlockStore
blockStore *velerotest.FakeBlockStore
backupStore *persistencemocks.BackupStore
controller *backupDeletionController
req *v1.DeleteBackupRequest
@@ -123,7 +123,7 @@ func setupBackupDeletionControllerTest(objects ...runtime.Object) *backupDeletio
var (
client = fake.NewSimpleClientset(objects...)
sharedInformers = informers.NewSharedInformerFactory(client, 0)
blockStore = &arktest.FakeBlockStore{SnapshotsTaken: sets.NewString()}
blockStore = &velerotest.FakeBlockStore{SnapshotsTaken: sets.NewString()}
pluginManager = &pluginmocks.Manager{}
backupStore = &persistencemocks.BackupStore{}
req = pkgbackup.NewDeleteBackupRequest("foo", "uid")
@@ -135,17 +135,17 @@ func setupBackupDeletionControllerTest(objects ...runtime.Object) *backupDeletio
blockStore: blockStore,
backupStore: backupStore,
controller: NewBackupDeletionController(
arktest.NewLogger(),
sharedInformers.Ark().V1().DeleteBackupRequests(),
client.ArkV1(), // deleteBackupRequestClient
client.ArkV1(), // backupClient
sharedInformers.Ark().V1().Restores(),
client.ArkV1(), // restoreClient
velerotest.NewLogger(),
sharedInformers.Velero().V1().DeleteBackupRequests(),
client.VeleroV1(), // deleteBackupRequestClient
client.VeleroV1(), // backupClient
sharedInformers.Velero().V1().Restores(),
client.VeleroV1(), // restoreClient
NewBackupTracker(),
nil, // restic repository manager
sharedInformers.Ark().V1().PodVolumeBackups(),
sharedInformers.Ark().V1().BackupStorageLocations(),
sharedInformers.Ark().V1().VolumeSnapshotLocations(),
sharedInformers.Velero().V1().PodVolumeBackups(),
sharedInformers.Velero().V1().BackupStorageLocations(),
sharedInformers.Velero().V1().VolumeSnapshotLocations(),
func(logrus.FieldLogger) plugin.Manager { return pluginManager },
).(*backupDeletionController),
@@ -158,7 +158,7 @@ func setupBackupDeletionControllerTest(objects ...runtime.Object) *backupDeletio
pluginManager.On("CleanupClients").Return(nil)
req.Namespace = "heptio-ark"
req.Namespace = "velero"
req.Name = "foo-abcde"
return data
@@ -192,7 +192,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
// past checking for an in-progress backup. this makes validation easier.
td.controller.backupTracker.Add(td.req.Namespace, td.req.Spec.BackupName)
require.NoError(t, td.sharedInformers.Ark().V1().DeleteBackupRequests().Informer().GetStore().Add(td.req))
require.NoError(t, td.sharedInformers.Velero().V1().DeleteBackupRequests().Informer().GetStore().Add(td.req))
existing := &v1.DeleteBackupRequest{
ObjectMeta: metav1.ObjectMeta{
@@ -206,11 +206,11 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
BackupName: td.req.Spec.BackupName,
},
}
require.NoError(t, td.sharedInformers.Ark().V1().DeleteBackupRequests().Informer().GetStore().Add(existing))
_, err := td.client.ArkV1().DeleteBackupRequests(td.req.Namespace).Create(existing)
require.NoError(t, td.sharedInformers.Velero().V1().DeleteBackupRequests().Informer().GetStore().Add(existing))
_, err := td.client.VeleroV1().DeleteBackupRequests(td.req.Namespace).Create(existing)
require.NoError(t, err)
require.NoError(t, td.sharedInformers.Ark().V1().DeleteBackupRequests().Informer().GetStore().Add(
require.NoError(t, td.sharedInformers.Velero().V1().DeleteBackupRequests().Informer().GetStore().Add(
&v1.DeleteBackupRequest{
ObjectMeta: metav1.ObjectMeta{
Namespace: td.req.Namespace,
@@ -272,7 +272,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
})
t.Run("patching backup to Deleting fails", func(t *testing.T) {
backup := arktest.NewTestBackup().WithName("foo").WithSnapshot("pv-1", "snap-1").Backup
backup := velerotest.NewTestBackup().WithName("foo").WithSnapshot("pv-1", "snap-1").Backup
td := setupBackupDeletionControllerTest(backup)
td.client.PrependReactor("patch", "deletebackuprequests", func(action core.Action) (bool, runtime.Object, error) {
@@ -324,7 +324,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
})
t.Run("pre-v0.10 backup with snapshots, no errors", func(t *testing.T) {
backup := arktest.NewTestBackup().WithName("foo").Backup
backup := velerotest.NewTestBackup().WithName("foo").Backup
backup.UID = "uid"
backup.Spec.StorageLocation = "primary"
backup.Status.VolumeBackups = map[string]*v1.VolumeBackupInfo{
@@ -333,15 +333,15 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
},
}
restore1 := arktest.NewTestRestore("heptio-ark", "restore-1", v1.RestorePhaseCompleted).WithBackup("foo").Restore
restore2 := arktest.NewTestRestore("heptio-ark", "restore-2", v1.RestorePhaseCompleted).WithBackup("foo").Restore
restore3 := arktest.NewTestRestore("heptio-ark", "restore-3", v1.RestorePhaseCompleted).WithBackup("some-other-backup").Restore
restore1 := velerotest.NewTestRestore("velero", "restore-1", v1.RestorePhaseCompleted).WithBackup("foo").Restore
restore2 := velerotest.NewTestRestore("velero", "restore-2", v1.RestorePhaseCompleted).WithBackup("foo").Restore
restore3 := velerotest.NewTestRestore("velero", "restore-3", v1.RestorePhaseCompleted).WithBackup("some-other-backup").Restore
td := setupBackupDeletionControllerTest(backup, restore1, restore2, restore3)
td.sharedInformers.Ark().V1().Restores().Informer().GetStore().Add(restore1)
td.sharedInformers.Ark().V1().Restores().Informer().GetStore().Add(restore2)
td.sharedInformers.Ark().V1().Restores().Informer().GetStore().Add(restore3)
td.sharedInformers.Velero().V1().Restores().Informer().GetStore().Add(restore1)
td.sharedInformers.Velero().V1().Restores().Informer().GetStore().Add(restore2)
td.sharedInformers.Velero().V1().Restores().Informer().GetStore().Add(restore3)
location := &v1.BackupStorageLocation{
ObjectMeta: metav1.ObjectMeta{
@@ -357,7 +357,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
},
},
}
require.NoError(t, td.sharedInformers.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(location))
require.NoError(t, td.sharedInformers.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(location))
snapshotLocation := &v1.VolumeSnapshotLocation{
ObjectMeta: metav1.ObjectMeta{
@@ -368,7 +368,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
Provider: "provider-1",
},
}
require.NoError(t, td.sharedInformers.Ark().V1().VolumeSnapshotLocations().Informer().GetStore().Add(snapshotLocation))
require.NoError(t, td.sharedInformers.Velero().V1().VolumeSnapshotLocations().Informer().GetStore().Add(snapshotLocation))
// Clear out req labels to make sure the controller adds them
td.req.Labels = make(map[string]string)
@@ -403,7 +403,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
v1.SchemeGroupVersion.WithResource("deletebackuprequests"),
td.req.Namespace,
td.req.Name,
[]byte(`{"metadata":{"labels":{"ark.heptio.com/backup-name":"foo"}},"status":{"phase":"InProgress"}}`),
[]byte(`{"metadata":{"labels":{"velero.io/backup-name":"foo"}},"status":{"phase":"InProgress"}}`),
),
core.NewGetAction(
v1.SchemeGroupVersion.WithResource("backups"),
@@ -414,7 +414,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
v1.SchemeGroupVersion.WithResource("deletebackuprequests"),
td.req.Namespace,
td.req.Name,
[]byte(`{"metadata":{"labels":{"ark.heptio.com/backup-uid":"uid"}}}`),
[]byte(`{"metadata":{"labels":{"velero.io/backup-uid":"uid"}}}`),
),
core.NewPatchAction(
v1.SchemeGroupVersion.WithResource("backups"),
@@ -450,26 +450,26 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
),
}
arktest.CompareActions(t, expectedActions, td.client.Actions())
velerotest.CompareActions(t, expectedActions, td.client.Actions())
// Make sure snapshot was deleted
assert.Equal(t, 0, td.blockStore.SnapshotsTaken.Len())
})
t.Run("full delete, no errors", func(t *testing.T) {
backup := arktest.NewTestBackup().WithName("foo").Backup
backup := velerotest.NewTestBackup().WithName("foo").Backup
backup.UID = "uid"
backup.Spec.StorageLocation = "primary"
restore1 := arktest.NewTestRestore("heptio-ark", "restore-1", v1.RestorePhaseCompleted).WithBackup("foo").Restore
restore2 := arktest.NewTestRestore("heptio-ark", "restore-2", v1.RestorePhaseCompleted).WithBackup("foo").Restore
restore3 := arktest.NewTestRestore("heptio-ark", "restore-3", v1.RestorePhaseCompleted).WithBackup("some-other-backup").Restore
restore1 := velerotest.NewTestRestore("velero", "restore-1", v1.RestorePhaseCompleted).WithBackup("foo").Restore
restore2 := velerotest.NewTestRestore("velero", "restore-2", v1.RestorePhaseCompleted).WithBackup("foo").Restore
restore3 := velerotest.NewTestRestore("velero", "restore-3", v1.RestorePhaseCompleted).WithBackup("some-other-backup").Restore
td := setupBackupDeletionControllerTest(backup, restore1, restore2, restore3)
td.sharedInformers.Ark().V1().Restores().Informer().GetStore().Add(restore1)
td.sharedInformers.Ark().V1().Restores().Informer().GetStore().Add(restore2)
td.sharedInformers.Ark().V1().Restores().Informer().GetStore().Add(restore3)
td.sharedInformers.Velero().V1().Restores().Informer().GetStore().Add(restore1)
td.sharedInformers.Velero().V1().Restores().Informer().GetStore().Add(restore2)
td.sharedInformers.Velero().V1().Restores().Informer().GetStore().Add(restore3)
location := &v1.BackupStorageLocation{
ObjectMeta: metav1.ObjectMeta{
@@ -485,7 +485,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
},
},
}
require.NoError(t, td.sharedInformers.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(location))
require.NoError(t, td.sharedInformers.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(location))
snapshotLocation := &v1.VolumeSnapshotLocation{
ObjectMeta: metav1.ObjectMeta{
@@ -496,7 +496,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
Provider: "provider-1",
},
}
require.NoError(t, td.sharedInformers.Ark().V1().VolumeSnapshotLocations().Informer().GetStore().Add(snapshotLocation))
require.NoError(t, td.sharedInformers.Velero().V1().VolumeSnapshotLocations().Informer().GetStore().Add(snapshotLocation))
// Clear out req labels to make sure the controller adds them
td.req.Labels = make(map[string]string)
@@ -543,7 +543,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
v1.SchemeGroupVersion.WithResource("deletebackuprequests"),
td.req.Namespace,
td.req.Name,
[]byte(`{"metadata":{"labels":{"ark.heptio.com/backup-name":"foo"}},"status":{"phase":"InProgress"}}`),
[]byte(`{"metadata":{"labels":{"velero.io/backup-name":"foo"}},"status":{"phase":"InProgress"}}`),
),
core.NewGetAction(
v1.SchemeGroupVersion.WithResource("backups"),
@@ -554,7 +554,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
v1.SchemeGroupVersion.WithResource("deletebackuprequests"),
td.req.Namespace,
td.req.Name,
[]byte(`{"metadata":{"labels":{"ark.heptio.com/backup-uid":"uid"}}}`),
[]byte(`{"metadata":{"labels":{"velero.io/backup-uid":"uid"}}}`),
),
core.NewPatchAction(
v1.SchemeGroupVersion.WithResource("backups"),
@@ -590,7 +590,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
),
}
arktest.CompareActions(t, expectedActions, td.client.Actions())
velerotest.CompareActions(t, expectedActions, td.client.Actions())
// Make sure snapshot was deleted
assert.Equal(t, 0, td.blockStore.SnapshotsTaken.Len())
@@ -711,17 +711,17 @@ func TestBackupDeletionControllerDeleteExpiredRequests(t *testing.T) {
sharedInformers := informers.NewSharedInformerFactory(client, 0)
controller := NewBackupDeletionController(
arktest.NewLogger(),
sharedInformers.Ark().V1().DeleteBackupRequests(),
client.ArkV1(), // deleteBackupRequestClient
client.ArkV1(), // backupClient
sharedInformers.Ark().V1().Restores(),
client.ArkV1(), // restoreClient
velerotest.NewLogger(),
sharedInformers.Velero().V1().DeleteBackupRequests(),
client.VeleroV1(), // deleteBackupRequestClient
client.VeleroV1(), // backupClient
sharedInformers.Velero().V1().Restores(),
client.VeleroV1(), // restoreClient
NewBackupTracker(),
nil,
sharedInformers.Ark().V1().PodVolumeBackups(),
sharedInformers.Ark().V1().BackupStorageLocations(),
sharedInformers.Ark().V1().VolumeSnapshotLocations(),
sharedInformers.Velero().V1().PodVolumeBackups(),
sharedInformers.Velero().V1().BackupStorageLocations(),
sharedInformers.Velero().V1().VolumeSnapshotLocations(),
nil, // new plugin manager func
).(*backupDeletionController)
@@ -730,7 +730,7 @@ func TestBackupDeletionControllerDeleteExpiredRequests(t *testing.T) {
controller.clock = fakeClock
for i := range test.requests {
sharedInformers.Ark().V1().DeleteBackupRequests().Informer().GetStore().Add(test.requests[i])
sharedInformers.Velero().V1().DeleteBackupRequests().Informer().GetStore().Add(test.requests[i])
}
controller.deleteExpiredRequests()
@@ -740,7 +740,7 @@ func TestBackupDeletionControllerDeleteExpiredRequests(t *testing.T) {
expectedActions = append(expectedActions, core.NewDeleteAction(v1.SchemeGroupVersion.WithResource("deletebackuprequests"), "ns", name))
}
arktest.CompareActions(t, expectedActions, client.Actions())
velerotest.CompareActions(t, expectedActions, client.Actions())
})
}
}

View File

@@ -29,31 +29,31 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/cache"
arkv1api "github.com/heptio/ark/pkg/apis/ark/v1"
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/persistence"
"github.com/heptio/ark/pkg/plugin"
"github.com/heptio/ark/pkg/util/stringslice"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/persistence"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/util/stringslice"
)
type backupSyncController struct {
*genericController
backupClient arkv1client.BackupsGetter
backupLocationClient arkv1client.BackupStorageLocationsGetter
backupClient velerov1client.BackupsGetter
backupLocationClient velerov1client.BackupStorageLocationsGetter
backupLister listers.BackupLister
backupStorageLocationLister listers.BackupStorageLocationLister
namespace string
defaultBackupLocation string
newPluginManager func(logrus.FieldLogger) plugin.Manager
newBackupStore func(*arkv1api.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error)
newBackupStore func(*velerov1api.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error)
}
func NewBackupSyncController(
backupClient arkv1client.BackupsGetter,
backupLocationClient arkv1client.BackupStorageLocationsGetter,
backupClient velerov1client.BackupsGetter,
backupLocationClient velerov1client.BackupStorageLocationsGetter,
backupInformer informers.BackupInformer,
backupStorageLocationInformer informers.BackupStorageLocationInformer,
syncPeriod time.Duration,
@@ -92,9 +92,10 @@ func NewBackupSyncController(
return c
}
// TODO(1.0): remove this
const gcFinalizer = "gc.ark.heptio.com"
func shouldSync(location *arkv1api.BackupStorageLocation, now time.Time, backupStore persistence.BackupStore, log logrus.FieldLogger) (bool, string) {
func shouldSync(location *velerov1api.BackupStorageLocation, now time.Time, backupStore persistence.BackupStore, log logrus.FieldLogger) (bool, string) {
log = log.WithFields(map[string]interface{}{
"lastSyncedRevision": location.Status.LastSyncedRevision,
"lastSyncedTime": location.Status.LastSyncedTime.Time.Format(time.RFC1123Z),
@@ -123,8 +124,8 @@ func shouldSync(location *arkv1api.BackupStorageLocation, now time.Time, backupS
// orderedBackupLocations returns a new slice with the default backup location first (if it exists),
// followed by the rest of the locations in no particular order.
func orderedBackupLocations(locations []*arkv1api.BackupStorageLocation, defaultLocationName string) []*arkv1api.BackupStorageLocation {
var result []*arkv1api.BackupStorageLocation
func orderedBackupLocations(locations []*velerov1api.BackupStorageLocation, defaultLocationName string) []*velerov1api.BackupStorageLocation {
var result []*velerov1api.BackupStorageLocation
for i := range locations {
if locations[i].Name == defaultLocationName {
@@ -223,7 +224,7 @@ func (c *backupSyncController) run() {
if backup.Labels == nil {
backup.Labels = make(map[string]string)
}
backup.Labels[arkv1api.StorageLocationLabel] = backup.Spec.StorageLocation
backup.Labels[velerov1api.StorageLocationLabel] = backup.Spec.StorageLocation
_, err = c.backupClient.Backups(backup.Namespace).Create(backup)
switch {
@@ -265,7 +266,7 @@ func (c *backupSyncController) run() {
}
}
func patchStorageLocation(backup *arkv1api.Backup, client arkv1client.BackupInterface, location string) error {
func patchStorageLocation(backup *velerov1api.Backup, client velerov1client.BackupInterface, location string) error {
patch := map[string]interface{}{
"spec": map[string]interface{}{
"storageLocation": location,
@@ -288,7 +289,7 @@ func patchStorageLocation(backup *arkv1api.Backup, client arkv1client.BackupInte
// and a phase of Completed, but no corresponding backup in object storage.
func (c *backupSyncController) deleteOrphanedBackups(locationName string, cloudBackupNames sets.String, log logrus.FieldLogger) {
locationSelector := labels.Set(map[string]string{
arkv1api.StorageLocationLabel: locationName,
velerov1api.StorageLocationLabel: locationName,
}).AsSelector()
backups, err := c.backupLister.Backups(c.namespace).List(locationSelector)
@@ -302,7 +303,7 @@ func (c *backupSyncController) deleteOrphanedBackups(locationName string, cloudB
for _, backup := range backups {
log = log.WithField("backup", backup.Name)
if backup.Status.Phase != arkv1api.BackupPhaseCompleted || cloudBackupNames.Has(backup.Name) {
if backup.Status.Phase != velerov1api.BackupPhaseCompleted || cloudBackupNames.Has(backup.Name) {
continue
}

View File

@@ -30,28 +30,28 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
core "k8s.io/client-go/testing"
arkv1api "github.com/heptio/ark/pkg/apis/ark/v1"
"github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions"
"github.com/heptio/ark/pkg/persistence"
persistencemocks "github.com/heptio/ark/pkg/persistence/mocks"
"github.com/heptio/ark/pkg/plugin"
pluginmocks "github.com/heptio/ark/pkg/plugin/mocks"
"github.com/heptio/ark/pkg/util/stringslice"
arktest "github.com/heptio/ark/pkg/util/test"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
"github.com/heptio/velero/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions"
"github.com/heptio/velero/pkg/persistence"
persistencemocks "github.com/heptio/velero/pkg/persistence/mocks"
"github.com/heptio/velero/pkg/plugin"
pluginmocks "github.com/heptio/velero/pkg/plugin/mocks"
"github.com/heptio/velero/pkg/util/stringslice"
velerotest "github.com/heptio/velero/pkg/util/test"
)
func defaultLocationsList(namespace string) []*arkv1api.BackupStorageLocation {
return []*arkv1api.BackupStorageLocation{
func defaultLocationsList(namespace string) []*velerov1api.BackupStorageLocation {
return []*velerov1api.BackupStorageLocation{
{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "location-1",
},
Spec: arkv1api.BackupStorageLocationSpec{
Spec: velerov1api.BackupStorageLocationSpec{
Provider: "objStoreProvider",
StorageType: arkv1api.StorageType{
ObjectStorage: &arkv1api.ObjectStorageLocation{
StorageType: velerov1api.StorageType{
ObjectStorage: &velerov1api.ObjectStorageLocation{
Bucket: "bucket-1",
},
},
@@ -62,10 +62,10 @@ func defaultLocationsList(namespace string) []*arkv1api.BackupStorageLocation {
Namespace: namespace,
Name: "location-2",
},
Spec: arkv1api.BackupStorageLocationSpec{
Spec: velerov1api.BackupStorageLocationSpec{
Provider: "objStoreProvider",
StorageType: arkv1api.StorageType{
ObjectStorage: &arkv1api.ObjectStorageLocation{
StorageType: velerov1api.StorageType{
ObjectStorage: &velerov1api.ObjectStorageLocation{
Bucket: "bucket-2",
},
},
@@ -78,9 +78,9 @@ func TestBackupSyncControllerRun(t *testing.T) {
tests := []struct {
name string
namespace string
locations []*arkv1api.BackupStorageLocation
cloudBackups map[string][]*arkv1api.Backup
existingBackups []*arkv1api.Backup
locations []*velerov1api.BackupStorageLocation
cloudBackups map[string][]*velerov1api.Backup
existingBackups []*velerov1api.Backup
}{
{
name: "no cloud backups",
@@ -89,13 +89,13 @@ func TestBackupSyncControllerRun(t *testing.T) {
name: "normal case",
namespace: "ns-1",
locations: defaultLocationsList("ns-1"),
cloudBackups: map[string][]*arkv1api.Backup{
cloudBackups: map[string][]*velerov1api.Backup{
"bucket-1": {
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").Backup,
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").Backup,
},
"bucket-2": {
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").Backup,
},
},
},
@@ -103,24 +103,24 @@ func TestBackupSyncControllerRun(t *testing.T) {
name: "gcFinalizer (only) gets removed on sync",
namespace: "ns-1",
locations: defaultLocationsList("ns-1"),
cloudBackups: map[string][]*arkv1api.Backup{
cloudBackups: map[string][]*velerov1api.Backup{
"bucket-1": {
arktest.NewTestBackup().WithNamespace("ns-1").WithFinalizers("a-finalizer", gcFinalizer, "some-other-finalizer").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithFinalizers("a-finalizer", gcFinalizer, "some-other-finalizer").Backup,
},
},
},
{
name: "all synced backups get created in Ark server's namespace",
namespace: "heptio-ark",
locations: defaultLocationsList("heptio-ark"),
cloudBackups: map[string][]*arkv1api.Backup{
name: "all synced backups get created in Velero server's namespace",
namespace: "velero",
locations: defaultLocationsList("velero"),
cloudBackups: map[string][]*velerov1api.Backup{
"bucket-1": {
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").Backup,
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").Backup,
},
"bucket-2": {
arktest.NewTestBackup().WithNamespace("ns-2").WithName("backup-3").Backup,
arktest.NewTestBackup().WithNamespace("heptio-ark").WithName("backup-4").Backup,
velerotest.NewTestBackup().WithNamespace("ns-2").WithName("backup-3").Backup,
velerotest.NewTestBackup().WithNamespace("velero").WithName("backup-4").Backup,
},
},
},
@@ -128,49 +128,49 @@ func TestBackupSyncControllerRun(t *testing.T) {
name: "new backups get synced when some cloud backups already exist in the cluster",
namespace: "ns-1",
locations: defaultLocationsList("ns-1"),
cloudBackups: map[string][]*arkv1api.Backup{
cloudBackups: map[string][]*velerov1api.Backup{
"bucket-1": {
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").Backup,
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").Backup,
},
"bucket-2": {
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").Backup,
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-4").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-4").Backup,
},
},
existingBackups: []*arkv1api.Backup{
existingBackups: []*velerov1api.Backup{
// add a label to each existing backup so we can differentiate it from the cloud
// backup during verification
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel("i-exist", "true").WithStorageLocation("location-1").Backup,
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").WithLabel("i-exist", "true").WithStorageLocation("location-2").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel("i-exist", "true").WithStorageLocation("location-1").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").WithLabel("i-exist", "true").WithStorageLocation("location-2").Backup,
},
},
{
name: "existing backups without a StorageLocation get it filled in",
namespace: "ns-1",
locations: defaultLocationsList("ns-1"),
cloudBackups: map[string][]*arkv1api.Backup{
cloudBackups: map[string][]*velerov1api.Backup{
"bucket-1": {
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").Backup,
},
},
existingBackups: []*arkv1api.Backup{
existingBackups: []*velerov1api.Backup{
// add a label to each existing backup so we can differentiate it from the cloud
// backup during verification
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel("i-exist", "true").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel("i-exist", "true").Backup,
},
},
{
name: "backup storage location names and labels get updated",
namespace: "ns-1",
locations: defaultLocationsList("ns-1"),
cloudBackups: map[string][]*arkv1api.Backup{
cloudBackups: map[string][]*velerov1api.Backup{
"bucket-1": {
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithStorageLocation("foo").WithLabel(arkv1api.StorageLocationLabel, "foo").Backup,
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithStorageLocation("foo").WithLabel(velerov1api.StorageLocationLabel, "foo").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").Backup,
},
"bucket-2": {
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").WithStorageLocation("bar").WithLabel(arkv1api.StorageLocationLabel, "bar").Backup,
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").WithStorageLocation("bar").WithLabel(velerov1api.StorageLocationLabel, "bar").Backup,
},
},
},
@@ -186,18 +186,18 @@ func TestBackupSyncControllerRun(t *testing.T) {
)
c := NewBackupSyncController(
client.ArkV1(),
client.ArkV1(),
sharedInformers.Ark().V1().Backups(),
sharedInformers.Ark().V1().BackupStorageLocations(),
client.VeleroV1(),
client.VeleroV1(),
sharedInformers.Velero().V1().Backups(),
sharedInformers.Velero().V1().BackupStorageLocations(),
time.Duration(0),
test.namespace,
"",
func(logrus.FieldLogger) plugin.Manager { return pluginManager },
arktest.NewLogger(),
velerotest.NewLogger(),
).(*backupSyncController)
c.newBackupStore = func(loc *arkv1api.BackupStorageLocation, _ persistence.ObjectStoreGetter, _ logrus.FieldLogger) (persistence.BackupStore, error) {
c.newBackupStore = func(loc *velerov1api.BackupStorageLocation, _ persistence.ObjectStoreGetter, _ logrus.FieldLogger) (persistence.BackupStore, error) {
// this gets populated just below, prior to exercising the method under test
return backupStores[loc.Name], nil
}
@@ -205,7 +205,7 @@ func TestBackupSyncControllerRun(t *testing.T) {
pluginManager.On("CleanupClients").Return(nil)
for _, location := range test.locations {
require.NoError(t, sharedInformers.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(location))
require.NoError(t, sharedInformers.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(location))
backupStores[location.Name] = &persistencemocks.BackupStore{}
}
@@ -224,9 +224,9 @@ func TestBackupSyncControllerRun(t *testing.T) {
}
for _, existingBackup := range test.existingBackups {
require.NoError(t, sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(existingBackup))
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(existingBackup))
_, err := client.ArkV1().Backups(test.namespace).Create(existingBackup)
_, err := client.VeleroV1().Backups(test.namespace).Create(existingBackup)
require.NoError(t, err)
}
client.ClearActions()
@@ -236,7 +236,7 @@ func TestBackupSyncControllerRun(t *testing.T) {
for bucket, backups := range test.cloudBackups {
// figure out which location this bucket is for; we need this for verification
// purposes later
var location *arkv1api.BackupStorageLocation
var location *velerov1api.BackupStorageLocation
for _, loc := range test.locations {
if loc.Spec.ObjectStorage.Bucket == bucket {
location = loc
@@ -246,11 +246,11 @@ func TestBackupSyncControllerRun(t *testing.T) {
require.NotNil(t, location)
for _, cloudBackup := range backups {
obj, err := client.ArkV1().Backups(test.namespace).Get(cloudBackup.Name, metav1.GetOptions{})
obj, err := client.VeleroV1().Backups(test.namespace).Get(cloudBackup.Name, metav1.GetOptions{})
require.NoError(t, err)
// did this cloud backup already exist in the cluster?
var existing *arkv1api.Backup
var existing *velerov1api.Backup
for _, obj := range test.existingBackups {
if obj.Name == cloudBackup.Name {
existing = obj
@@ -273,7 +273,7 @@ func TestBackupSyncControllerRun(t *testing.T) {
// verify that the storage location field and label are set properly
assert.Equal(t, location.Name, obj.Spec.StorageLocation)
assert.Equal(t, location.Name, obj.Labels[arkv1api.StorageLocationLabel])
assert.Equal(t, location.Name, obj.Labels[velerov1api.StorageLocationLabel])
}
}
}
@@ -285,7 +285,7 @@ func TestDeleteOrphanedBackups(t *testing.T) {
tests := []struct {
name string
cloudBackups sets.String
k8sBackups []*arktest.TestBackup
k8sBackups []*velerotest.TestBackup
namespace string
expectedDeletes sets.String
}{
@@ -293,10 +293,10 @@ func TestDeleteOrphanedBackups(t *testing.T) {
name: "no overlapping backups",
namespace: "ns-1",
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
k8sBackups: []*arktest.TestBackup{
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backupA").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backupB").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backupC").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
k8sBackups: []*velerotest.TestBackup{
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backupA").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backupB").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backupC").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
},
expectedDeletes: sets.NewString("backupA", "backupB", "backupC"),
},
@@ -304,10 +304,10 @@ func TestDeleteOrphanedBackups(t *testing.T) {
name: "some overlapping backups",
namespace: "ns-1",
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
k8sBackups: []*arktest.TestBackup{
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-C").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
k8sBackups: []*velerotest.TestBackup{
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-C").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
},
expectedDeletes: sets.NewString("backup-C"),
},
@@ -315,10 +315,10 @@ func TestDeleteOrphanedBackups(t *testing.T) {
name: "all overlapping backups",
namespace: "ns-1",
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
k8sBackups: []*arktest.TestBackup{
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
k8sBackups: []*velerotest.TestBackup{
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
},
expectedDeletes: sets.NewString(),
},
@@ -326,13 +326,13 @@ func TestDeleteOrphanedBackups(t *testing.T) {
name: "no overlapping backups but including backups that are not complete",
namespace: "ns-1",
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
k8sBackups: []*arktest.TestBackup{
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backupA").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("Deleting").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseDeleting),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("Failed").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseFailed),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("FailedValidation").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseFailedValidation),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("InProgress").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseInProgress),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("New").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseNew),
k8sBackups: []*velerotest.TestBackup{
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backupA").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("Deleting").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseDeleting),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("Failed").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseFailed),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("FailedValidation").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseFailedValidation),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("InProgress").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseInProgress),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("New").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseNew),
},
expectedDeletes: sets.NewString("backupA"),
},
@@ -340,10 +340,10 @@ func TestDeleteOrphanedBackups(t *testing.T) {
name: "all overlapping backups and all backups that are not complete",
namespace: "ns-1",
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
k8sBackups: []*arktest.TestBackup{
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseFailed),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseFailedValidation),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseInProgress),
k8sBackups: []*velerotest.TestBackup{
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseFailed),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseFailedValidation),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseInProgress),
},
expectedDeletes: sets.NewString(),
},
@@ -351,13 +351,13 @@ func TestDeleteOrphanedBackups(t *testing.T) {
name: "no completed backups in other locations are deleted",
namespace: "ns-1",
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
k8sBackups: []*arktest.TestBackup{
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-C").WithLabel(arkv1api.StorageLocationLabel, "default").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-4").WithLabel(arkv1api.StorageLocationLabel, "alternate").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-5").WithLabel(arkv1api.StorageLocationLabel, "alternate").WithPhase(arkv1api.BackupPhaseCompleted),
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-6").WithLabel(arkv1api.StorageLocationLabel, "alternate").WithPhase(arkv1api.BackupPhaseCompleted),
k8sBackups: []*velerotest.TestBackup{
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-C").WithLabel(velerov1api.StorageLocationLabel, "default").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-4").WithLabel(velerov1api.StorageLocationLabel, "alternate").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-5").WithLabel(velerov1api.StorageLocationLabel, "alternate").WithPhase(velerov1api.BackupPhaseCompleted),
velerotest.NewTestBackup().WithNamespace("ns-1").WithName("backup-6").WithLabel(velerov1api.StorageLocationLabel, "alternate").WithPhase(velerov1api.BackupPhaseCompleted),
},
expectedDeletes: sets.NewString("backup-C"),
},
@@ -371,31 +371,31 @@ func TestDeleteOrphanedBackups(t *testing.T) {
)
c := NewBackupSyncController(
client.ArkV1(),
client.ArkV1(),
sharedInformers.Ark().V1().Backups(),
sharedInformers.Ark().V1().BackupStorageLocations(),
client.VeleroV1(),
client.VeleroV1(),
sharedInformers.Velero().V1().Backups(),
sharedInformers.Velero().V1().BackupStorageLocations(),
time.Duration(0),
test.namespace,
"",
nil, // new plugin manager func
arktest.NewLogger(),
velerotest.NewLogger(),
).(*backupSyncController)
expectedDeleteActions := make([]core.Action, 0)
for _, backup := range test.k8sBackups {
// add test backup to informer
require.NoError(t, sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(backup.Backup), "Error adding backup to informer")
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(backup.Backup), "Error adding backup to informer")
// add test backup to client
_, err := client.Ark().Backups(test.namespace).Create(backup.Backup)
_, err := client.VeleroV1().Backups(test.namespace).Create(backup.Backup)
require.NoError(t, err, "Error adding backup to clientset")
// if we expect this backup to be deleted, set up the expected DeleteAction
if test.expectedDeletes.Has(backup.Name) {
actionDelete := core.NewDeleteAction(
arkv1api.SchemeGroupVersion.WithResource("backups"),
velerov1api.SchemeGroupVersion.WithResource("backups"),
test.namespace,
backup.Name,
)
@@ -403,7 +403,7 @@ func TestDeleteOrphanedBackups(t *testing.T) {
}
}
c.deleteOrphanedBackups("default", test.cloudBackups, arktest.NewLogger())
c.deleteOrphanedBackups("default", test.cloudBackups, velerotest.NewLogger())
numBackups, err := numBackups(t, client, c.namespace)
assert.NoError(t, err)
@@ -411,7 +411,7 @@ func TestDeleteOrphanedBackups(t *testing.T) {
expected := len(test.k8sBackups) - len(test.expectedDeletes)
assert.Equal(t, expected, numBackups)
arktest.CompareActions(t, expectedDeleteActions, getDeleteActions(client.Actions()))
velerotest.CompareActions(t, expectedDeleteActions, getDeleteActions(client.Actions()))
})
}
}
@@ -421,7 +421,7 @@ func TestShouldSync(t *testing.T) {
tests := []struct {
name string
location *arkv1api.BackupStorageLocation
location *velerov1api.BackupStorageLocation
backupStoreRevision string
now time.Time
expectSync bool
@@ -429,7 +429,7 @@ func TestShouldSync(t *testing.T) {
}{
{
name: "BSL with no last-synced metadata should sync",
location: &arkv1api.BackupStorageLocation{},
location: &velerov1api.BackupStorageLocation{},
backupStoreRevision: "foo",
now: c.Now(),
expectSync: true,
@@ -437,8 +437,8 @@ func TestShouldSync(t *testing.T) {
},
{
name: "BSL with unchanged revision last synced more than an hour ago should sync",
location: &arkv1api.BackupStorageLocation{
Status: arkv1api.BackupStorageLocationStatus{
location: &velerov1api.BackupStorageLocation{
Status: velerov1api.BackupStorageLocationStatus{
LastSyncedRevision: types.UID("foo"),
LastSyncedTime: metav1.Time{Time: c.Now().Add(-61 * time.Minute)},
},
@@ -450,8 +450,8 @@ func TestShouldSync(t *testing.T) {
},
{
name: "BSL with unchanged revision last synced less than an hour ago should not sync",
location: &arkv1api.BackupStorageLocation{
Status: arkv1api.BackupStorageLocationStatus{
location: &velerov1api.BackupStorageLocation{
Status: velerov1api.BackupStorageLocationStatus{
LastSyncedRevision: types.UID("foo"),
LastSyncedTime: metav1.Time{Time: c.Now().Add(-59 * time.Minute)},
},
@@ -462,8 +462,8 @@ func TestShouldSync(t *testing.T) {
},
{
name: "BSL with different revision than backup store last synced less than an hour ago should sync",
location: &arkv1api.BackupStorageLocation{
Status: arkv1api.BackupStorageLocationStatus{
location: &velerov1api.BackupStorageLocation{
Status: velerov1api.BackupStorageLocationStatus{
LastSyncedRevision: types.UID("foo"),
LastSyncedTime: metav1.Time{Time: c.Now().Add(-time.Minute)},
},
@@ -475,8 +475,8 @@ func TestShouldSync(t *testing.T) {
},
{
name: "BSL with different revision than backup store last synced more than an hour ago should sync",
location: &arkv1api.BackupStorageLocation{
Status: arkv1api.BackupStorageLocationStatus{
location: &velerov1api.BackupStorageLocation{
Status: velerov1api.BackupStorageLocationStatus{
LastSyncedRevision: types.UID("foo"),
LastSyncedTime: metav1.Time{Time: c.Now().Add(-61 * time.Minute)},
},
@@ -497,7 +497,7 @@ func TestShouldSync(t *testing.T) {
backupStore.On("GetRevision").Return("", errors.New("object revision not found"))
}
shouldSync, rev := shouldSync(test.location, test.now, backupStore, arktest.NewLogger())
shouldSync, rev := shouldSync(test.location, test.now, backupStore, velerotest.NewLogger())
assert.Equal(t, test.expectSync, shouldSync)
assert.Equal(t, test.expectedRevision, rev)
})
@@ -517,7 +517,7 @@ func getDeleteActions(actions []core.Action) []core.Action {
func numBackups(t *testing.T, c *fake.Clientset, ns string) (int, error) {
t.Helper()
existingK8SBackups, err := c.ArkV1().Backups(ns).List(metav1.ListOptions{})
existingK8SBackups, err := c.VeleroV1().Backups(ns).List(metav1.ListOptions{})
if err != nil {
return 0, err
}

View File

@@ -30,19 +30,19 @@ import (
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/client-go/tools/cache"
"github.com/heptio/ark/pkg/apis/ark/v1"
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/persistence"
"github.com/heptio/ark/pkg/plugin"
"github.com/heptio/ark/pkg/util/kube"
v1 "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/persistence"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/util/kube"
)
type downloadRequestController struct {
*genericController
downloadRequestClient arkv1client.DownloadRequestsGetter
downloadRequestClient velerov1client.DownloadRequestsGetter
downloadRequestLister listers.DownloadRequestLister
restoreLister listers.RestoreLister
clock clock.Clock
@@ -54,7 +54,7 @@ type downloadRequestController struct {
// NewDownloadRequestController creates a new DownloadRequestController.
func NewDownloadRequestController(
downloadRequestClient arkv1client.DownloadRequestsGetter,
downloadRequestClient velerov1client.DownloadRequestsGetter,
downloadRequestInformer informers.DownloadRequestInformer,
restoreInformer informers.RestoreInformer,
backupLocationInformer informers.BackupStorageLocationInformer,
@@ -223,7 +223,7 @@ func (c *downloadRequestController) resync() {
}
}
func patchDownloadRequest(original, updated *v1.DownloadRequest, client arkv1client.DownloadRequestsGetter) (*v1.DownloadRequest, error) {
func patchDownloadRequest(original, updated *v1.DownloadRequest, client velerov1client.DownloadRequestsGetter) (*v1.DownloadRequest, error) {
origBytes, err := json.Marshal(original)
if err != nil {
return nil, errors.Wrap(err, "error marshalling original download request")

View File

@@ -27,15 +27,15 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/clock"
"github.com/heptio/ark/pkg/apis/ark/v1"
"github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions"
"github.com/heptio/ark/pkg/persistence"
persistencemocks "github.com/heptio/ark/pkg/persistence/mocks"
"github.com/heptio/ark/pkg/plugin"
pluginmocks "github.com/heptio/ark/pkg/plugin/mocks"
kubeutil "github.com/heptio/ark/pkg/util/kube"
arktest "github.com/heptio/ark/pkg/util/test"
v1 "github.com/heptio/velero/pkg/apis/velero/v1"
"github.com/heptio/velero/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions"
"github.com/heptio/velero/pkg/persistence"
persistencemocks "github.com/heptio/velero/pkg/persistence/mocks"
"github.com/heptio/velero/pkg/plugin"
pluginmocks "github.com/heptio/velero/pkg/plugin/mocks"
kubeutil "github.com/heptio/velero/pkg/util/kube"
velerotest "github.com/heptio/velero/pkg/util/test"
)
type downloadRequestTestHarness struct {
@@ -54,13 +54,13 @@ func newDownloadRequestTestHarness(t *testing.T) *downloadRequestTestHarness {
pluginManager = new(pluginmocks.Manager)
backupStore = new(persistencemocks.BackupStore)
controller = NewDownloadRequestController(
client.ArkV1(),
informerFactory.Ark().V1().DownloadRequests(),
informerFactory.Ark().V1().Restores(),
informerFactory.Ark().V1().BackupStorageLocations(),
informerFactory.Ark().V1().Backups(),
client.VeleroV1(),
informerFactory.Velero().V1().DownloadRequests(),
informerFactory.Velero().V1().Restores(),
informerFactory.Velero().V1().BackupStorageLocations(),
informerFactory.Velero().V1().Backups(),
func(logrus.FieldLogger) plugin.Manager { return pluginManager },
arktest.NewLogger(),
velerotest.NewLogger(),
).(*downloadRequestController)
)
@@ -145,94 +145,94 @@ func TestProcessDownloadRequest(t *testing.T) {
{
name: "backup contents request for nonexistent backup returns an error",
downloadRequest: newDownloadRequest("", v1.DownloadTargetKindBackupContents, "a-backup"),
backup: arktest.NewTestBackup().WithName("non-matching-backup").WithStorageLocation("a-location").Backup,
backup: velerotest.NewTestBackup().WithName("non-matching-backup").WithStorageLocation("a-location").Backup,
backupLocation: newBackupLocation("a-location", "a-provider", "a-bucket"),
expectedErr: "backup.ark.heptio.com \"a-backup\" not found",
expectedErr: "backup.velero.io \"a-backup\" not found",
},
{
name: "restore log request for nonexistent restore returns an error",
downloadRequest: newDownloadRequest("", v1.DownloadTargetKindRestoreLog, "a-backup-20170912150214"),
restore: arktest.NewTestRestore(v1.DefaultNamespace, "non-matching-restore", v1.RestorePhaseCompleted).WithBackup("a-backup").Restore,
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
restore: velerotest.NewTestRestore(v1.DefaultNamespace, "non-matching-restore", v1.RestorePhaseCompleted).WithBackup("a-backup").Restore,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backupLocation: newBackupLocation("a-location", "a-provider", "a-bucket"),
expectedErr: "error getting Restore: restore.ark.heptio.com \"a-backup-20170912150214\" not found",
expectedErr: "error getting Restore: restore.velero.io \"a-backup-20170912150214\" not found",
},
{
name: "backup contents request for backup with nonexistent location returns an error",
downloadRequest: newDownloadRequest("", v1.DownloadTargetKindBackupContents, "a-backup"),
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backupLocation: newBackupLocation("non-matching-location", "a-provider", "a-bucket"),
expectedErr: "backupstoragelocation.ark.heptio.com \"a-location\" not found",
expectedErr: "backupstoragelocation.velero.io \"a-location\" not found",
},
{
name: "backup contents request with phase '' gets a url",
downloadRequest: newDownloadRequest("", v1.DownloadTargetKindBackupContents, "a-backup"),
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backupLocation: newBackupLocation("a-location", "a-provider", "a-bucket"),
expectGetsURL: true,
},
{
name: "backup contents request with phase 'New' gets a url",
downloadRequest: newDownloadRequest(v1.DownloadRequestPhaseNew, v1.DownloadTargetKindBackupContents, "a-backup"),
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backupLocation: newBackupLocation("a-location", "a-provider", "a-bucket"),
expectGetsURL: true,
},
{
name: "backup log request with phase '' gets a url",
downloadRequest: newDownloadRequest("", v1.DownloadTargetKindBackupLog, "a-backup"),
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backupLocation: newBackupLocation("a-location", "a-provider", "a-bucket"),
expectGetsURL: true,
},
{
name: "backup log request with phase 'New' gets a url",
downloadRequest: newDownloadRequest(v1.DownloadRequestPhaseNew, v1.DownloadTargetKindBackupLog, "a-backup"),
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backupLocation: newBackupLocation("a-location", "a-provider", "a-bucket"),
expectGetsURL: true,
},
{
name: "restore log request with phase '' gets a url",
downloadRequest: newDownloadRequest("", v1.DownloadTargetKindRestoreLog, "a-backup-20170912150214"),
restore: arktest.NewTestRestore(v1.DefaultNamespace, "a-backup-20170912150214", v1.RestorePhaseCompleted).WithBackup("a-backup").Restore,
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
restore: velerotest.NewTestRestore(v1.DefaultNamespace, "a-backup-20170912150214", v1.RestorePhaseCompleted).WithBackup("a-backup").Restore,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backupLocation: newBackupLocation("a-location", "a-provider", "a-bucket"),
expectGetsURL: true,
},
{
name: "restore log request with phase 'New' gets a url",
downloadRequest: newDownloadRequest(v1.DownloadRequestPhaseNew, v1.DownloadTargetKindRestoreLog, "a-backup-20170912150214"),
restore: arktest.NewTestRestore(v1.DefaultNamespace, "a-backup-20170912150214", v1.RestorePhaseCompleted).WithBackup("a-backup").Restore,
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
restore: velerotest.NewTestRestore(v1.DefaultNamespace, "a-backup-20170912150214", v1.RestorePhaseCompleted).WithBackup("a-backup").Restore,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backupLocation: newBackupLocation("a-location", "a-provider", "a-bucket"),
expectGetsURL: true,
},
{
name: "restore results request with phase '' gets a url",
downloadRequest: newDownloadRequest("", v1.DownloadTargetKindRestoreResults, "a-backup-20170912150214"),
restore: arktest.NewTestRestore(v1.DefaultNamespace, "a-backup-20170912150214", v1.RestorePhaseCompleted).WithBackup("a-backup").Restore,
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
restore: velerotest.NewTestRestore(v1.DefaultNamespace, "a-backup-20170912150214", v1.RestorePhaseCompleted).WithBackup("a-backup").Restore,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backupLocation: newBackupLocation("a-location", "a-provider", "a-bucket"),
expectGetsURL: true,
},
{
name: "restore results request with phase 'New' gets a url",
downloadRequest: newDownloadRequest(v1.DownloadRequestPhaseNew, v1.DownloadTargetKindRestoreResults, "a-backup-20170912150214"),
restore: arktest.NewTestRestore(v1.DefaultNamespace, "a-backup-20170912150214", v1.RestorePhaseCompleted).WithBackup("a-backup").Restore,
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
restore: velerotest.NewTestRestore(v1.DefaultNamespace, "a-backup-20170912150214", v1.RestorePhaseCompleted).WithBackup("a-backup").Restore,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backupLocation: newBackupLocation("a-location", "a-provider", "a-bucket"),
expectGetsURL: true,
},
{
name: "request with phase 'Processed' is not deleted if not expired",
downloadRequest: newDownloadRequest(v1.DownloadRequestPhaseProcessed, v1.DownloadTargetKindBackupLog, "a-backup-20170912150214"),
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
},
{
name: "request with phase 'Processed' is deleted if expired",
downloadRequest: newDownloadRequest(v1.DownloadRequestPhaseProcessed, v1.DownloadTargetKindBackupLog, "a-backup-20170912150214"),
backup: arktest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
backup: velerotest.NewTestBackup().WithName("a-backup").WithStorageLocation("a-location").Backup,
expired: true,
},
}
@@ -254,22 +254,22 @@ func TestProcessDownloadRequest(t *testing.T) {
}
if tc.downloadRequest != nil {
require.NoError(t, harness.informerFactory.Ark().V1().DownloadRequests().Informer().GetStore().Add(tc.downloadRequest))
require.NoError(t, harness.informerFactory.Velero().V1().DownloadRequests().Informer().GetStore().Add(tc.downloadRequest))
_, err := harness.client.ArkV1().DownloadRequests(tc.downloadRequest.Namespace).Create(tc.downloadRequest)
_, err := harness.client.VeleroV1().DownloadRequests(tc.downloadRequest.Namespace).Create(tc.downloadRequest)
require.NoError(t, err)
}
if tc.restore != nil {
require.NoError(t, harness.informerFactory.Ark().V1().Restores().Informer().GetStore().Add(tc.restore))
require.NoError(t, harness.informerFactory.Velero().V1().Restores().Informer().GetStore().Add(tc.restore))
}
if tc.backup != nil {
require.NoError(t, harness.informerFactory.Ark().V1().Backups().Informer().GetStore().Add(tc.backup))
require.NoError(t, harness.informerFactory.Velero().V1().Backups().Informer().GetStore().Add(tc.backup))
}
if tc.backupLocation != nil {
require.NoError(t, harness.informerFactory.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(tc.backupLocation))
require.NoError(t, harness.informerFactory.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(tc.backupLocation))
}
if tc.expectGetsURL {
@@ -292,16 +292,16 @@ func TestProcessDownloadRequest(t *testing.T) {
}
if tc.expectGetsURL {
output, err := harness.client.ArkV1().DownloadRequests(tc.downloadRequest.Namespace).Get(tc.downloadRequest.Name, metav1.GetOptions{})
output, err := harness.client.VeleroV1().DownloadRequests(tc.downloadRequest.Namespace).Get(tc.downloadRequest.Name, metav1.GetOptions{})
require.NoError(t, err)
assert.Equal(t, string(v1.DownloadRequestPhaseProcessed), string(output.Status.Phase))
assert.Equal(t, "a-url", output.Status.DownloadURL)
assert.True(t, arktest.TimesAreEqual(harness.controller.clock.Now().Add(signedURLTTL), output.Status.Expiration.Time), "expiration does not match")
assert.True(t, velerotest.TimesAreEqual(harness.controller.clock.Now().Add(signedURLTTL), output.Status.Expiration.Time), "expiration does not match")
}
if tc.downloadRequest != nil && tc.downloadRequest.Status.Phase == v1.DownloadRequestPhaseProcessed {
res, err := harness.client.ArkV1().DownloadRequests(tc.downloadRequest.Namespace).Get(tc.downloadRequest.Name, metav1.GetOptions{})
res, err := harness.client.VeleroV1().DownloadRequests(tc.downloadRequest.Namespace).Get(tc.downloadRequest.Name, metav1.GetOptions{})
if tc.expired {
assert.True(t, apierrors.IsNotFound(err))

View File

@@ -26,11 +26,11 @@ import (
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/client-go/tools/cache"
arkv1api "github.com/heptio/ark/pkg/apis/ark/v1"
pkgbackup "github.com/heptio/ark/pkg/backup"
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
pkgbackup "github.com/heptio/velero/pkg/backup"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
)
const (
@@ -43,7 +43,7 @@ type gcController struct {
backupLister listers.BackupLister
deleteBackupRequestLister listers.DeleteBackupRequestLister
deleteBackupRequestClient arkv1client.DeleteBackupRequestsGetter
deleteBackupRequestClient velerov1client.DeleteBackupRequestsGetter
clock clock.Clock
}
@@ -53,7 +53,7 @@ func NewGCController(
logger logrus.FieldLogger,
backupInformer informers.BackupInformer,
deleteBackupRequestInformer informers.DeleteBackupRequestInformer,
deleteBackupRequestClient arkv1client.DeleteBackupRequestsGetter,
deleteBackupRequestClient velerov1client.DeleteBackupRequestsGetter,
) Interface {
c := &gcController{
genericController: newGenericController("gc-controller", logger),
@@ -133,8 +133,8 @@ func (c *gcController) processQueueItem(key string) error {
log.Info("Backup has expired")
selector := labels.SelectorFromSet(labels.Set(map[string]string{
arkv1api.BackupNameLabel: backup.Name,
arkv1api.BackupUIDLabel: string(backup.UID),
velerov1api.BackupNameLabel: backup.Name,
velerov1api.BackupUIDLabel: string(backup.UID),
}))
dbrs, err := c.deleteBackupRequestLister.DeleteBackupRequests(ns).List(selector)
@@ -146,7 +146,7 @@ func (c *gcController) processQueueItem(key string) error {
// another one
for _, dbr := range dbrs {
switch dbr.Status.Phase {
case "", arkv1api.DeleteBackupRequestPhaseNew, arkv1api.DeleteBackupRequestPhaseInProgress:
case "", velerov1api.DeleteBackupRequestPhaseNew, velerov1api.DeleteBackupRequestPhaseInProgress:
log.Info("Backup already has a pending deletion request")
return nil
}

View File

@@ -32,11 +32,11 @@ import (
"k8s.io/apimachinery/pkg/watch"
core "k8s.io/client-go/testing"
api "github.com/heptio/ark/pkg/apis/ark/v1"
"github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions"
"github.com/heptio/ark/pkg/util/kube"
arktest "github.com/heptio/ark/pkg/util/test"
api "github.com/heptio/velero/pkg/apis/velero/v1"
"github.com/heptio/velero/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions"
"github.com/heptio/velero/pkg/util/kube"
velerotest "github.com/heptio/velero/pkg/util/test"
)
func TestGCControllerEnqueueAllBackups(t *testing.T) {
@@ -45,10 +45,10 @@ func TestGCControllerEnqueueAllBackups(t *testing.T) {
sharedInformers = informers.NewSharedInformerFactory(client, 0)
controller = NewGCController(
arktest.NewLogger(),
sharedInformers.Ark().V1().Backups(),
sharedInformers.Ark().V1().DeleteBackupRequests(),
client.ArkV1(),
velerotest.NewLogger(),
sharedInformers.Velero().V1().Backups(),
sharedInformers.Velero().V1().DeleteBackupRequests(),
client.VeleroV1(),
).(*gcController)
)
@@ -65,8 +65,8 @@ func TestGCControllerEnqueueAllBackups(t *testing.T) {
var expected []string
for i := 0; i < 3; i++ {
backup := arktest.NewTestBackup().WithName(fmt.Sprintf("backup-%d", i)).Backup
sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(backup)
backup := velerotest.NewTestBackup().WithName(fmt.Sprintf("backup-%d", i)).Backup
sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(backup)
expected = append(expected, kube.NamespaceAndName(backup))
}
@@ -96,7 +96,7 @@ Loop:
}
func TestGCControllerHasUpdateFunc(t *testing.T) {
backup := arktest.NewTestBackup().WithName("backup").Backup
backup := velerotest.NewTestBackup().WithName("backup").Backup
expected := kube.NamespaceAndName(backup)
client := fake.NewSimpleClientset(backup)
@@ -108,10 +108,10 @@ func TestGCControllerHasUpdateFunc(t *testing.T) {
sharedInformers := informers.NewSharedInformerFactory(client, 0)
controller := NewGCController(
arktest.NewLogger(),
sharedInformers.Ark().V1().Backups(),
sharedInformers.Ark().V1().DeleteBackupRequests(),
client.ArkV1(),
velerotest.NewLogger(),
sharedInformers.Velero().V1().Backups(),
sharedInformers.Velero().V1().DeleteBackupRequests(),
client.VeleroV1(),
).(*gcController)
keys := make(chan string)
@@ -163,21 +163,21 @@ func TestGCControllerProcessQueueItem(t *testing.T) {
},
{
name: "unexpired backup is not deleted",
backup: arktest.NewTestBackup().WithName("backup-1").
backup: velerotest.NewTestBackup().WithName("backup-1").
WithExpiration(fakeClock.Now().Add(1 * time.Minute)).
Backup,
expectDeletion: false,
},
{
name: "expired backup with no pending deletion requests is deleted",
backup: arktest.NewTestBackup().WithName("backup-1").
backup: velerotest.NewTestBackup().WithName("backup-1").
WithExpiration(fakeClock.Now().Add(-1 * time.Second)).
Backup,
expectDeletion: true,
},
{
name: "expired backup with a pending deletion request is not deleted",
backup: arktest.NewTestBackup().WithName("backup-1").
backup: velerotest.NewTestBackup().WithName("backup-1").
WithExpiration(fakeClock.Now().Add(-1 * time.Second)).
Backup,
deleteBackupRequests: []*api.DeleteBackupRequest{
@@ -199,7 +199,7 @@ func TestGCControllerProcessQueueItem(t *testing.T) {
},
{
name: "expired backup with only processed deletion requests is deleted",
backup: arktest.NewTestBackup().WithName("backup-1").
backup: velerotest.NewTestBackup().WithName("backup-1").
WithExpiration(fakeClock.Now().Add(-1 * time.Second)).
Backup,
deleteBackupRequests: []*api.DeleteBackupRequest{
@@ -221,7 +221,7 @@ func TestGCControllerProcessQueueItem(t *testing.T) {
},
{
name: "create DeleteBackupRequest error returns an error",
backup: arktest.NewTestBackup().WithName("backup-1").
backup: velerotest.NewTestBackup().WithName("backup-1").
WithExpiration(fakeClock.Now().Add(-1 * time.Second)).
Backup,
expectDeletion: true,
@@ -238,21 +238,21 @@ func TestGCControllerProcessQueueItem(t *testing.T) {
)
controller := NewGCController(
arktest.NewLogger(),
sharedInformers.Ark().V1().Backups(),
sharedInformers.Ark().V1().DeleteBackupRequests(),
client.ArkV1(),
velerotest.NewLogger(),
sharedInformers.Velero().V1().Backups(),
sharedInformers.Velero().V1().DeleteBackupRequests(),
client.VeleroV1(),
).(*gcController)
controller.clock = fakeClock
var key string
if test.backup != nil {
key = kube.NamespaceAndName(test.backup)
sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(test.backup)
sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(test.backup)
}
for _, dbr := range test.deleteBackupRequests {
sharedInformers.Ark().V1().DeleteBackupRequests().Informer().GetStore().Add(dbr)
sharedInformers.Velero().V1().DeleteBackupRequests().Informer().GetStore().Add(dbr)
}
if test.createDeleteBackupRequestError {

View File

@@ -32,20 +32,20 @@ import (
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache"
arkv1api "github.com/heptio/ark/pkg/apis/ark/v1"
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/restic"
arkexec "github.com/heptio/ark/pkg/util/exec"
"github.com/heptio/ark/pkg/util/filesystem"
"github.com/heptio/ark/pkg/util/kube"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/restic"
veleroexec "github.com/heptio/velero/pkg/util/exec"
"github.com/heptio/velero/pkg/util/filesystem"
"github.com/heptio/velero/pkg/util/kube"
)
type podVolumeBackupController struct {
*genericController
podVolumeBackupClient arkv1client.PodVolumeBackupsGetter
podVolumeBackupClient velerov1client.PodVolumeBackupsGetter
podVolumeBackupLister listers.PodVolumeBackupLister
secretLister corev1listers.SecretLister
podLister corev1listers.PodLister
@@ -53,7 +53,7 @@ type podVolumeBackupController struct {
backupLocationLister listers.BackupStorageLocationLister
nodeName string
processBackupFunc func(*arkv1api.PodVolumeBackup) error
processBackupFunc func(*velerov1api.PodVolumeBackup) error
fileSystem filesystem.Interface
}
@@ -61,7 +61,7 @@ type podVolumeBackupController struct {
func NewPodVolumeBackupController(
logger logrus.FieldLogger,
podVolumeBackupInformer informers.PodVolumeBackupInformer,
podVolumeBackupClient arkv1client.PodVolumeBackupsGetter,
podVolumeBackupClient velerov1client.PodVolumeBackupsGetter,
podInformer cache.SharedIndexInformer,
secretInformer cache.SharedIndexInformer,
pvcInformer corev1informers.PersistentVolumeClaimInformer,
@@ -103,7 +103,7 @@ func NewPodVolumeBackupController(
}
func (c *podVolumeBackupController) pvbHandler(obj interface{}) {
req := obj.(*arkv1api.PodVolumeBackup)
req := obj.(*velerov1api.PodVolumeBackup)
// only enqueue items for this node
if req.Spec.Node != c.nodeName {
@@ -112,7 +112,7 @@ func (c *podVolumeBackupController) pvbHandler(obj interface{}) {
log := loggerForPodVolumeBackup(c.logger, req)
if req.Status.Phase != "" && req.Status.Phase != arkv1api.PodVolumeBackupPhaseNew {
if req.Status.Phase != "" && req.Status.Phase != velerov1api.PodVolumeBackupPhaseNew {
log.Debug("Backup is not new, not enqueuing")
return
}
@@ -142,7 +142,7 @@ func (c *podVolumeBackupController) processQueueItem(key string) error {
// only process new items
switch req.Status.Phase {
case "", arkv1api.PodVolumeBackupPhaseNew:
case "", velerov1api.PodVolumeBackupPhaseNew:
default:
return nil
}
@@ -152,7 +152,7 @@ func (c *podVolumeBackupController) processQueueItem(key string) error {
return c.processBackupFunc(reqCopy)
}
func loggerForPodVolumeBackup(baseLogger logrus.FieldLogger, req *arkv1api.PodVolumeBackup) logrus.FieldLogger {
func loggerForPodVolumeBackup(baseLogger logrus.FieldLogger, req *velerov1api.PodVolumeBackup) logrus.FieldLogger {
log := baseLogger.WithFields(logrus.Fields{
"namespace": req.Namespace,
"name": req.Name,
@@ -165,7 +165,7 @@ func loggerForPodVolumeBackup(baseLogger logrus.FieldLogger, req *arkv1api.PodVo
return log
}
func (c *podVolumeBackupController) processBackup(req *arkv1api.PodVolumeBackup) error {
func (c *podVolumeBackupController) processBackup(req *velerov1api.PodVolumeBackup) error {
log := loggerForPodVolumeBackup(c.logger, req)
log.Info("Backup starting")
@@ -173,7 +173,7 @@ func (c *podVolumeBackupController) processBackup(req *arkv1api.PodVolumeBackup)
var err error
// update status to InProgress
req, err = c.patchPodVolumeBackup(req, updatePhaseFunc(arkv1api.PodVolumeBackupPhaseInProgress))
req, err = c.patchPodVolumeBackup(req, updatePhaseFunc(velerov1api.PodVolumeBackupPhaseInProgress))
if err != nil {
log.WithError(err).Error("Error setting phase to InProgress")
return errors.WithStack(err)
@@ -228,7 +228,7 @@ func (c *podVolumeBackupController) processBackup(req *arkv1api.PodVolumeBackup)
var stdout, stderr string
if stdout, stderr, err = arkexec.RunCommand(resticCmd.Cmd()); err != nil {
if stdout, stderr, err = veleroexec.RunCommand(resticCmd.Cmd()); err != nil {
log.WithError(errors.WithStack(err)).Errorf("Error running command=%s, stdout=%s, stderr=%s", resticCmd.String(), stdout, stderr)
return c.fail(req, fmt.Sprintf("error running restic backup, stderr=%s: %s", stderr, err.Error()), log)
}
@@ -241,10 +241,10 @@ func (c *podVolumeBackupController) processBackup(req *arkv1api.PodVolumeBackup)
}
// update status to Completed with path & snapshot id
req, err = c.patchPodVolumeBackup(req, func(r *arkv1api.PodVolumeBackup) {
req, err = c.patchPodVolumeBackup(req, func(r *velerov1api.PodVolumeBackup) {
r.Status.Path = path
r.Status.SnapshotID = snapshotID
r.Status.Phase = arkv1api.PodVolumeBackupPhaseCompleted
r.Status.Phase = velerov1api.PodVolumeBackupPhaseCompleted
})
if err != nil {
log.WithError(err).Error("Error setting phase to Completed")
@@ -256,7 +256,7 @@ func (c *podVolumeBackupController) processBackup(req *arkv1api.PodVolumeBackup)
return nil
}
func (c *podVolumeBackupController) patchPodVolumeBackup(req *arkv1api.PodVolumeBackup, mutate func(*arkv1api.PodVolumeBackup)) (*arkv1api.PodVolumeBackup, error) {
func (c *podVolumeBackupController) patchPodVolumeBackup(req *velerov1api.PodVolumeBackup, mutate func(*velerov1api.PodVolumeBackup)) (*velerov1api.PodVolumeBackup, error) {
// Record original json
oldData, err := json.Marshal(req)
if err != nil {
@@ -285,9 +285,9 @@ func (c *podVolumeBackupController) patchPodVolumeBackup(req *arkv1api.PodVolume
return req, nil
}
func (c *podVolumeBackupController) fail(req *arkv1api.PodVolumeBackup, msg string, log logrus.FieldLogger) error {
if _, err := c.patchPodVolumeBackup(req, func(r *arkv1api.PodVolumeBackup) {
r.Status.Phase = arkv1api.PodVolumeBackupPhaseFailed
func (c *podVolumeBackupController) fail(req *velerov1api.PodVolumeBackup, msg string, log logrus.FieldLogger) error {
if _, err := c.patchPodVolumeBackup(req, func(r *velerov1api.PodVolumeBackup) {
r.Status.Phase = velerov1api.PodVolumeBackupPhaseFailed
r.Status.Message = msg
}); err != nil {
log.WithError(err).Error("Error setting phase to Failed")
@@ -296,8 +296,8 @@ func (c *podVolumeBackupController) fail(req *arkv1api.PodVolumeBackup, msg stri
return nil
}
func updatePhaseFunc(phase arkv1api.PodVolumeBackupPhase) func(r *arkv1api.PodVolumeBackup) {
return func(r *arkv1api.PodVolumeBackup) {
func updatePhaseFunc(phase velerov1api.PodVolumeBackupPhase) func(r *velerov1api.PodVolumeBackup) {
return func(r *velerov1api.PodVolumeBackup) {
r.Status.Phase = phase
}
}

View File

@@ -22,8 +22,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
arkv1api "github.com/heptio/ark/pkg/apis/ark/v1"
arktest "github.com/heptio/ark/pkg/util/test"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
velerotest "github.com/heptio/velero/pkg/util/test"
)
func TestPVBHandler(t *testing.T) {
@@ -31,13 +31,13 @@ func TestPVBHandler(t *testing.T) {
tests := []struct {
name string
obj *arkv1api.PodVolumeBackup
obj *velerov1api.PodVolumeBackup
shouldEnqueue bool
}{
{
name: "Empty phase pvb on same node should be enqueued",
obj: &arkv1api.PodVolumeBackup{
Spec: arkv1api.PodVolumeBackupSpec{
obj: &velerov1api.PodVolumeBackup{
Spec: velerov1api.PodVolumeBackupSpec{
Node: controllerNode,
},
},
@@ -45,48 +45,48 @@ func TestPVBHandler(t *testing.T) {
},
{
name: "New phase pvb on same node should be enqueued",
obj: &arkv1api.PodVolumeBackup{
Spec: arkv1api.PodVolumeBackupSpec{
obj: &velerov1api.PodVolumeBackup{
Spec: velerov1api.PodVolumeBackupSpec{
Node: controllerNode,
},
Status: arkv1api.PodVolumeBackupStatus{
Phase: arkv1api.PodVolumeBackupPhaseNew,
Status: velerov1api.PodVolumeBackupStatus{
Phase: velerov1api.PodVolumeBackupPhaseNew,
},
},
shouldEnqueue: true,
},
{
name: "InProgress phase pvb on same node should not be enqueued",
obj: &arkv1api.PodVolumeBackup{
Spec: arkv1api.PodVolumeBackupSpec{
obj: &velerov1api.PodVolumeBackup{
Spec: velerov1api.PodVolumeBackupSpec{
Node: controllerNode,
},
Status: arkv1api.PodVolumeBackupStatus{
Phase: arkv1api.PodVolumeBackupPhaseInProgress,
Status: velerov1api.PodVolumeBackupStatus{
Phase: velerov1api.PodVolumeBackupPhaseInProgress,
},
},
shouldEnqueue: false,
},
{
name: "Completed phase pvb on same node should not be enqueued",
obj: &arkv1api.PodVolumeBackup{
Spec: arkv1api.PodVolumeBackupSpec{
obj: &velerov1api.PodVolumeBackup{
Spec: velerov1api.PodVolumeBackupSpec{
Node: controllerNode,
},
Status: arkv1api.PodVolumeBackupStatus{
Phase: arkv1api.PodVolumeBackupPhaseCompleted,
Status: velerov1api.PodVolumeBackupStatus{
Phase: velerov1api.PodVolumeBackupPhaseCompleted,
},
},
shouldEnqueue: false,
},
{
name: "Failed phase pvb on same node should not be enqueued",
obj: &arkv1api.PodVolumeBackup{
Spec: arkv1api.PodVolumeBackupSpec{
obj: &velerov1api.PodVolumeBackup{
Spec: velerov1api.PodVolumeBackupSpec{
Node: controllerNode,
},
Status: arkv1api.PodVolumeBackupStatus{
Phase: arkv1api.PodVolumeBackupPhaseFailed,
Status: velerov1api.PodVolumeBackupStatus{
Phase: velerov1api.PodVolumeBackupPhaseFailed,
},
},
shouldEnqueue: false,
@@ -94,8 +94,8 @@ func TestPVBHandler(t *testing.T) {
{
name: "Empty phase pvb on different node should not be enqueued",
obj: &arkv1api.PodVolumeBackup{
Spec: arkv1api.PodVolumeBackupSpec{
obj: &velerov1api.PodVolumeBackup{
Spec: velerov1api.PodVolumeBackupSpec{
Node: "some-other-node",
},
},
@@ -103,48 +103,48 @@ func TestPVBHandler(t *testing.T) {
},
{
name: "New phase pvb on different node should not be enqueued",
obj: &arkv1api.PodVolumeBackup{
Spec: arkv1api.PodVolumeBackupSpec{
obj: &velerov1api.PodVolumeBackup{
Spec: velerov1api.PodVolumeBackupSpec{
Node: "some-other-node",
},
Status: arkv1api.PodVolumeBackupStatus{
Phase: arkv1api.PodVolumeBackupPhaseNew,
Status: velerov1api.PodVolumeBackupStatus{
Phase: velerov1api.PodVolumeBackupPhaseNew,
},
},
shouldEnqueue: false,
},
{
name: "InProgress phase pvb on different node should not be enqueued",
obj: &arkv1api.PodVolumeBackup{
Spec: arkv1api.PodVolumeBackupSpec{
obj: &velerov1api.PodVolumeBackup{
Spec: velerov1api.PodVolumeBackupSpec{
Node: "some-other-node",
},
Status: arkv1api.PodVolumeBackupStatus{
Phase: arkv1api.PodVolumeBackupPhaseInProgress,
Status: velerov1api.PodVolumeBackupStatus{
Phase: velerov1api.PodVolumeBackupPhaseInProgress,
},
},
shouldEnqueue: false,
},
{
name: "Completed phase pvb on different node should not be enqueued",
obj: &arkv1api.PodVolumeBackup{
Spec: arkv1api.PodVolumeBackupSpec{
obj: &velerov1api.PodVolumeBackup{
Spec: velerov1api.PodVolumeBackupSpec{
Node: "some-other-node",
},
Status: arkv1api.PodVolumeBackupStatus{
Phase: arkv1api.PodVolumeBackupPhaseCompleted,
Status: velerov1api.PodVolumeBackupStatus{
Phase: velerov1api.PodVolumeBackupPhaseCompleted,
},
},
shouldEnqueue: false,
},
{
name: "Failed phase pvb on different node should not be enqueued",
obj: &arkv1api.PodVolumeBackup{
Spec: arkv1api.PodVolumeBackupSpec{
obj: &velerov1api.PodVolumeBackup{
Spec: velerov1api.PodVolumeBackupSpec{
Node: "some-other-node",
},
Status: arkv1api.PodVolumeBackupStatus{
Phase: arkv1api.PodVolumeBackupPhaseFailed,
Status: velerov1api.PodVolumeBackupStatus{
Phase: velerov1api.PodVolumeBackupPhaseFailed,
},
},
shouldEnqueue: false,
@@ -154,7 +154,7 @@ func TestPVBHandler(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
c := &podVolumeBackupController{
genericController: newGenericController("pod-volume-backup", arktest.NewLogger()),
genericController: newGenericController("pod-volume-backup", velerotest.NewLogger()),
nodeName: controllerNode,
}

View File

@@ -35,21 +35,21 @@ import (
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache"
arkv1api "github.com/heptio/ark/pkg/apis/ark/v1"
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/restic"
"github.com/heptio/ark/pkg/util/boolptr"
arkexec "github.com/heptio/ark/pkg/util/exec"
"github.com/heptio/ark/pkg/util/filesystem"
"github.com/heptio/ark/pkg/util/kube"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/restic"
"github.com/heptio/velero/pkg/util/boolptr"
veleroexec "github.com/heptio/velero/pkg/util/exec"
"github.com/heptio/velero/pkg/util/filesystem"
"github.com/heptio/velero/pkg/util/kube"
)
type podVolumeRestoreController struct {
*genericController
podVolumeRestoreClient arkv1client.PodVolumeRestoresGetter
podVolumeRestoreClient velerov1client.PodVolumeRestoresGetter
podVolumeRestoreLister listers.PodVolumeRestoreLister
podLister corev1listers.PodLister
secretLister corev1listers.SecretLister
@@ -57,7 +57,7 @@ type podVolumeRestoreController struct {
backupLocationLister listers.BackupStorageLocationLister
nodeName string
processRestoreFunc func(*arkv1api.PodVolumeRestore) error
processRestoreFunc func(*velerov1api.PodVolumeRestore) error
fileSystem filesystem.Interface
}
@@ -65,7 +65,7 @@ type podVolumeRestoreController struct {
func NewPodVolumeRestoreController(
logger logrus.FieldLogger,
podVolumeRestoreInformer informers.PodVolumeRestoreInformer,
podVolumeRestoreClient arkv1client.PodVolumeRestoresGetter,
podVolumeRestoreClient velerov1client.PodVolumeRestoresGetter,
podInformer cache.SharedIndexInformer,
secretInformer cache.SharedIndexInformer,
pvcInformer corev1informers.PersistentVolumeClaimInformer,
@@ -118,7 +118,7 @@ func NewPodVolumeRestoreController(
}
func (c *podVolumeRestoreController) pvrHandler(obj interface{}) {
pvr := obj.(*arkv1api.PodVolumeRestore)
pvr := obj.(*velerov1api.PodVolumeRestore)
log := loggerForPodVolumeRestore(c.logger, pvr)
if !isPVRNew(pvr) {
@@ -166,7 +166,7 @@ func (c *podVolumeRestoreController) podHandler(obj interface{}) {
}
selector := labels.Set(map[string]string{
arkv1api.PodUIDLabel: string(pod.UID),
velerov1api.PodUIDLabel: string(pod.UID),
}).AsSelector()
pvrs, err := c.podVolumeRestoreLister.List(selector)
@@ -190,8 +190,8 @@ func (c *podVolumeRestoreController) podHandler(obj interface{}) {
}
}
func isPVRNew(pvr *arkv1api.PodVolumeRestore) bool {
return pvr.Status.Phase == "" || pvr.Status.Phase == arkv1api.PodVolumeRestorePhaseNew
func isPVRNew(pvr *velerov1api.PodVolumeRestore) bool {
return pvr.Status.Phase == "" || pvr.Status.Phase == velerov1api.PodVolumeRestorePhaseNew
}
func isPodOnNode(pod *corev1api.Pod, node string) bool {
@@ -199,7 +199,7 @@ func isPodOnNode(pod *corev1api.Pod, node string) bool {
}
func isResticInitContainerRunning(pod *corev1api.Pod) bool {
// no init containers, or the first one is not the ark restic one: return false
// no init containers, or the first one is not the velero restic one: return false
if len(pod.Spec.InitContainers) == 0 || pod.Spec.InitContainers[0].Name != restic.InitContainer {
return false
}
@@ -237,7 +237,7 @@ func (c *podVolumeRestoreController) processQueueItem(key string) error {
return c.processRestoreFunc(reqCopy)
}
func loggerForPodVolumeRestore(baseLogger logrus.FieldLogger, req *arkv1api.PodVolumeRestore) logrus.FieldLogger {
func loggerForPodVolumeRestore(baseLogger logrus.FieldLogger, req *velerov1api.PodVolumeRestore) logrus.FieldLogger {
log := baseLogger.WithFields(logrus.Fields{
"namespace": req.Namespace,
"name": req.Name,
@@ -250,7 +250,7 @@ func loggerForPodVolumeRestore(baseLogger logrus.FieldLogger, req *arkv1api.PodV
return log
}
func (c *podVolumeRestoreController) processRestore(req *arkv1api.PodVolumeRestore) error {
func (c *podVolumeRestoreController) processRestore(req *velerov1api.PodVolumeRestore) error {
log := loggerForPodVolumeRestore(c.logger, req)
log.Info("Restore starting")
@@ -258,7 +258,7 @@ func (c *podVolumeRestoreController) processRestore(req *arkv1api.PodVolumeResto
var err error
// update status to InProgress
req, err = c.patchPodVolumeRestore(req, updatePodVolumeRestorePhaseFunc(arkv1api.PodVolumeRestorePhaseInProgress))
req, err = c.patchPodVolumeRestore(req, updatePodVolumeRestorePhaseFunc(velerov1api.PodVolumeRestorePhaseInProgress))
if err != nil {
log.WithError(err).Error("Error setting phase to InProgress")
return errors.WithStack(err)
@@ -291,7 +291,7 @@ func (c *podVolumeRestoreController) processRestore(req *arkv1api.PodVolumeResto
}
// update status to Completed
if _, err = c.patchPodVolumeRestore(req, updatePodVolumeRestorePhaseFunc(arkv1api.PodVolumeRestorePhaseCompleted)); err != nil {
if _, err = c.patchPodVolumeRestore(req, updatePodVolumeRestorePhaseFunc(velerov1api.PodVolumeRestorePhaseCompleted)); err != nil {
log.WithError(err).Error("Error setting phase to Completed")
return err
}
@@ -301,7 +301,7 @@ func (c *podVolumeRestoreController) processRestore(req *arkv1api.PodVolumeResto
return nil
}
func (c *podVolumeRestoreController) restorePodVolume(req *arkv1api.PodVolumeRestore, credsFile, volumeDir string, log logrus.FieldLogger) error {
func (c *podVolumeRestoreController) restorePodVolume(req *velerov1api.PodVolumeRestore, credsFile, volumeDir string, log logrus.FieldLogger) error {
// Get the full path of the new volume's directory as mounted in the daemonset pod, which
// will look like: /host_pods/<new-pod-uid>/volumes/<volume-plugin-name>/<volume-dir>
volumePath, err := singlePathMatch(fmt.Sprintf("/host_pods/%s/volumes/*/%s", string(req.Spec.Pod.UID), volumeDir))
@@ -327,17 +327,17 @@ func (c *podVolumeRestoreController) restorePodVolume(req *arkv1api.PodVolumeRes
var stdout, stderr string
if stdout, stderr, err = arkexec.RunCommand(resticCmd.Cmd()); err != nil {
if stdout, stderr, err = veleroexec.RunCommand(resticCmd.Cmd()); err != nil {
return errors.Wrapf(err, "error running restic restore, cmd=%s, stdout=%s, stderr=%s", resticCmd.String(), stdout, stderr)
}
log.Debugf("Ran command=%s, stdout=%s, stderr=%s", resticCmd.String(), stdout, stderr)
// Remove the .ark directory from the restored volume (it may contain done files from previous restores
// Remove the .velero directory from the restored volume (it may contain done files from previous restores
// of this volume, which we don't want to carry over). If this fails for any reason, log and continue, since
// this is non-essential cleanup (the done files are named based on restore UID and the init container looks
// for the one specific to the restore being executed).
if err := os.RemoveAll(filepath.Join(volumePath, ".ark")); err != nil {
log.WithError(err).Warnf("error removing .ark directory from directory %s", volumePath)
if err := os.RemoveAll(filepath.Join(volumePath, ".velero")); err != nil {
log.WithError(err).Warnf("error removing .velero directory from directory %s", volumePath)
}
var restoreUID types.UID
@@ -348,23 +348,23 @@ func (c *podVolumeRestoreController) restorePodVolume(req *arkv1api.PodVolumeRes
}
}
// Create the .ark directory within the volume dir so we can write a done file
// Create the .velero directory within the volume dir so we can write a done file
// for this restore.
if err := os.MkdirAll(filepath.Join(volumePath, ".ark"), 0755); err != nil {
return errors.Wrap(err, "error creating .ark directory for done file")
if err := os.MkdirAll(filepath.Join(volumePath, ".velero"), 0755); err != nil {
return errors.Wrap(err, "error creating .velero directory for done file")
}
// Write a done file with name=<restore-uid> into the just-created .ark dir
// within the volume. The ark restic init container on the pod is waiting
// Write a done file with name=<restore-uid> into the just-created .velero dir
// within the volume. The velero restic init container on the pod is waiting
// for this file to exist in each restored volume before completing.
if err := ioutil.WriteFile(filepath.Join(volumePath, ".ark", string(restoreUID)), nil, 0644); err != nil {
if err := ioutil.WriteFile(filepath.Join(volumePath, ".velero", string(restoreUID)), nil, 0644); err != nil {
return errors.Wrap(err, "error writing done file")
}
return nil
}
func (c *podVolumeRestoreController) patchPodVolumeRestore(req *arkv1api.PodVolumeRestore, mutate func(*arkv1api.PodVolumeRestore)) (*arkv1api.PodVolumeRestore, error) {
func (c *podVolumeRestoreController) patchPodVolumeRestore(req *velerov1api.PodVolumeRestore, mutate func(*velerov1api.PodVolumeRestore)) (*velerov1api.PodVolumeRestore, error) {
// Record original json
oldData, err := json.Marshal(req)
if err != nil {
@@ -393,9 +393,9 @@ func (c *podVolumeRestoreController) patchPodVolumeRestore(req *arkv1api.PodVolu
return req, nil
}
func (c *podVolumeRestoreController) failRestore(req *arkv1api.PodVolumeRestore, msg string, log logrus.FieldLogger) error {
if _, err := c.patchPodVolumeRestore(req, func(pvr *arkv1api.PodVolumeRestore) {
pvr.Status.Phase = arkv1api.PodVolumeRestorePhaseFailed
func (c *podVolumeRestoreController) failRestore(req *velerov1api.PodVolumeRestore, msg string, log logrus.FieldLogger) error {
if _, err := c.patchPodVolumeRestore(req, func(pvr *velerov1api.PodVolumeRestore) {
pvr.Status.Phase = velerov1api.PodVolumeRestorePhaseFailed
pvr.Status.Message = msg
}); err != nil {
log.WithError(err).Error("Error setting phase to Failed")
@@ -404,8 +404,8 @@ func (c *podVolumeRestoreController) failRestore(req *arkv1api.PodVolumeRestore,
return nil
}
func updatePodVolumeRestorePhaseFunc(phase arkv1api.PodVolumeRestorePhase) func(r *arkv1api.PodVolumeRestore) {
return func(r *arkv1api.PodVolumeRestore) {
func updatePodVolumeRestorePhaseFunc(phase velerov1api.PodVolumeRestorePhase) func(r *velerov1api.PodVolumeRestore) {
return func(r *velerov1api.PodVolumeRestore) {
r.Status.Phase = phase
}
}

View File

@@ -29,12 +29,12 @@ import (
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache"
arkv1api "github.com/heptio/ark/pkg/apis/ark/v1"
arkfake "github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
arkinformers "github.com/heptio/ark/pkg/generated/informers/externalversions"
arkv1listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/restic"
arktest "github.com/heptio/ark/pkg/util/test"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
velerofake "github.com/heptio/velero/pkg/generated/clientset/versioned/fake"
veleroinformers "github.com/heptio/velero/pkg/generated/informers/externalversions"
velerov1listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/restic"
velerotest "github.com/heptio/velero/pkg/util/test"
)
func TestPVRHandler(t *testing.T) {
@@ -42,47 +42,47 @@ func TestPVRHandler(t *testing.T) {
tests := []struct {
name string
obj *arkv1api.PodVolumeRestore
obj *velerov1api.PodVolumeRestore
pod *corev1api.Pod
shouldEnqueue bool
}{
{
name: "InProgress phase pvr should not be enqueued",
obj: &arkv1api.PodVolumeRestore{
Status: arkv1api.PodVolumeRestoreStatus{
Phase: arkv1api.PodVolumeRestorePhaseInProgress,
obj: &velerov1api.PodVolumeRestore{
Status: velerov1api.PodVolumeRestoreStatus{
Phase: velerov1api.PodVolumeRestorePhaseInProgress,
},
},
shouldEnqueue: false,
},
{
name: "Completed phase pvr should not be enqueued",
obj: &arkv1api.PodVolumeRestore{
Status: arkv1api.PodVolumeRestoreStatus{
Phase: arkv1api.PodVolumeRestorePhaseCompleted,
obj: &velerov1api.PodVolumeRestore{
Status: velerov1api.PodVolumeRestoreStatus{
Phase: velerov1api.PodVolumeRestorePhaseCompleted,
},
},
shouldEnqueue: false,
},
{
name: "Failed phase pvr should not be enqueued",
obj: &arkv1api.PodVolumeRestore{
Status: arkv1api.PodVolumeRestoreStatus{
Phase: arkv1api.PodVolumeRestorePhaseFailed,
obj: &velerov1api.PodVolumeRestore{
Status: velerov1api.PodVolumeRestoreStatus{
Phase: velerov1api.PodVolumeRestorePhaseFailed,
},
},
shouldEnqueue: false,
},
{
name: "Unable to get pvr's pod should not be enqueued",
obj: &arkv1api.PodVolumeRestore{
Spec: arkv1api.PodVolumeRestoreSpec{
obj: &velerov1api.PodVolumeRestore{
Spec: velerov1api.PodVolumeRestoreSpec{
Pod: corev1api.ObjectReference{
Namespace: "ns-1",
Name: "pod-1",
},
},
Status: arkv1api.PodVolumeRestoreStatus{
Status: velerov1api.PodVolumeRestoreStatus{
Phase: "",
},
},
@@ -90,14 +90,14 @@ func TestPVRHandler(t *testing.T) {
},
{
name: "Empty phase pvr with pod not on node running init container should not be enqueued",
obj: &arkv1api.PodVolumeRestore{
Spec: arkv1api.PodVolumeRestoreSpec{
obj: &velerov1api.PodVolumeRestore{
Spec: velerov1api.PodVolumeRestoreSpec{
Pod: corev1api.ObjectReference{
Namespace: "ns-1",
Name: "pod-1",
},
},
Status: arkv1api.PodVolumeRestoreStatus{
Status: velerov1api.PodVolumeRestoreStatus{
Phase: "",
},
},
@@ -130,14 +130,14 @@ func TestPVRHandler(t *testing.T) {
},
{
name: "Empty phase pvr with pod on node not running init container should not be enqueued",
obj: &arkv1api.PodVolumeRestore{
Spec: arkv1api.PodVolumeRestoreSpec{
obj: &velerov1api.PodVolumeRestore{
Spec: velerov1api.PodVolumeRestoreSpec{
Pod: corev1api.ObjectReference{
Namespace: "ns-1",
Name: "pod-1",
},
},
Status: arkv1api.PodVolumeRestoreStatus{
Status: velerov1api.PodVolumeRestoreStatus{
Phase: "",
},
},
@@ -166,14 +166,14 @@ func TestPVRHandler(t *testing.T) {
},
{
name: "Empty phase pvr with pod on node running init container should be enqueued",
obj: &arkv1api.PodVolumeRestore{
Spec: arkv1api.PodVolumeRestoreSpec{
obj: &velerov1api.PodVolumeRestore{
Spec: velerov1api.PodVolumeRestoreSpec{
Pod: corev1api.ObjectReference{
Namespace: "ns-1",
Name: "pod-1",
},
},
Status: arkv1api.PodVolumeRestoreStatus{
Status: velerov1api.PodVolumeRestoreStatus{
Phase: "",
},
},
@@ -211,7 +211,7 @@ func TestPVRHandler(t *testing.T) {
var (
podInformer = cache.NewSharedIndexInformer(nil, new(corev1api.Pod), 0, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
c = &podVolumeRestoreController{
genericController: newGenericController("pod-volume-restore", arktest.NewLogger()),
genericController: newGenericController("pod-volume-restore", velerotest.NewLogger()),
podLister: corev1listers.NewPodLister(podInformer.GetIndexer()),
nodeName: controllerNode,
}
@@ -239,7 +239,7 @@ func TestPodHandler(t *testing.T) {
tests := []struct {
name string
pod *corev1api.Pod
podVolumeRestores []*arkv1api.PodVolumeRestore
podVolumeRestores []*velerov1api.PodVolumeRestore
expectedEnqueues sets.String
}{
{
@@ -268,13 +268,13 @@ func TestPodHandler(t *testing.T) {
},
},
},
podVolumeRestores: []*arkv1api.PodVolumeRestore{
podVolumeRestores: []*velerov1api.PodVolumeRestore{
{
ObjectMeta: metav1.ObjectMeta{
Namespace: "ns-1",
Name: "pvr-1",
Labels: map[string]string{
arkv1api.PodUIDLabel: "uid",
velerov1api.PodUIDLabel: "uid",
},
},
},
@@ -283,7 +283,7 @@ func TestPodHandler(t *testing.T) {
Namespace: "ns-1",
Name: "pvr-2",
Labels: map[string]string{
arkv1api.PodUIDLabel: "uid",
velerov1api.PodUIDLabel: "uid",
},
},
},
@@ -292,11 +292,11 @@ func TestPodHandler(t *testing.T) {
Namespace: "ns-1",
Name: "pvr-3",
Labels: map[string]string{
arkv1api.PodUIDLabel: "uid",
velerov1api.PodUIDLabel: "uid",
},
},
Status: arkv1api.PodVolumeRestoreStatus{
Phase: arkv1api.PodVolumeRestorePhaseInProgress,
Status: velerov1api.PodVolumeRestoreStatus{
Phase: velerov1api.PodVolumeRestorePhaseInProgress,
},
},
{
@@ -304,7 +304,7 @@ func TestPodHandler(t *testing.T) {
Namespace: "ns-1",
Name: "pvr-4",
Labels: map[string]string{
arkv1api.PodUIDLabel: "some-other-pod",
velerov1api.PodUIDLabel: "some-other-pod",
},
},
},
@@ -335,13 +335,13 @@ func TestPodHandler(t *testing.T) {
},
},
},
podVolumeRestores: []*arkv1api.PodVolumeRestore{
podVolumeRestores: []*velerov1api.PodVolumeRestore{
{
ObjectMeta: metav1.ObjectMeta{
Namespace: "ns-1",
Name: "pvr-1",
Labels: map[string]string{
arkv1api.PodUIDLabel: "uid",
velerov1api.PodUIDLabel: "uid",
},
},
},
@@ -373,13 +373,13 @@ func TestPodHandler(t *testing.T) {
},
},
},
podVolumeRestores: []*arkv1api.PodVolumeRestore{
podVolumeRestores: []*velerov1api.PodVolumeRestore{
{
ObjectMeta: metav1.ObjectMeta{
Namespace: "ns-1",
Name: "pvr-1",
Labels: map[string]string{
arkv1api.PodUIDLabel: "uid",
velerov1api.PodUIDLabel: "uid",
},
},
},
@@ -390,12 +390,12 @@ func TestPodHandler(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var (
client = arkfake.NewSimpleClientset()
informers = arkinformers.NewSharedInformerFactory(client, 0)
pvrInformer = informers.Ark().V1().PodVolumeRestores()
client = velerofake.NewSimpleClientset()
informers = veleroinformers.NewSharedInformerFactory(client, 0)
pvrInformer = informers.Velero().V1().PodVolumeRestores()
c = &podVolumeRestoreController{
genericController: newGenericController("pod-volume-restore", arktest.NewLogger()),
podVolumeRestoreLister: arkv1listers.NewPodVolumeRestoreLister(pvrInformer.Informer().GetIndexer()),
genericController: newGenericController("pod-volume-restore", velerotest.NewLogger()),
podVolumeRestoreLister: velerov1listers.NewPodVolumeRestoreLister(pvrInformer.Informer().GetIndexer()),
nodeName: controllerNode,
}
)
@@ -421,14 +421,14 @@ func TestPodHandler(t *testing.T) {
}
func TestIsPVRNew(t *testing.T) {
pvr := &arkv1api.PodVolumeRestore{}
pvr := &velerov1api.PodVolumeRestore{}
expectationByStatus := map[arkv1api.PodVolumeRestorePhase]bool{
"": true,
arkv1api.PodVolumeRestorePhaseNew: true,
arkv1api.PodVolumeRestorePhaseInProgress: false,
arkv1api.PodVolumeRestorePhaseCompleted: false,
arkv1api.PodVolumeRestorePhaseFailed: false,
expectationByStatus := map[velerov1api.PodVolumeRestorePhase]bool{
"": true,
velerov1api.PodVolumeRestorePhaseNew: true,
velerov1api.PodVolumeRestorePhaseInProgress: false,
velerov1api.PodVolumeRestorePhaseCompleted: false,
velerov1api.PodVolumeRestorePhaseFailed: false,
}
for phase, expected := range expectationByStatus {

View File

@@ -30,17 +30,17 @@ import (
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/client-go/tools/cache"
"github.com/heptio/ark/pkg/apis/ark/v1"
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/restic"
v1 "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/restic"
)
type resticRepositoryController struct {
*genericController
resticRepositoryClient arkv1client.ResticRepositoriesGetter
resticRepositoryClient velerov1client.ResticRepositoriesGetter
resticRepositoryLister listers.ResticRepositoryLister
backupLocationLister listers.BackupStorageLocationLister
repositoryManager restic.RepositoryManager
@@ -52,7 +52,7 @@ type resticRepositoryController struct {
func NewResticRepositoryController(
logger logrus.FieldLogger,
resticRepositoryInformer informers.ResticRepositoryInformer,
resticRepositoryClient arkv1client.ResticRepositoriesGetter,
resticRepositoryClient velerov1client.ResticRepositoriesGetter,
backupLocationInformer informers.BackupStorageLocationInformer,
repositoryManager restic.RepositoryManager,
) Interface {

View File

@@ -33,17 +33,18 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/cache"
api "github.com/heptio/ark/pkg/apis/ark/v1"
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/metrics"
"github.com/heptio/ark/pkg/persistence"
"github.com/heptio/ark/pkg/plugin"
"github.com/heptio/ark/pkg/restore"
"github.com/heptio/ark/pkg/util/collections"
kubeutil "github.com/heptio/ark/pkg/util/kube"
"github.com/heptio/ark/pkg/util/logging"
api "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/metrics"
"github.com/heptio/velero/pkg/persistence"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/restore"
"github.com/heptio/velero/pkg/util/collections"
kubeutil "github.com/heptio/velero/pkg/util/kube"
"github.com/heptio/velero/pkg/util/logging"
)
// nonRestorableResources is a blacklist for the restoration process. Any resources
@@ -54,20 +55,22 @@ var nonRestorableResources = []string{
"events.events.k8s.io",
// Don't ever restore backups - if appropriate, they'll be synced in from object storage.
// https://github.com/heptio/ark/issues/622
// https://github.com/heptio/velero/issues/622
"backups.ark.heptio.com",
"backups.velero.io",
// Restores are cluster-specific, and don't have value moving across clusters.
// https://github.com/heptio/ark/issues/622
// https://github.com/heptio/velero/issues/622
"restores.ark.heptio.com",
"restores.velero.io",
}
type restoreController struct {
*genericController
namespace string
restoreClient arkv1client.RestoresGetter
backupClient arkv1client.BackupsGetter
restoreClient velerov1client.RestoresGetter
backupClient velerov1client.BackupsGetter
restorer restore.Restorer
backupLister listers.BackupLister
restoreLister listers.RestoreLister
@@ -88,8 +91,8 @@ type restoreResult struct {
func NewRestoreController(
namespace string,
restoreInformer informers.RestoreInformer,
restoreClient arkv1client.RestoresGetter,
backupClient arkv1client.BackupsGetter,
restoreClient velerov1client.RestoresGetter,
backupClient velerov1client.BackupsGetter,
restorer restore.Restorer,
backupInformer informers.BackupInformer,
backupLocationInformer informers.BackupStorageLocationInformer,
@@ -238,12 +241,14 @@ func (c *restoreController) processRestore(key string) error {
pluginManager,
)
restore.Status.Warnings = len(restoreRes.warnings.Ark) + len(restoreRes.warnings.Cluster)
//TODO(1.0): Remove warnings.Ark
restore.Status.Warnings = len(restoreRes.warnings.Velero) + len(restoreRes.warnings.Cluster) + len(restoreRes.warnings.Ark)
for _, w := range restoreRes.warnings.Namespaces {
restore.Status.Warnings += len(w)
}
restore.Status.Errors = len(restoreRes.errors.Ark) + len(restoreRes.errors.Cluster)
//TODO (1.0): Remove errors.Ark
restore.Status.Errors = len(restoreRes.errors.Velero) + len(restoreRes.errors.Cluster) + len(restoreRes.errors.Ark)
for _, e := range restoreRes.errors.Namespaces {
restore.Status.Errors += len(e)
}
@@ -310,7 +315,7 @@ func (c *restoreController) validateAndComplete(restore *api.Restore, pluginMana
// the schedule
if restore.Spec.ScheduleName != "" {
selector := labels.SelectorFromSet(labels.Set(map[string]string{
"ark-schedule": restore.Spec.ScheduleName,
velerov1api.ScheduleNameLabel: restore.Spec.ScheduleName,
}))
backups, err := c.backupLister.Backups(c.namespace).List(selector)
@@ -358,7 +363,7 @@ func (c *restoreController) validateAndComplete(restore *api.Restore, pluginMana
// Fill in the ScheduleName so it's easier to consume for metrics.
if restore.Spec.ScheduleName == "" {
restore.Spec.ScheduleName = info.backup.GetLabels()["ark-schedule"]
restore.Spec.ScheduleName = info.backup.GetLabels()[velerov1api.ScheduleNameLabel]
}
return info
@@ -419,33 +424,6 @@ func (c *restoreController) fetchBackupInfo(backupName string, pluginManager plu
}, nil
}
func (c *restoreController) backupInfoForLocation(location *api.BackupStorageLocation, backupName string, pluginManager plugin.Manager) (backupInfo, error) {
backupStore, err := persistence.NewObjectBackupStore(location, pluginManager, c.logger)
if err != nil {
return backupInfo{}, err
}
backup, err := backupStore.GetBackupMetadata(backupName)
if err != nil {
return backupInfo{}, err
}
// ResourceVersion needs to be cleared in order to create the object in the API
backup.ResourceVersion = ""
// Clear out the namespace, in case the backup was made in a different cluster, with a different namespace
backup.Namespace = ""
backupCreated, err := c.backupClient.Backups(c.namespace).Create(backup)
if err != nil {
return backupInfo{}, errors.WithStack(err)
}
return backupInfo{
backup: backupCreated,
backupStore: backupStore,
}, nil
}
func (c *restoreController) runRestore(
restore *api.Restore,
actions []restore.ItemAction,
@@ -465,7 +443,7 @@ func (c *restoreController) runRestore(
).
WithError(errors.WithStack(err)).
Error("Error creating log temp file")
restoreErrors.Ark = append(restoreErrors.Ark, err.Error())
restoreErrors.Velero = append(restoreErrors.Velero, err.Error())
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}
gzippedLogFile := gzip.NewWriter(logFile)
@@ -487,7 +465,7 @@ func (c *restoreController) runRestore(
backupFile, err := downloadToTempFile(restore.Spec.BackupName, info.backupStore, c.logger)
if err != nil {
log.WithError(err).Error("Error downloading backup")
restoreErrors.Ark = append(restoreErrors.Ark, err.Error())
restoreErrors.Velero = append(restoreErrors.Velero, err.Error())
restoreFailure = err
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}
@@ -496,7 +474,7 @@ func (c *restoreController) runRestore(
resultsFile, err := ioutil.TempFile("", "")
if err != nil {
log.WithError(errors.WithStack(err)).Error("Error creating results temp file")
restoreErrors.Ark = append(restoreErrors.Ark, err.Error())
restoreErrors.Velero = append(restoreErrors.Velero, err.Error())
restoreFailure = err
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}
@@ -505,7 +483,7 @@ func (c *restoreController) runRestore(
volumeSnapshots, err := info.backupStore.GetBackupVolumeSnapshots(restore.Spec.BackupName)
if err != nil {
log.WithError(errors.WithStack(err)).Error("Error fetching volume snapshots")
restoreErrors.Ark = append(restoreErrors.Ark, err.Error())
restoreErrors.Velero = append(restoreErrors.Velero, err.Error())
restoreFailure = err
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}
@@ -516,13 +494,13 @@ func (c *restoreController) runRestore(
restoreWarnings, restoreErrors = c.restorer.Restore(log, restore, info.backup, volumeSnapshots, backupFile, actions, c.snapshotLocationLister, pluginManager)
log.Info("restore completed")
// Try to upload the log file. This is best-effort. If we fail, we'll add to the ark errors.
// Try to upload the log file. This is best-effort. If we fail, we'll add to the velero errors.
if err := gzippedLogFile.Close(); err != nil {
c.logger.WithError(err).Error("error closing gzippedLogFile")
}
// Reset the offset to 0 for reading
if _, err = logFile.Seek(0, 0); err != nil {
restoreErrors.Ark = append(restoreErrors.Ark, fmt.Sprintf("error resetting log file offset to 0: %v", err))
restoreErrors.Velero = append(restoreErrors.Velero, fmt.Sprintf("error resetting log file offset to 0: %v", err))
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}
@@ -589,7 +567,7 @@ func downloadToTempFile(
return file, nil
}
func patchRestore(original, updated *api.Restore, client arkv1client.RestoresGetter) (*api.Restore, error) {
func patchRestore(original, updated *api.Restore, client velerov1client.RestoresGetter) (*api.Restore, error) {
origBytes, err := json.Marshal(original)
if err != nil {
return nil, errors.Wrap(err, "error marshalling original restore")

View File

@@ -34,19 +34,20 @@ import (
core "k8s.io/client-go/testing"
"k8s.io/client-go/tools/cache"
api "github.com/heptio/ark/pkg/apis/ark/v1"
"github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions"
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/metrics"
"github.com/heptio/ark/pkg/persistence"
persistencemocks "github.com/heptio/ark/pkg/persistence/mocks"
"github.com/heptio/ark/pkg/plugin"
pluginmocks "github.com/heptio/ark/pkg/plugin/mocks"
"github.com/heptio/ark/pkg/restore"
"github.com/heptio/ark/pkg/util/collections"
arktest "github.com/heptio/ark/pkg/util/test"
"github.com/heptio/ark/pkg/volume"
api "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
"github.com/heptio/velero/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/metrics"
"github.com/heptio/velero/pkg/persistence"
persistencemocks "github.com/heptio/velero/pkg/persistence/mocks"
"github.com/heptio/velero/pkg/plugin"
pluginmocks "github.com/heptio/velero/pkg/plugin/mocks"
"github.com/heptio/velero/pkg/restore"
"github.com/heptio/velero/pkg/util/collections"
velerotest "github.com/heptio/velero/pkg/util/test"
"github.com/heptio/velero/pkg/volume"
)
func TestFetchBackupInfo(t *testing.T) {
@@ -63,17 +64,17 @@ func TestFetchBackupInfo(t *testing.T) {
{
name: "lister has backup",
backupName: "backup-1",
informerLocations: []*api.BackupStorageLocation{arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation},
informerBackups: []*api.Backup{arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup},
expectedRes: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
informerLocations: []*api.BackupStorageLocation{velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation},
informerBackups: []*api.Backup{velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup},
expectedRes: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
},
{
name: "lister does not have a backup, but backupSvc does",
backupName: "backup-1",
backupStoreBackup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
informerLocations: []*api.BackupStorageLocation{arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation},
informerBackups: []*api.Backup{arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup},
expectedRes: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
backupStoreBackup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
informerLocations: []*api.BackupStorageLocation{velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation},
informerBackups: []*api.Backup{velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup},
expectedRes: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
},
{
name: "no backup",
@@ -89,7 +90,7 @@ func TestFetchBackupInfo(t *testing.T) {
client = fake.NewSimpleClientset()
restorer = &fakeRestorer{}
sharedInformers = informers.NewSharedInformerFactory(client, 0)
logger = arktest.NewLogger()
logger = velerotest.NewLogger()
pluginManager = &pluginmocks.Manager{}
backupStore = &persistencemocks.BackupStore{}
)
@@ -99,13 +100,13 @@ func TestFetchBackupInfo(t *testing.T) {
c := NewRestoreController(
api.DefaultNamespace,
sharedInformers.Ark().V1().Restores(),
client.ArkV1(),
client.ArkV1(),
sharedInformers.Velero().V1().Restores(),
client.VeleroV1(),
client.VeleroV1(),
restorer,
sharedInformers.Ark().V1().Backups(),
sharedInformers.Ark().V1().BackupStorageLocations(),
sharedInformers.Ark().V1().VolumeSnapshotLocations(),
sharedInformers.Velero().V1().Backups(),
sharedInformers.Velero().V1().BackupStorageLocations(),
sharedInformers.Velero().V1().VolumeSnapshotLocations(),
logger,
logrus.InfoLevel,
func(logrus.FieldLogger) plugin.Manager { return pluginManager },
@@ -119,11 +120,11 @@ func TestFetchBackupInfo(t *testing.T) {
if test.backupStoreError == nil {
for _, itm := range test.informerLocations {
sharedInformers.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(itm)
sharedInformers.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(itm)
}
for _, itm := range test.informerBackups {
sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(itm)
sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(itm)
}
}
@@ -167,17 +168,17 @@ func TestProcessRestoreSkips(t *testing.T) {
{
name: "restore with phase InProgress does not get processed",
restoreKey: "foo/bar",
restore: arktest.NewTestRestore("foo", "bar", api.RestorePhaseInProgress).Restore,
restore: velerotest.NewTestRestore("foo", "bar", api.RestorePhaseInProgress).Restore,
},
{
name: "restore with phase Completed does not get processed",
restoreKey: "foo/bar",
restore: arktest.NewTestRestore("foo", "bar", api.RestorePhaseCompleted).Restore,
restore: velerotest.NewTestRestore("foo", "bar", api.RestorePhaseCompleted).Restore,
},
{
name: "restore with phase FailedValidation does not get processed",
restoreKey: "foo/bar",
restore: arktest.NewTestRestore("foo", "bar", api.RestorePhaseFailedValidation).Restore,
restore: velerotest.NewTestRestore("foo", "bar", api.RestorePhaseFailedValidation).Restore,
},
}
@@ -187,18 +188,18 @@ func TestProcessRestoreSkips(t *testing.T) {
client = fake.NewSimpleClientset()
restorer = &fakeRestorer{}
sharedInformers = informers.NewSharedInformerFactory(client, 0)
logger = arktest.NewLogger()
logger = velerotest.NewLogger()
)
c := NewRestoreController(
api.DefaultNamespace,
sharedInformers.Ark().V1().Restores(),
client.ArkV1(),
client.ArkV1(),
sharedInformers.Velero().V1().Restores(),
client.VeleroV1(),
client.VeleroV1(),
restorer,
sharedInformers.Ark().V1().Backups(),
sharedInformers.Ark().V1().BackupStorageLocations(),
sharedInformers.Ark().V1().VolumeSnapshotLocations(),
sharedInformers.Velero().V1().Backups(),
sharedInformers.Velero().V1().BackupStorageLocations(),
sharedInformers.Velero().V1().VolumeSnapshotLocations(),
logger,
logrus.InfoLevel,
nil,
@@ -207,7 +208,7 @@ func TestProcessRestoreSkips(t *testing.T) {
).(*restoreController)
if test.restore != nil {
sharedInformers.Ark().V1().Restores().Informer().GetStore().Add(test.restore)
sharedInformers.Velero().V1().Restores().Informer().GetStore().Add(test.restore)
}
err := c.processRestore(test.restoreKey)
@@ -237,18 +238,18 @@ func TestProcessRestore(t *testing.T) {
}{
{
name: "restore with both namespace in both includedNamespaces and excludedNamespaces fails validation",
location: arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
location: velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "backup-1", "another-1", "*", api.RestorePhaseNew).WithExcludedNamespace("another-1").Restore,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
expectedErr: false,
expectedPhase: string(api.RestorePhaseFailedValidation),
expectedValidationErrors: []string{"Invalid included/excluded namespace lists: excludes list cannot contain an item in the includes list: another-1"},
},
{
name: "restore with resource in both includedResources and excludedResources fails validation",
location: arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
location: velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "backup-1", "*", "a-resource", api.RestorePhaseNew).WithExcludedResource("a-resource").Restore,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
expectedErr: false,
expectedPhase: string(api.RestorePhaseFailedValidation),
expectedValidationErrors: []string{"Invalid included/excluded resource lists: excludes list cannot contain an item in the includes list: a-resource"},
@@ -269,13 +270,13 @@ func TestProcessRestore(t *testing.T) {
},
{
name: "valid restore with schedule name gets executed",
location: arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
location: velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "", "ns-1", "", api.RestorePhaseNew).WithSchedule("sched-1").Restore,
backup: arktest.
backup: velerotest.
NewTestBackup().
WithName("backup-1").
WithStorageLocation("default").
WithLabel("ark-schedule", "sched-1").
WithLabel(velerov1api.ScheduleNameLabel, "sched-1").
WithPhase(api.BackupPhaseCompleted).
Backup,
expectedErr: false,
@@ -287,14 +288,14 @@ func TestProcessRestore(t *testing.T) {
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "*", api.RestorePhaseNew).Restore,
expectedErr: false,
expectedPhase: string(api.RestorePhaseFailedValidation),
expectedValidationErrors: []string{"Error retrieving backup: backup.ark.heptio.com \"backup-1\" not found"},
expectedValidationErrors: []string{"Error retrieving backup: backup.velero.io \"backup-1\" not found"},
backupStoreGetBackupMetadataErr: errors.New("no backup here"),
},
{
name: "restorer throwing an error causes the restore to fail",
location: arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
location: velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "", api.RestorePhaseNew).Restore,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
restorerError: errors.New("blarg"),
expectedErr: false,
expectedPhase: string(api.RestorePhaseInProgress),
@@ -303,18 +304,18 @@ func TestProcessRestore(t *testing.T) {
},
{
name: "valid restore gets executed",
location: arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
location: velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "", api.RestorePhaseNew).Restore,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
expectedErr: false,
expectedPhase: string(api.RestorePhaseInProgress),
expectedRestorerCall: NewRestore("foo", "bar", "backup-1", "ns-1", "", api.RestorePhaseInProgress).Restore,
},
{
name: "restoration of nodes is not supported",
location: arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
location: velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "nodes", api.RestorePhaseNew).Restore,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
expectedErr: false,
expectedPhase: string(api.RestorePhaseFailedValidation),
expectedValidationErrors: []string{
@@ -324,9 +325,9 @@ func TestProcessRestore(t *testing.T) {
},
{
name: "restoration of events is not supported",
location: arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
location: velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "events", api.RestorePhaseNew).Restore,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
expectedErr: false,
expectedPhase: string(api.RestorePhaseFailedValidation),
expectedValidationErrors: []string{
@@ -336,9 +337,9 @@ func TestProcessRestore(t *testing.T) {
},
{
name: "restoration of events.events.k8s.io is not supported",
location: arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
location: velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "events.events.k8s.io", api.RestorePhaseNew).Restore,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
expectedErr: false,
expectedPhase: string(api.RestorePhaseFailedValidation),
expectedValidationErrors: []string{
@@ -347,37 +348,37 @@ func TestProcessRestore(t *testing.T) {
},
},
{
name: "restoration of backups.ark.heptio.com is not supported",
location: arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "backups.ark.heptio.com", api.RestorePhaseNew).Restore,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
name: "restoration of backups.velero.io is not supported",
location: velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "backups.velero.io", api.RestorePhaseNew).Restore,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
expectedErr: false,
expectedPhase: string(api.RestorePhaseFailedValidation),
expectedValidationErrors: []string{
"backups.ark.heptio.com are non-restorable resources",
"Invalid included/excluded resource lists: excludes list cannot contain an item in the includes list: backups.ark.heptio.com",
"backups.velero.io are non-restorable resources",
"Invalid included/excluded resource lists: excludes list cannot contain an item in the includes list: backups.velero.io",
},
},
{
name: "restoration of restores.ark.heptio.com is not supported",
location: arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "restores.ark.heptio.com", api.RestorePhaseNew).Restore,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
name: "restoration of restores.velero.io is not supported",
location: velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "restores.velero.io", api.RestorePhaseNew).Restore,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
expectedErr: false,
expectedPhase: string(api.RestorePhaseFailedValidation),
expectedValidationErrors: []string{
"restores.ark.heptio.com are non-restorable resources",
"Invalid included/excluded resource lists: excludes list cannot contain an item in the includes list: restores.ark.heptio.com",
"restores.velero.io are non-restorable resources",
"Invalid included/excluded resource lists: excludes list cannot contain an item in the includes list: restores.velero.io",
},
},
{
name: "backup download error results in failed restore",
location: arktest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
location: velerotest.NewTestBackupStorageLocation().WithName("default").WithProvider("myCloud").WithObjectStorage("bucket").BackupStorageLocation,
restore: NewRestore(api.DefaultNamespace, "bar", "backup-1", "ns-1", "", api.RestorePhaseNew).Restore,
expectedPhase: string(api.RestorePhaseInProgress),
expectedFinalPhase: string(api.RestorePhaseFailed),
backupStoreGetBackupContentsErr: errors.New("Couldn't download backup"),
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("default").Backup,
},
}
@@ -387,7 +388,7 @@ func TestProcessRestore(t *testing.T) {
client = fake.NewSimpleClientset()
restorer = &fakeRestorer{}
sharedInformers = informers.NewSharedInformerFactory(client, 0)
logger = arktest.NewLogger()
logger = velerotest.NewLogger()
pluginManager = &pluginmocks.Manager{}
backupStore = &persistencemocks.BackupStore{}
)
@@ -397,13 +398,13 @@ func TestProcessRestore(t *testing.T) {
c := NewRestoreController(
api.DefaultNamespace,
sharedInformers.Ark().V1().Restores(),
client.ArkV1(),
client.ArkV1(),
sharedInformers.Velero().V1().Restores(),
client.VeleroV1(),
client.VeleroV1(),
restorer,
sharedInformers.Ark().V1().Backups(),
sharedInformers.Ark().V1().BackupStorageLocations(),
sharedInformers.Ark().V1().VolumeSnapshotLocations(),
sharedInformers.Velero().V1().Backups(),
sharedInformers.Velero().V1().BackupStorageLocations(),
sharedInformers.Velero().V1().VolumeSnapshotLocations(),
logger,
logrus.InfoLevel,
func(logrus.FieldLogger) plugin.Manager { return pluginManager },
@@ -416,14 +417,14 @@ func TestProcessRestore(t *testing.T) {
}
if test.location != nil {
sharedInformers.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(test.location)
sharedInformers.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(test.location)
}
if test.backup != nil {
sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(test.backup)
sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(test.backup)
}
if test.restore != nil {
sharedInformers.Ark().V1().Restores().Informer().GetStore().Add(test.restore)
sharedInformers.Velero().V1().Restores().Informer().GetStore().Add(test.restore)
// this is necessary so the Patch() call returns the appropriate object
client.PrependReactor("patch", "restores", func(action core.Action) (bool, runtime.Object, error) {
@@ -461,7 +462,7 @@ func TestProcessRestore(t *testing.T) {
}
if test.backup != nil {
sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(test.backup)
sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(test.backup)
}
var warnings, errors api.RestoreResult
@@ -469,7 +470,7 @@ func TestProcessRestore(t *testing.T) {
errors.Namespaces = map[string][]string{"ns-1": {test.restorerError.Error()}}
}
if test.putRestoreLogErr != nil {
errors.Ark = append(errors.Ark, "error uploading log file to object storage: "+test.putRestoreLogErr.Error())
errors.Velero = append(errors.Velero, "error uploading log file to object storage: "+test.putRestoreLogErr.Error())
}
if test.expectedRestorerCall != nil {
backupStore.On("GetBackupContents", test.backup.Name).Return(ioutil.NopCloser(bytes.NewReader([]byte("hello world"))), nil)
@@ -566,7 +567,7 @@ func TestProcessRestore(t *testing.T) {
}
}
arktest.ValidatePatch(t, actions[0], expected, decode)
velerotest.ValidatePatch(t, actions[0], expected, decode)
// if we don't expect a restore, validate it wasn't called and exit the test
if test.expectedRestorerCall == nil {
@@ -594,7 +595,7 @@ func TestProcessRestore(t *testing.T) {
}
}
arktest.ValidatePatch(t, actions[1], expected, decode)
velerotest.ValidatePatch(t, actions[1], expected, decode)
// explicitly capturing the argument passed to Restore myself because
// I want to validate the called arg as of the time of calling, but
@@ -616,31 +617,31 @@ func TestValidateAndComplete(t *testing.T) {
}{
{
name: "backup with .status.volumeBackups and no volumesnapshots.json file does not error",
storageLocation: arktest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("loc-1").WithSnapshot("pv-1", "snap-1").Backup,
storageLocation: velerotest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("loc-1").WithSnapshot("pv-1", "snap-1").Backup,
volumeSnapshots: nil,
restore: arktest.NewDefaultTestRestore().WithBackup("backup-1").Restore,
restore: velerotest.NewDefaultTestRestore().WithBackup("backup-1").Restore,
expectedErrs: nil,
},
{
name: "backup with no .status.volumeBackups and volumesnapshots.json file does not error",
storageLocation: arktest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("loc-1").Backup,
storageLocation: velerotest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("loc-1").Backup,
volumeSnapshots: []*volume.Snapshot{{}},
restore: arktest.NewDefaultTestRestore().WithBackup("backup-1").Restore,
restore: velerotest.NewDefaultTestRestore().WithBackup("backup-1").Restore,
expectedErrs: nil,
},
{
name: "backup with both .status.volumeBackups and volumesnapshots.json file errors",
storageLocation: arktest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation,
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("loc-1").WithSnapshot("pv-1", "snap-1").Backup,
storageLocation: velerotest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("loc-1").WithSnapshot("pv-1", "snap-1").Backup,
volumeSnapshots: []*volume.Snapshot{{}},
restore: arktest.NewDefaultTestRestore().WithBackup("backup-1").Restore,
restore: velerotest.NewDefaultTestRestore().WithBackup("backup-1").Restore,
expectedErrs: []string{"Backup must not have both .status.volumeBackups and a volumesnapshots.json.gz file in object storage"},
},
{
name: "backup with .status.volumeBackups, and >1 volume snapshot locations exist, errors",
storageLocation: arktest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation,
storageLocation: velerotest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation,
snapshotLocations: []*api.VolumeSnapshotLocation{
{
ObjectMeta: metav1.ObjectMeta{
@@ -655,13 +656,13 @@ func TestValidateAndComplete(t *testing.T) {
},
},
},
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("loc-1").WithSnapshot("pv-1", "snap-1").Backup,
restore: arktest.NewDefaultTestRestore().WithBackup("backup-1").Restore,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("loc-1").WithSnapshot("pv-1", "snap-1").Backup,
restore: velerotest.NewDefaultTestRestore().WithBackup("backup-1").Restore,
expectedErrs: []string{"Cannot restore backup with .status.volumeBackups when more than one volume snapshot location exists"},
},
{
name: "backup with .status.volumeBackups, and 1 volume snapshot location exists, does not error",
storageLocation: arktest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation,
storageLocation: velerotest.NewTestBackupStorageLocation().WithName("loc-1").BackupStorageLocation,
snapshotLocations: []*api.VolumeSnapshotLocation{
{
ObjectMeta: metav1.ObjectMeta{
@@ -670,8 +671,8 @@ func TestValidateAndComplete(t *testing.T) {
},
},
},
backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("loc-1").WithSnapshot("pv-1", "snap-1").Backup,
restore: arktest.NewDefaultTestRestore().WithBackup("backup-1").Restore,
backup: velerotest.NewTestBackup().WithName("backup-1").WithStorageLocation("loc-1").WithSnapshot("pv-1", "snap-1").Backup,
restore: velerotest.NewDefaultTestRestore().WithBackup("backup-1").Restore,
expectedErrs: nil,
},
}
@@ -681,26 +682,26 @@ func TestValidateAndComplete(t *testing.T) {
var (
clientset = fake.NewSimpleClientset()
sharedInformers = informers.NewSharedInformerFactory(clientset, 0)
logger = arktest.NewLogger()
logger = velerotest.NewLogger()
backupStore = &persistencemocks.BackupStore{}
controller = &restoreController{
genericController: &genericController{
logger: logger,
},
namespace: api.DefaultNamespace,
backupLister: sharedInformers.Ark().V1().Backups().Lister(),
backupLocationLister: sharedInformers.Ark().V1().BackupStorageLocations().Lister(),
snapshotLocationLister: sharedInformers.Ark().V1().VolumeSnapshotLocations().Lister(),
backupLister: sharedInformers.Velero().V1().Backups().Lister(),
backupLocationLister: sharedInformers.Velero().V1().BackupStorageLocations().Lister(),
snapshotLocationLister: sharedInformers.Velero().V1().VolumeSnapshotLocations().Lister(),
newBackupStore: func(*api.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error) {
return backupStore, nil
},
}
)
require.NoError(t, sharedInformers.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(tc.storageLocation))
require.NoError(t, sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(tc.backup))
require.NoError(t, sharedInformers.Velero().V1().BackupStorageLocations().Informer().GetStore().Add(tc.storageLocation))
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(tc.backup))
for _, loc := range tc.snapshotLocations {
require.NoError(t, sharedInformers.Ark().V1().VolumeSnapshotLocations().Informer().GetStore().Add(loc))
require.NoError(t, sharedInformers.Velero().V1().VolumeSnapshotLocations().Informer().GetStore().Add(loc))
}
backupStore.On("GetBackupVolumeSnapshots", tc.backup.Name).Return(tc.volumeSnapshots, nil)
@@ -716,19 +717,19 @@ func TestvalidateAndCompleteWhenScheduleNameSpecified(t *testing.T) {
var (
client = fake.NewSimpleClientset()
sharedInformers = informers.NewSharedInformerFactory(client, 0)
logger = arktest.NewLogger()
logger = velerotest.NewLogger()
pluginManager = &pluginmocks.Manager{}
)
c := NewRestoreController(
api.DefaultNamespace,
sharedInformers.Ark().V1().Restores(),
client.ArkV1(),
client.ArkV1(),
sharedInformers.Velero().V1().Restores(),
client.VeleroV1(),
client.VeleroV1(),
nil,
sharedInformers.Ark().V1().Backups(),
sharedInformers.Ark().V1().BackupStorageLocations(),
sharedInformers.Ark().V1().VolumeSnapshotLocations(),
sharedInformers.Velero().V1().Backups(),
sharedInformers.Velero().V1().BackupStorageLocations(),
sharedInformers.Velero().V1().VolumeSnapshotLocations(),
logger,
logrus.DebugLevel,
nil,
@@ -747,10 +748,10 @@ func TestvalidateAndCompleteWhenScheduleNameSpecified(t *testing.T) {
}
// no backups created from the schedule: fail validation
require.NoError(t, sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(arktest.
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(velerotest.
NewTestBackup().
WithName("backup-1").
WithLabel("ark-schedule", "non-matching-schedule").
WithLabel(velerov1api.ScheduleNameLabel, "non-matching-schedule").
WithPhase(api.BackupPhaseCompleted).
Backup,
))
@@ -760,10 +761,10 @@ func TestvalidateAndCompleteWhenScheduleNameSpecified(t *testing.T) {
assert.Empty(t, restore.Spec.BackupName)
// no completed backups created from the schedule: fail validation
require.NoError(t, sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(arktest.
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(velerotest.
NewTestBackup().
WithName("backup-2").
WithLabel("ark-schedule", "schedule-1").
WithLabel(velerov1api.ScheduleNameLabel, "schedule-1").
WithPhase(api.BackupPhaseInProgress).
Backup,
))
@@ -775,18 +776,18 @@ func TestvalidateAndCompleteWhenScheduleNameSpecified(t *testing.T) {
// multiple completed backups created from the schedule: use most recent
now := time.Now()
require.NoError(t, sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(arktest.
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(velerotest.
NewTestBackup().
WithName("foo").
WithLabel("ark-schedule", "schedule-1").
WithLabel(velerov1api.ScheduleNameLabel, "schedule-1").
WithPhase(api.BackupPhaseCompleted).
WithStartTimestamp(now).
Backup,
))
require.NoError(t, sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(arktest.
require.NoError(t, sharedInformers.Velero().V1().Backups().Informer().GetStore().Add(velerotest.
NewTestBackup().
WithName("bar").
WithLabel("ark-schedule", "schedule-1").
WithLabel(velerov1api.ScheduleNameLabel, "schedule-1").
WithPhase(api.BackupPhaseCompleted).
WithStartTimestamp(now.Add(time.Second)).
Backup,
@@ -887,8 +888,8 @@ func TestMostRecentCompletedBackup(t *testing.T) {
assert.Equal(t, expected, mostRecentCompletedBackup(backups))
}
func NewRestore(ns, name, backup, includeNS, includeResource string, phase api.RestorePhase) *arktest.TestRestore {
restore := arktest.NewTestRestore(ns, name, phase).WithBackup(backup)
func NewRestore(ns, name, backup, includeNS, includeResource string, phase api.RestorePhase) *velerotest.TestRestore {
restore := velerotest.NewTestRestore(ns, name, phase).WithBackup(backup)
if includeNS != "" {
restore = restore.WithIncludedNamespace(includeNS)

View File

@@ -32,12 +32,13 @@ import (
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/client-go/tools/cache"
api "github.com/heptio/ark/pkg/apis/ark/v1"
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/metrics"
kubeutil "github.com/heptio/ark/pkg/util/kube"
api "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/metrics"
kubeutil "github.com/heptio/velero/pkg/util/kube"
)
const (
@@ -48,8 +49,8 @@ type scheduleController struct {
*genericController
namespace string
schedulesClient arkv1client.SchedulesGetter
backupsClient arkv1client.BackupsGetter
schedulesClient velerov1client.SchedulesGetter
backupsClient velerov1client.BackupsGetter
schedulesLister listers.ScheduleLister
clock clock.Clock
metrics *metrics.ServerMetrics
@@ -57,8 +58,8 @@ type scheduleController struct {
func NewScheduleController(
namespace string,
schedulesClient arkv1client.SchedulesGetter,
backupsClient arkv1client.BackupsGetter,
schedulesClient velerov1client.SchedulesGetter,
backupsClient velerov1client.BackupsGetter,
schedulesInformer informers.ScheduleInformer,
logger logrus.FieldLogger,
metrics *metrics.ServerMetrics,
@@ -293,7 +294,6 @@ func getBackup(item *api.Schedule, timestamp time.Time) *api.Backup {
},
}
// add schedule labels and 'ark-schedule' label to the backup
addLabelsToBackup(item, backup)
return backup
@@ -304,12 +304,12 @@ func addLabelsToBackup(item *api.Schedule, backup *api.Backup) {
if labels == nil {
labels = make(map[string]string)
}
labels["ark-schedule"] = item.Name
labels[velerov1api.ScheduleNameLabel] = item.Name
backup.Labels = labels
}
func patchSchedule(original, updated *api.Schedule, client arkv1client.SchedulesGetter) (*api.Schedule, error) {
func patchSchedule(original, updated *api.Schedule, client velerov1client.SchedulesGetter) (*api.Schedule, error) {
origBytes, err := json.Marshal(original)
if err != nil {
return nil, errors.Wrap(err, "error marshalling original schedule")

View File

@@ -30,12 +30,13 @@ import (
core "k8s.io/client-go/testing"
"k8s.io/client-go/tools/cache"
api "github.com/heptio/ark/pkg/apis/ark/v1"
"github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions"
"github.com/heptio/ark/pkg/metrics"
"github.com/heptio/ark/pkg/util/collections"
arktest "github.com/heptio/ark/pkg/util/test"
api "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
"github.com/heptio/velero/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions"
"github.com/heptio/velero/pkg/metrics"
"github.com/heptio/velero/pkg/util/collections"
velerotest "github.com/heptio/velero/pkg/util/test"
)
func TestProcessSchedule(t *testing.T) {
@@ -62,54 +63,54 @@ func TestProcessSchedule(t *testing.T) {
},
{
name: "schedule with phase FailedValidation does not get processed",
schedule: arktest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseFailedValidation).Schedule,
schedule: velerotest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseFailedValidation).Schedule,
expectedErr: false,
},
{
name: "schedule with phase New gets validated and failed if invalid",
schedule: arktest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseNew).Schedule,
schedule: velerotest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseNew).Schedule,
expectedErr: false,
expectedPhase: string(api.SchedulePhaseFailedValidation),
expectedValidationErrors: []string{"Schedule must be a non-empty valid Cron expression"},
},
{
name: "schedule with phase <blank> gets validated and failed if invalid",
schedule: arktest.NewTestSchedule("ns", "name").Schedule,
schedule: velerotest.NewTestSchedule("ns", "name").Schedule,
expectedErr: false,
expectedPhase: string(api.SchedulePhaseFailedValidation),
expectedValidationErrors: []string{"Schedule must be a non-empty valid Cron expression"},
},
{
name: "schedule with phase Enabled gets re-validated and failed if invalid",
schedule: arktest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseEnabled).Schedule,
schedule: velerotest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseEnabled).Schedule,
expectedErr: false,
expectedPhase: string(api.SchedulePhaseFailedValidation),
expectedValidationErrors: []string{"Schedule must be a non-empty valid Cron expression"},
},
{
name: "schedule with phase New gets validated and triggers a backup",
schedule: arktest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseNew).WithCronSchedule("@every 5m").Schedule,
schedule: velerotest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseNew).WithCronSchedule("@every 5m").Schedule,
fakeClockTime: "2017-01-01 12:00:00",
expectedErr: false,
expectedPhase: string(api.SchedulePhaseEnabled),
expectedBackupCreate: arktest.NewTestBackup().WithNamespace("ns").WithName("name-20170101120000").WithLabel("ark-schedule", "name").Backup,
expectedBackupCreate: velerotest.NewTestBackup().WithNamespace("ns").WithName("name-20170101120000").WithLabel(velerov1api.ScheduleNameLabel, "name").Backup,
expectedLastBackup: "2017-01-01 12:00:00",
},
{
name: "schedule with phase Enabled gets re-validated and triggers a backup if valid",
schedule: arktest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseEnabled).WithCronSchedule("@every 5m").Schedule,
schedule: velerotest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseEnabled).WithCronSchedule("@every 5m").Schedule,
fakeClockTime: "2017-01-01 12:00:00",
expectedErr: false,
expectedBackupCreate: arktest.NewTestBackup().WithNamespace("ns").WithName("name-20170101120000").WithLabel("ark-schedule", "name").Backup,
expectedBackupCreate: velerotest.NewTestBackup().WithNamespace("ns").WithName("name-20170101120000").WithLabel(velerov1api.ScheduleNameLabel, "name").Backup,
expectedLastBackup: "2017-01-01 12:00:00",
},
{
name: "schedule that's already run gets LastBackup updated",
schedule: arktest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseEnabled).
schedule: velerotest.NewTestSchedule("ns", "name").WithPhase(api.SchedulePhaseEnabled).
WithCronSchedule("@every 5m").WithLastBackupTime("2000-01-01 00:00:00").Schedule,
fakeClockTime: "2017-01-01 12:00:00",
expectedErr: false,
expectedBackupCreate: arktest.NewTestBackup().WithNamespace("ns").WithName("name-20170101120000").WithLabel("ark-schedule", "name").Backup,
expectedBackupCreate: velerotest.NewTestBackup().WithNamespace("ns").WithName("name-20170101120000").WithLabel(velerov1api.ScheduleNameLabel, "name").Backup,
expectedLastBackup: "2017-01-01 12:00:00",
},
}
@@ -119,14 +120,14 @@ func TestProcessSchedule(t *testing.T) {
var (
client = fake.NewSimpleClientset()
sharedInformers = informers.NewSharedInformerFactory(client, 0)
logger = arktest.NewLogger()
logger = velerotest.NewLogger()
)
c := NewScheduleController(
"namespace",
client.ArkV1(),
client.ArkV1(),
sharedInformers.Ark().V1().Schedules(),
client.VeleroV1(),
client.VeleroV1(),
sharedInformers.Velero().V1().Schedules(),
logger,
metrics.NewServerMetrics(),
)
@@ -142,7 +143,7 @@ func TestProcessSchedule(t *testing.T) {
c.clock = clock.NewFakeClock(testTime)
if test.schedule != nil {
sharedInformers.Ark().V1().Schedules().Informer().GetStore().Add(test.schedule)
sharedInformers.Velero().V1().Schedules().Informer().GetStore().Add(test.schedule)
// this is necessary so the Patch() call returns the appropriate object
client.PrependReactor("patch", "schedules", func(action core.Action) (bool, runtime.Object, error) {
@@ -217,7 +218,7 @@ func TestProcessSchedule(t *testing.T) {
},
}
arktest.ValidatePatch(t, actions[index], expected, decode)
velerotest.ValidatePatch(t, actions[index], expected, decode)
index++
}
@@ -244,7 +245,7 @@ func TestProcessSchedule(t *testing.T) {
},
}
arktest.ValidatePatch(t, actions[index], expected, decode)
velerotest.ValidatePatch(t, actions[index], expected, decode)
}
})
}
@@ -329,7 +330,7 @@ func TestGetNextRunTime(t *testing.T) {
}
func TestParseCronSchedule(t *testing.T) {
// From https://github.com/heptio/ark/issues/30, where we originally were using cron.Parse(),
// From https://github.com/heptio/velero/issues/30, where we originally were using cron.Parse(),
// which treats the first field as seconds, and not minutes. We want to use cron.ParseStandard()
// instead, which has the first field as minutes.
@@ -347,7 +348,7 @@ func TestParseCronSchedule(t *testing.T) {
},
}
logger := arktest.NewLogger()
logger := velerotest.NewLogger()
c, errs := parseCronSchedule(s, logger)
require.Empty(t, errs)
@@ -403,7 +404,7 @@ func TestGetBackup(t *testing.T) {
Namespace: "foo",
Name: "bar-20170725091500",
Labels: map[string]string{
"ark-schedule": "bar",
velerov1api.ScheduleNameLabel: "bar",
},
},
Spec: api.BackupSpec{},
@@ -426,7 +427,7 @@ func TestGetBackup(t *testing.T) {
Namespace: "foo",
Name: "bar-20170725141500",
Labels: map[string]string{
"ark-schedule": "bar",
velerov1api.ScheduleNameLabel: "bar",
},
},
Spec: api.BackupSpec{},
@@ -456,7 +457,7 @@ func TestGetBackup(t *testing.T) {
Namespace: "foo",
Name: "bar-20170725091500",
Labels: map[string]string{
"ark-schedule": "bar",
velerov1api.ScheduleNameLabel: "bar",
},
},
Spec: api.BackupSpec{
@@ -490,9 +491,9 @@ func TestGetBackup(t *testing.T) {
Namespace: "foo",
Name: "bar-20170725141500",
Labels: map[string]string{
"ark-schedule": "bar",
"bar": "baz",
"foo": "bar",
velerov1api.ScheduleNameLabel: "bar",
"bar": "baz",
"foo": "bar",
},
},
Spec: api.BackupSpec{},

View File

@@ -26,12 +26,12 @@ import (
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/client-go/tools/cache"
arkv1api "github.com/heptio/ark/pkg/apis/ark/v1"
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
arkv1informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
arkv1listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
"github.com/heptio/ark/pkg/serverstatusrequest"
kubeutil "github.com/heptio/ark/pkg/util/kube"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
velerov1informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
velerov1listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/serverstatusrequest"
kubeutil "github.com/heptio/velero/pkg/util/kube"
)
const statusRequestResyncPeriod = 5 * time.Minute
@@ -39,15 +39,15 @@ const statusRequestResyncPeriod = 5 * time.Minute
type statusRequestController struct {
*genericController
client arkv1client.ServerStatusRequestsGetter
lister arkv1listers.ServerStatusRequestLister
client velerov1client.ServerStatusRequestsGetter
lister velerov1listers.ServerStatusRequestLister
clock clock.Clock
}
func NewServerStatusRequestController(
logger logrus.FieldLogger,
client arkv1client.ServerStatusRequestsGetter,
informer arkv1informers.ServerStatusRequestInformer,
client velerov1client.ServerStatusRequestsGetter,
informer velerov1informers.ServerStatusRequestInformer,
) *statusRequestController {
c := &statusRequestController{
genericController: newGenericController("serverstatusrequest", logger),
@@ -66,7 +66,7 @@ func NewServerStatusRequestController(
informer.Informer().AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
req := obj.(*arkv1api.ServerStatusRequest)
req := obj.(*velerov1api.ServerStatusRequest)
key := kubeutil.NamespaceAndName(req)
c.logger.WithFields(logrus.Fields{