when syncing backups, set their namespace to current cluster's Ark ns

Signed-off-by: Steve Kriss <steve@heptio.com>
This commit is contained in:
Steve Kriss
2018-05-07 09:12:51 -07:00
parent b6316aff70
commit 6754955bcd
3 changed files with 21 additions and 2 deletions
+1
View File
@@ -451,6 +451,7 @@ func (s *server) runControllers(config *api.Config) error {
s.backupService,
config.BackupStorageProvider.Bucket,
config.BackupSyncPeriod.Duration,
s.namespace,
s.logger,
)
wg.Add(1)
+4
View File
@@ -37,6 +37,7 @@ type backupSyncController struct {
backupService cloudprovider.BackupService
bucket string
syncPeriod time.Duration
namespace string
logger logrus.FieldLogger
}
@@ -45,6 +46,7 @@ func NewBackupSyncController(
backupService cloudprovider.BackupService,
bucket string,
syncPeriod time.Duration,
namespace string,
logger logrus.FieldLogger,
) Interface {
if syncPeriod < time.Minute {
@@ -56,6 +58,7 @@ func NewBackupSyncController(
backupService: backupService,
bucket: bucket,
syncPeriod: syncPeriod,
namespace: namespace,
logger: logger,
}
}
@@ -88,6 +91,7 @@ func (c *backupSyncController) run() {
// faster than the sync finishes. Just process them as we find them.
cloudBackup.Finalizers = stringslice.Except(cloudBackup.Finalizers, gcFinalizer)
cloudBackup.Namespace = c.namespace
cloudBackup.ResourceVersion = ""
if _, err := c.client.Backups(cloudBackup.Namespace).Create(cloudBackup); err != nil && !kuberrs.IsAlreadyExists(err) {
logContext.WithError(errors.WithStack(err)).Error("Error syncing backup from object storage")
+16 -2
View File
@@ -36,6 +36,7 @@ func TestBackupSyncControllerRun(t *testing.T) {
name string
getAllBackupsError error
cloudBackups []*v1.Backup
namespace string
}{
{
name: "no cloud backups",
@@ -49,20 +50,31 @@ func TestBackupSyncControllerRun(t *testing.T) {
cloudBackups: []*v1.Backup{
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").Backup,
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-2").Backup,
arktest.NewTestBackup().WithNamespace("ns-2").WithName("backup-3").Backup,
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-3").Backup,
},
namespace: "ns-1",
},
{
name: "Finalizer gets removed on sync",
cloudBackups: []*v1.Backup{
arktest.NewTestBackup().WithNamespace("ns-1").WithFinalizers(gcFinalizer).Backup,
},
namespace: "ns-1",
},
{
name: "Only target finalizer is removed",
cloudBackups: []*v1.Backup{
arktest.NewTestBackup().WithNamespace("ns-1").WithFinalizers(gcFinalizer, "blah").Backup,
},
namespace: "ns-1",
},
{
name: "backups get created in Ark server's namespace",
cloudBackups: []*v1.Backup{
arktest.NewTestBackup().WithNamespace("ns-1").WithName("backup-1").Backup,
arktest.NewTestBackup().WithNamespace("ns-2").WithName("backup-2").Backup,
},
namespace: "heptio-ark",
},
}
@@ -79,6 +91,7 @@ func TestBackupSyncControllerRun(t *testing.T) {
bs,
"bucket",
time.Duration(0),
test.namespace,
logger,
).(*backupSyncController)
@@ -92,9 +105,10 @@ func TestBackupSyncControllerRun(t *testing.T) {
for _, cloudBackup := range test.cloudBackups {
// Verify that the run function stripped the GC finalizer
assert.False(t, stringslice.Has(cloudBackup.Finalizers, gcFinalizer))
assert.Equal(t, test.namespace, cloudBackup.Namespace)
action := core.NewCreateAction(
v1.SchemeGroupVersion.WithResource("backups"),
cloudBackup.Namespace,
test.namespace,
cloudBackup,
)