Files
velero/pkg/util/test/test_backup.go
Andy Goldstein 74f60b1ee1 Switch backup finalizer to DeleteBackupRequest
We ran into a lot of problems using a finalizer on the backup to allow
the Ark server to clean up all associated backup data when deleting a
backup.

Users also found it less than desirable that deleting the heptio-ark
namespace resulted in all the backup data being deleted.

This removes the finalizer and replaces it with an explicit
DeleteBackupRequest that is created as a means of requesting the
deletion of a backup and all its associated data. This is what `ark
backup delete` does.

If you use kubectl to delete a backup or to delete the heptio-ark
namespace, this no longer deletes associated backups. Additionally, as
long as the heptio-ark namespace still exists, the Ark server's
BackupSyncController will continually sync backups into the heptio-ark
namespace from object storage.

Signed-off-by: Andy Goldstein <andy.goldstein@gmail.com>
2018-04-05 11:16:15 -04:00

127 lines
2.9 KiB
Go

/*
Copyright 2017 the Heptio Ark contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package test
import (
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/heptio/ark/pkg/apis/ark/v1"
)
type TestBackup struct {
*v1.Backup
}
func NewTestBackup() *TestBackup {
return &TestBackup{
Backup: &v1.Backup{
ObjectMeta: metav1.ObjectMeta{
Namespace: v1.DefaultNamespace,
},
},
}
}
func (b *TestBackup) WithNamespace(namespace string) *TestBackup {
b.Namespace = namespace
return b
}
func (b *TestBackup) WithName(name string) *TestBackup {
b.Name = name
return b
}
func (b *TestBackup) WithLabel(key, value string) *TestBackup {
if b.Labels == nil {
b.Labels = make(map[string]string)
}
b.Labels[key] = value
return b
}
func (b *TestBackup) WithPhase(phase v1.BackupPhase) *TestBackup {
b.Status.Phase = phase
return b
}
func (b *TestBackup) WithIncludedResources(r ...string) *TestBackup {
b.Spec.IncludedResources = r
return b
}
func (b *TestBackup) WithExcludedResources(r ...string) *TestBackup {
b.Spec.ExcludedResources = r
return b
}
func (b *TestBackup) WithIncludedNamespaces(ns ...string) *TestBackup {
b.Spec.IncludedNamespaces = ns
return b
}
func (b *TestBackup) WithExcludedNamespaces(ns ...string) *TestBackup {
b.Spec.ExcludedNamespaces = ns
return b
}
func (b *TestBackup) WithTTL(ttl time.Duration) *TestBackup {
b.Spec.TTL = metav1.Duration{Duration: ttl}
return b
}
func (b *TestBackup) WithExpiration(expiration time.Time) *TestBackup {
b.Status.Expiration = metav1.Time{Time: expiration}
return b
}
func (b *TestBackup) WithVersion(version int) *TestBackup {
b.Status.Version = version
return b
}
func (b *TestBackup) WithSnapshot(pv string, snapshot string) *TestBackup {
if b.Status.VolumeBackups == nil {
b.Status.VolumeBackups = make(map[string]*v1.VolumeBackupInfo)
}
b.Status.VolumeBackups[pv] = &v1.VolumeBackupInfo{SnapshotID: snapshot}
return b
}
func (b *TestBackup) WithSnapshotVolumes(value bool) *TestBackup {
b.Spec.SnapshotVolumes = &value
return b
}
func (b *TestBackup) WithSnapshotVolumesPointer(value *bool) *TestBackup {
b.Spec.SnapshotVolumes = value
return b
}
func (b *TestBackup) WithDeletionTimestamp(time time.Time) *TestBackup {
b.DeletionTimestamp = &metav1.Time{Time: time}
return b
}
func (b *TestBackup) WithResourceVersion(version string) *TestBackup {
b.ResourceVersion = version
return b
}