mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 13:55:20 +00:00
* k8s 1.18 import wip backup, cmd, controller, generated, restic, restore, serverstatusrequest, test and util Signed-off-by: Andrew Lavery <laverya@umich.edu> * go mod tidy Signed-off-by: Andrew Lavery <laverya@umich.edu> * add changelog file Signed-off-by: Andrew Lavery <laverya@umich.edu> * go fmt Signed-off-by: Andrew Lavery <laverya@umich.edu> * update code-generator and controller-gen in CI Signed-off-by: Andrew Lavery <laverya@umich.edu> * checkout proper code-generator version, regen Signed-off-by: Andrew Lavery <laverya@umich.edu> * fix remaining calls Signed-off-by: Andrew Lavery <laverya@umich.edu> * regenerate CRDs with ./hack/update-generated-crd-code.sh Signed-off-by: Andrew Lavery <laverya@umich.edu> * use existing context in restic and server Signed-off-by: Andrew Lavery <laverya@umich.edu> * fix test cases by resetting resource version also use main library go context, not golang.org/x/net/context, in pkg/restore/restore.go Signed-off-by: Andrew Lavery <laverya@umich.edu> * clarify changelog message Signed-off-by: Andrew Lavery <laverya@umich.edu> * use github.com/kubernetes-csi/external-snapshotter/v2@v2.2.0-rc1 Signed-off-by: Andrew Lavery <laverya@umich.edu> * run 'go mod tidy' to remove old external-snapshotter version Signed-off-by: Andrew Lavery <laverya@umich.edu>
90 lines
2.8 KiB
Go
90 lines
2.8 KiB
Go
/*
|
|
Copyright 2019 the Velero 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 backup
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
|
"github.com/vmware-tanzu/velero/pkg/builder"
|
|
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/fake"
|
|
)
|
|
|
|
const testNamespace = "velero"
|
|
|
|
func TestCreateOptions_BuildBackup(t *testing.T) {
|
|
o := NewCreateOptions()
|
|
o.Labels.Set("velero.io/test=true")
|
|
|
|
backup, err := o.BuildBackup(testNamespace)
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, velerov1api.BackupSpec{
|
|
TTL: metav1.Duration{Duration: o.TTL},
|
|
IncludedNamespaces: []string(o.IncludeNamespaces),
|
|
SnapshotVolumes: o.SnapshotVolumes.Value,
|
|
IncludeClusterResources: o.IncludeClusterResources.Value,
|
|
}, backup.Spec)
|
|
|
|
assert.Equal(t, map[string]string{
|
|
"velero.io/test": "true",
|
|
}, backup.GetLabels())
|
|
}
|
|
|
|
func TestCreateOptions_BuildBackupFromSchedule(t *testing.T) {
|
|
o := NewCreateOptions()
|
|
o.FromSchedule = "test"
|
|
o.client = fake.NewSimpleClientset()
|
|
|
|
t.Run("inexistant schedule", func(t *testing.T) {
|
|
_, err := o.BuildBackup(testNamespace)
|
|
assert.Error(t, err)
|
|
})
|
|
|
|
expectedBackupSpec := builder.ForBackup("test", testNamespace).IncludedNamespaces("test").Result().Spec
|
|
schedule := builder.ForSchedule(testNamespace, "test").Template(expectedBackupSpec).ObjectMeta(builder.WithLabels("velero.io/test", "true")).Result()
|
|
o.client.VeleroV1().Schedules(testNamespace).Create(context.TODO(), schedule, metav1.CreateOptions{})
|
|
|
|
t.Run("existing schedule", func(t *testing.T) {
|
|
backup, err := o.BuildBackup(testNamespace)
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expectedBackupSpec, backup.Spec)
|
|
assert.Equal(t, map[string]string{
|
|
"velero.io/test": "true",
|
|
velerov1api.ScheduleNameLabel: "test",
|
|
}, backup.GetLabels())
|
|
})
|
|
|
|
t.Run("command line labels take precedence over schedule labels", func(t *testing.T) {
|
|
o.Labels.Set("velero.io/test=yes,custom-label=true")
|
|
backup, err := o.BuildBackup(testNamespace)
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expectedBackupSpec, backup.Spec)
|
|
assert.Equal(t, map[string]string{
|
|
"velero.io/test": "yes",
|
|
velerov1api.ScheduleNameLabel: "test",
|
|
"custom-label": "true",
|
|
}, backup.GetLabels())
|
|
})
|
|
}
|