2017-08-02 17:27:17 +00:00
|
|
|
/*
|
2018-01-02 18:51:49 +00:00
|
|
|
Copyright 2017 the Heptio Ark contributors.
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
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 controller
|
|
|
|
|
|
|
|
import (
|
2018-07-10 22:17:53 +00:00
|
|
|
"bytes"
|
2017-12-11 22:10:52 +00:00
|
|
|
"encoding/json"
|
2017-08-02 17:27:17 +00:00
|
|
|
"io"
|
2018-07-10 22:17:53 +00:00
|
|
|
"strings"
|
2017-08-02 17:27:17 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-08-20 23:29:54 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2018-06-20 18:08:07 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2017-08-02 17:27:17 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/apimachinery/pkg/util/clock"
|
|
|
|
core "k8s.io/client-go/testing"
|
|
|
|
|
|
|
|
"github.com/heptio/ark/pkg/apis/ark/v1"
|
2017-11-15 02:35:02 +00:00
|
|
|
"github.com/heptio/ark/pkg/backup"
|
2017-10-25 16:42:03 +00:00
|
|
|
"github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
|
2017-08-02 17:27:17 +00:00
|
|
|
informers "github.com/heptio/ark/pkg/generated/informers/externalversions"
|
2018-06-06 21:35:06 +00:00
|
|
|
"github.com/heptio/ark/pkg/metrics"
|
2018-08-20 23:29:54 +00:00
|
|
|
"github.com/heptio/ark/pkg/persistence"
|
|
|
|
persistencemocks "github.com/heptio/ark/pkg/persistence/mocks"
|
2018-05-13 13:28:09 +00:00
|
|
|
"github.com/heptio/ark/pkg/plugin"
|
|
|
|
pluginmocks "github.com/heptio/ark/pkg/plugin/mocks"
|
2017-12-11 22:10:52 +00:00
|
|
|
"github.com/heptio/ark/pkg/util/collections"
|
2018-05-13 13:28:09 +00:00
|
|
|
"github.com/heptio/ark/pkg/util/logging"
|
2017-12-11 22:10:52 +00:00
|
|
|
arktest "github.com/heptio/ark/pkg/util/test"
|
2017-08-02 17:27:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type fakeBackupper struct {
|
|
|
|
mock.Mock
|
|
|
|
}
|
|
|
|
|
2018-05-13 13:28:09 +00:00
|
|
|
func (b *fakeBackupper) Backup(logger logrus.FieldLogger, backup *v1.Backup, backupFile io.Writer, actions []backup.ItemAction) error {
|
|
|
|
args := b.Called(logger, backup, backupFile, actions)
|
2017-08-02 17:27:17 +00:00
|
|
|
return args.Error(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessBackup(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
key string
|
|
|
|
expectError bool
|
|
|
|
expectedIncludes []string
|
|
|
|
expectedExcludes []string
|
2017-12-11 22:10:52 +00:00
|
|
|
backup *arktest.TestBackup
|
2017-08-02 17:27:17 +00:00
|
|
|
expectBackup bool
|
2017-08-09 22:52:27 +00:00
|
|
|
allowSnapshots bool
|
2017-08-02 17:27:17 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "bad key",
|
|
|
|
key: "bad/key/here",
|
|
|
|
expectError: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "lister failed",
|
|
|
|
key: "heptio-ark/backup1",
|
|
|
|
expectError: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "do not process phase FailedValidation",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseFailedValidation),
|
2017-08-02 17:27:17 +00:00
|
|
|
expectBackup: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "do not process phase InProgress",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseInProgress),
|
2017-08-02 17:27:17 +00:00
|
|
|
expectBackup: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "do not process phase Completed",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseCompleted),
|
2017-08-02 17:27:17 +00:00
|
|
|
expectBackup: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "do not process phase Failed",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseFailed),
|
2017-08-02 17:27:17 +00:00
|
|
|
expectBackup: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "do not process phase other",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase("arg"),
|
2017-08-02 17:27:17 +00:00
|
|
|
expectBackup: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid included/excluded resources fails validation",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithIncludedResources("foo").WithExcludedResources("foo"),
|
2017-08-02 17:27:17 +00:00
|
|
|
expectBackup: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid included/excluded namespaces fails validation",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithIncludedNamespaces("foo").WithExcludedNamespaces("foo"),
|
2017-08-02 17:27:17 +00:00
|
|
|
expectBackup: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "make sure specified included and excluded resources are honored",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithIncludedResources("i", "j").WithExcludedResources("k", "l"),
|
2017-08-02 17:27:17 +00:00
|
|
|
expectedIncludes: []string{"i", "j"},
|
|
|
|
expectedExcludes: []string{"k", "l"},
|
|
|
|
expectBackup: true,
|
|
|
|
},
|
|
|
|
{
|
2017-10-02 20:53:08 +00:00
|
|
|
name: "if includednamespaces are specified, don't default to *",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithIncludedNamespaces("ns-1"),
|
2017-10-02 20:53:08 +00:00
|
|
|
expectBackup: true,
|
2017-08-02 17:27:17 +00:00
|
|
|
},
|
|
|
|
{
|
2017-10-02 20:53:08 +00:00
|
|
|
name: "ttl",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithTTL(10 * time.Minute),
|
2017-10-02 20:53:08 +00:00
|
|
|
expectBackup: true,
|
2017-08-02 17:27:17 +00:00
|
|
|
},
|
2017-08-09 22:52:27 +00:00
|
|
|
{
|
|
|
|
name: "backup with SnapshotVolumes when allowSnapshots=false fails validation",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithSnapshotVolumes(true),
|
2017-08-09 22:52:27 +00:00
|
|
|
expectBackup: false,
|
|
|
|
},
|
|
|
|
{
|
2017-10-02 20:53:08 +00:00
|
|
|
name: "backup with SnapshotVolumes when allowSnapshots=true gets executed",
|
|
|
|
key: "heptio-ark/backup1",
|
2017-12-11 22:10:52 +00:00
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithSnapshotVolumes(true),
|
2017-10-02 20:53:08 +00:00
|
|
|
allowSnapshots: true,
|
|
|
|
expectBackup: true,
|
2017-08-09 22:52:27 +00:00
|
|
|
},
|
2018-08-16 22:41:59 +00:00
|
|
|
{
|
|
|
|
name: "Backup without a location will have it set to the default",
|
|
|
|
key: "heptio-ark/backup1",
|
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew),
|
|
|
|
expectBackup: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Backup with a location completes",
|
|
|
|
key: "heptio-ark/backup1",
|
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithStorageLocation("loc1"),
|
|
|
|
expectBackup: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Backup with non-existent location will fail validation",
|
|
|
|
key: "heptio-ark/backup1",
|
|
|
|
backup: arktest.NewTestBackup().WithName("backup1").WithPhase(v1.BackupPhaseNew).WithStorageLocation("loc2"),
|
|
|
|
expectBackup: false,
|
|
|
|
},
|
2017-08-02 17:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2017-09-14 21:27:31 +00:00
|
|
|
var (
|
|
|
|
client = fake.NewSimpleClientset()
|
|
|
|
backupper = &fakeBackupper{}
|
|
|
|
sharedInformers = informers.NewSharedInformerFactory(client, 0)
|
2018-05-13 13:28:09 +00:00
|
|
|
logger = logging.DefaultLogger(logrus.DebugLevel)
|
2018-04-09 22:50:20 +00:00
|
|
|
clockTime, _ = time.Parse("Mon Jan 2 15:04:05 2006", "Mon Jan 2 15:04:05 2006")
|
2018-05-13 13:28:09 +00:00
|
|
|
pluginManager = &pluginmocks.Manager{}
|
2018-08-20 23:29:54 +00:00
|
|
|
backupStore = &persistencemocks.BackupStore{}
|
2017-09-14 21:27:31 +00:00
|
|
|
)
|
2018-05-13 13:28:09 +00:00
|
|
|
defer backupper.AssertExpectations(t)
|
|
|
|
defer pluginManager.AssertExpectations(t)
|
2018-08-20 23:29:54 +00:00
|
|
|
defer backupStore.AssertExpectations(t)
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
c := NewBackupController(
|
|
|
|
sharedInformers.Ark().V1().Backups(),
|
|
|
|
client.ArkV1(),
|
|
|
|
backupper,
|
2017-08-09 22:52:27 +00:00
|
|
|
test.allowSnapshots,
|
2017-09-14 21:27:31 +00:00
|
|
|
logger,
|
2018-05-13 13:28:09 +00:00
|
|
|
logrus.InfoLevel,
|
2018-08-25 19:53:56 +00:00
|
|
|
func(logrus.FieldLogger) plugin.Manager { return pluginManager },
|
2018-04-06 17:08:39 +00:00
|
|
|
NewBackupTracker(),
|
2018-08-16 22:41:59 +00:00
|
|
|
sharedInformers.Ark().V1().BackupStorageLocations(),
|
|
|
|
"default",
|
2018-06-06 21:35:06 +00:00
|
|
|
metrics.NewServerMetrics(),
|
2017-08-02 17:27:17 +00:00
|
|
|
).(*backupController)
|
2018-04-09 22:50:20 +00:00
|
|
|
|
|
|
|
c.clock = clock.NewFakeClock(clockTime)
|
2017-08-02 17:27:17 +00:00
|
|
|
|
2018-08-20 23:29:54 +00:00
|
|
|
c.newBackupStore = func(*v1.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error) {
|
|
|
|
return backupStore, nil
|
|
|
|
}
|
|
|
|
|
2018-06-20 18:08:07 +00:00
|
|
|
var expiration, startTime time.Time
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
if test.backup != nil {
|
|
|
|
// add directly to the informer's store so the lister can function and so we don't have to
|
|
|
|
// start the shared informers.
|
|
|
|
sharedInformers.Ark().V1().Backups().Informer().GetStore().Add(test.backup.Backup)
|
|
|
|
|
2018-06-20 18:08:07 +00:00
|
|
|
startTime = c.clock.Now()
|
|
|
|
|
2017-08-02 17:27:17 +00:00
|
|
|
if test.backup.Spec.TTL.Duration > 0 {
|
|
|
|
expiration = c.clock.Now().Add(test.backup.Spec.TTL.Duration)
|
|
|
|
}
|
2018-05-13 13:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if test.expectBackup {
|
2017-08-02 17:27:17 +00:00
|
|
|
// set up a Backup object to represent what we expect to be passed to backupper.Backup()
|
2017-12-11 22:10:52 +00:00
|
|
|
backup := test.backup.DeepCopy()
|
2017-08-02 17:27:17 +00:00
|
|
|
backup.Spec.IncludedResources = test.expectedIncludes
|
|
|
|
backup.Spec.ExcludedResources = test.expectedExcludes
|
2017-10-02 20:53:08 +00:00
|
|
|
backup.Spec.IncludedNamespaces = test.backup.Spec.IncludedNamespaces
|
2017-08-09 22:52:27 +00:00
|
|
|
backup.Spec.SnapshotVolumes = test.backup.Spec.SnapshotVolumes
|
2017-08-02 17:27:17 +00:00
|
|
|
backup.Status.Phase = v1.BackupPhaseInProgress
|
|
|
|
backup.Status.Expiration.Time = expiration
|
2018-06-20 18:08:07 +00:00
|
|
|
backup.Status.StartTimestamp.Time = startTime
|
2017-08-02 17:27:17 +00:00
|
|
|
backup.Status.Version = 1
|
2018-05-13 13:28:09 +00:00
|
|
|
backupper.On("Backup",
|
|
|
|
mock.Anything, // logger
|
|
|
|
backup,
|
|
|
|
mock.Anything, // backup file
|
|
|
|
mock.Anything, // actions
|
|
|
|
).Return(nil)
|
|
|
|
|
2018-08-16 22:41:59 +00:00
|
|
|
defaultLocation := &v1.BackupStorageLocation{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Namespace: backup.Namespace,
|
|
|
|
Name: "default",
|
|
|
|
},
|
|
|
|
Spec: v1.BackupStorageLocationSpec{
|
|
|
|
Provider: "myCloud",
|
|
|
|
StorageType: v1.StorageType{
|
|
|
|
ObjectStorage: &v1.ObjectStorageLocation{
|
|
|
|
Bucket: "bucket",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
loc1 := &v1.BackupStorageLocation{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Namespace: backup.Namespace,
|
|
|
|
Name: "loc1",
|
|
|
|
},
|
|
|
|
Spec: v1.BackupStorageLocationSpec{
|
|
|
|
Provider: "myCloud",
|
|
|
|
StorageType: v1.StorageType{
|
|
|
|
ObjectStorage: &v1.ObjectStorageLocation{
|
|
|
|
Bucket: "bucket",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.NoError(t, sharedInformers.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(defaultLocation))
|
|
|
|
require.NoError(t, sharedInformers.Ark().V1().BackupStorageLocations().Informer().GetStore().Add(loc1))
|
|
|
|
|
2018-05-13 13:28:09 +00:00
|
|
|
pluginManager.On("GetBackupItemActions").Return(nil, nil)
|
2017-08-02 17:27:17 +00:00
|
|
|
|
2018-07-10 22:17:53 +00:00
|
|
|
// Ensure we have a CompletionTimestamp when uploading.
|
|
|
|
// Failures will display the bytes in buf.
|
|
|
|
completionTimestampIsPresent := func(buf *bytes.Buffer) bool {
|
|
|
|
json := buf.String()
|
|
|
|
timeString := `"completionTimestamp": "2006-01-02T15:04:05Z"`
|
|
|
|
|
|
|
|
return strings.Contains(json, timeString)
|
|
|
|
}
|
2018-08-20 23:29:54 +00:00
|
|
|
backupStore.On("PutBackup", test.backup.Name, mock.MatchedBy(completionTimestampIsPresent), mock.Anything, mock.Anything).Return(nil)
|
|
|
|
pluginManager.On("CleanupClients").Return()
|
2017-08-02 17:27:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 22:10:52 +00:00
|
|
|
// this is necessary so the Patch() call returns the appropriate object
|
|
|
|
client.PrependReactor("patch", "backups", func(action core.Action) (bool, runtime.Object, error) {
|
|
|
|
if test.backup == nil {
|
|
|
|
return true, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
patch := action.(core.PatchAction).GetPatch()
|
|
|
|
patchMap := make(map[string]interface{})
|
|
|
|
|
|
|
|
if err := json.Unmarshal(patch, &patchMap); err != nil {
|
|
|
|
t.Logf("error unmarshalling patch: %s\n", err)
|
|
|
|
return false, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
phase, err := collections.GetString(patchMap, "status.phase")
|
2017-08-02 17:27:17 +00:00
|
|
|
if err != nil {
|
2017-12-11 22:10:52 +00:00
|
|
|
t.Logf("error getting status.phase: %s\n", err)
|
2017-08-02 17:27:17 +00:00
|
|
|
return false, nil, err
|
|
|
|
}
|
2017-12-11 22:10:52 +00:00
|
|
|
|
|
|
|
res := test.backup.DeepCopy()
|
|
|
|
|
|
|
|
// these are the fields that we expect to be set by
|
|
|
|
// the controller
|
|
|
|
res.Status.Version = 1
|
|
|
|
res.Status.Expiration.Time = expiration
|
|
|
|
res.Status.Phase = v1.BackupPhase(phase)
|
|
|
|
|
2018-06-20 18:08:07 +00:00
|
|
|
// If there's an error, it's mostly likely that the key wasn't found
|
|
|
|
// which is fine since not all patches will have them.
|
|
|
|
completionString, err := collections.GetString(patchMap, "status.completionTimestamp")
|
|
|
|
if err == nil {
|
|
|
|
completionTime, err := time.Parse(time.RFC3339Nano, completionString)
|
|
|
|
require.NoError(t, err, "unexpected completionTimestamp parsing error %v", err)
|
|
|
|
res.Status.CompletionTimestamp.Time = completionTime
|
|
|
|
}
|
|
|
|
startString, err := collections.GetString(patchMap, "status.startTimestamp")
|
|
|
|
if err == nil {
|
|
|
|
startTime, err := time.Parse(time.RFC3339Nano, startString)
|
|
|
|
require.NoError(t, err, "unexpected startTimestamp parsing error %v", err)
|
|
|
|
res.Status.StartTimestamp.Time = startTime
|
|
|
|
}
|
|
|
|
|
2017-12-11 22:10:52 +00:00
|
|
|
return true, res, nil
|
2017-08-02 17:27:17 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// method under test
|
|
|
|
err := c.processBackup(test.key)
|
|
|
|
|
|
|
|
if test.expectError {
|
|
|
|
require.Error(t, err, "processBackup should error")
|
|
|
|
return
|
|
|
|
}
|
2017-08-07 15:20:38 +00:00
|
|
|
require.NoError(t, err, "processBackup unexpected error: %v", err)
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
if !test.expectBackup {
|
2018-05-13 13:28:09 +00:00
|
|
|
// the AssertExpectations calls above make sure we aren't running anything we shouldn't be
|
2017-08-02 17:27:17 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-12-11 22:10:52 +00:00
|
|
|
actions := client.Actions()
|
|
|
|
require.Equal(t, 2, len(actions))
|
|
|
|
|
2018-04-09 22:50:20 +00:00
|
|
|
// structs and func for decoding patch content
|
|
|
|
type StatusPatch struct {
|
2018-06-20 18:08:07 +00:00
|
|
|
Expiration time.Time `json:"expiration"`
|
|
|
|
Version int `json:"version"`
|
|
|
|
Phase v1.BackupPhase `json:"phase"`
|
|
|
|
StartTimestamp metav1.Time `json:"startTimestamp"`
|
|
|
|
CompletionTimestamp metav1.Time `json:"completionTimestamp"`
|
2018-04-09 22:50:20 +00:00
|
|
|
}
|
2018-08-16 22:41:59 +00:00
|
|
|
type SpecPatch struct {
|
|
|
|
StorageLocation string `json:"storageLocation"`
|
|
|
|
}
|
2018-08-21 23:52:49 +00:00
|
|
|
type ObjectMetaPatch struct {
|
|
|
|
Labels map[string]string `json:"labels"`
|
|
|
|
}
|
2017-12-11 22:10:52 +00:00
|
|
|
|
2018-04-09 22:50:20 +00:00
|
|
|
type Patch struct {
|
2018-08-21 23:52:49 +00:00
|
|
|
Status StatusPatch `json:"status"`
|
|
|
|
Spec SpecPatch `json:"spec,omitempty"`
|
|
|
|
ObjectMeta ObjectMetaPatch `json:"metadata,omitempty"`
|
2018-04-09 22:50:20 +00:00
|
|
|
}
|
2017-12-11 22:10:52 +00:00
|
|
|
|
2018-04-09 22:50:20 +00:00
|
|
|
decode := func(decoder *json.Decoder) (interface{}, error) {
|
|
|
|
actual := new(Patch)
|
|
|
|
err := decoder.Decode(actual)
|
2017-12-11 22:10:52 +00:00
|
|
|
|
2018-04-09 22:50:20 +00:00
|
|
|
return *actual, err
|
2017-08-02 17:27:17 +00:00
|
|
|
}
|
|
|
|
|
2018-08-16 22:41:59 +00:00
|
|
|
// validate Patch call 1 (setting version, expiration, phase, and storage location)
|
|
|
|
var expected Patch
|
|
|
|
if test.backup.Spec.StorageLocation == "" {
|
|
|
|
expected = Patch{
|
|
|
|
Status: StatusPatch{
|
|
|
|
Version: 1,
|
|
|
|
Phase: v1.BackupPhaseInProgress,
|
|
|
|
Expiration: expiration,
|
|
|
|
},
|
|
|
|
Spec: SpecPatch{
|
|
|
|
StorageLocation: "default",
|
|
|
|
},
|
2018-08-21 23:52:49 +00:00
|
|
|
ObjectMeta: ObjectMetaPatch{
|
|
|
|
Labels: map[string]string{
|
|
|
|
v1.StorageLocationLabel: "default",
|
|
|
|
},
|
|
|
|
},
|
2018-08-16 22:41:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
expected = Patch{
|
|
|
|
Status: StatusPatch{
|
|
|
|
Version: 1,
|
|
|
|
Phase: v1.BackupPhaseInProgress,
|
|
|
|
Expiration: expiration,
|
|
|
|
},
|
2018-08-21 23:52:49 +00:00
|
|
|
ObjectMeta: ObjectMetaPatch{
|
|
|
|
Labels: map[string]string{
|
|
|
|
v1.StorageLocationLabel: test.backup.Spec.StorageLocation,
|
|
|
|
},
|
|
|
|
},
|
2018-08-16 22:41:59 +00:00
|
|
|
}
|
2018-04-09 22:50:20 +00:00
|
|
|
}
|
2017-12-11 22:10:52 +00:00
|
|
|
|
2018-04-09 22:50:20 +00:00
|
|
|
arktest.ValidatePatch(t, actions[0], expected, decode)
|
2017-12-11 22:10:52 +00:00
|
|
|
|
2018-06-20 18:08:07 +00:00
|
|
|
// validate Patch call 2 (setting phase, startTimestamp, completionTimestamp)
|
2018-04-09 22:50:20 +00:00
|
|
|
expected = Patch{
|
|
|
|
Status: StatusPatch{
|
2018-06-20 18:08:07 +00:00
|
|
|
Phase: v1.BackupPhaseCompleted,
|
|
|
|
StartTimestamp: metav1.Time{Time: c.clock.Now()},
|
|
|
|
CompletionTimestamp: metav1.Time{Time: c.clock.Now()},
|
2018-04-09 22:50:20 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
arktest.ValidatePatch(t, actions[1], expected, decode)
|
2017-08-02 17:27:17 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|