feat: support configure BSL CR to indicate which one is the default (#3092)

* Add default field to BSL CRD

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add a new flag `--default` under `velero backup-location create`

add a new flag `--default` under `velero backup-location create`
to specify this new location to be the new default BSL.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add a new default field under `velero backup-location get`

add a new default field under `velero backup-location get` to indicate
which BSL is the default one.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add a new sub-command and flag under `velero backup-location`

Add a new sub-command called `velero backup-location set` sub-command
and a new flag `velero backup-cation set --default` to configure which
BSL is the default one.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add new flag to get the default backup-location

Add a new flag `--default` under `velero backup-location get`
to displays the current default BSL.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Configures default BSL in BSL controller

When upgrade the BSL CRDs, none of the BSL has been labeled as default.
Sets the BSL default field to true if the BSL name matches to the default BSL setting.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Configures the default BSL in BSL controller for velero upgrade

When upgrade the BSL CRDs, none of the BSL be marked as the default.
Sets the BSL `.spec.default: true` if the BSL name matches against the
`velero server --default-backup-storage-location`.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add unit test to test default BSL behavior

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Update check which one is the default BSL in backup/backup_sync/restore controller

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add changelog

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Update docs locations.md and upgrade-to-1.6.md

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>
pull/3166/head
JenTing Hsiao 2020-12-09 05:38:29 +08:00 committed by GitHub
parent 5eb64eb84b
commit 9dd158d13d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 440 additions and 64 deletions

View File

@ -0,0 +1 @@
feat: support configures BackupStorageLocation custom resources to indicate which one is the default

View File

@ -33,6 +33,10 @@ spec:
- JSONPath: .metadata.creationTimestamp
name: Age
type: date
- JSONPath: .spec.default
description: Default backup storage location
name: Default
type: boolean
group: velero.io
names:
kind: BackupStorageLocation
@ -83,6 +87,10 @@ spec:
type: string
description: Config is for provider-specific configuration fields.
type: object
default:
description: Default indicates this location is the default backup storage
location.
type: boolean
objectStorage:
description: ObjectStorageLocation specifies the settings necessary
to connect to a provider's object storage.

File diff suppressed because one or more lines are too long

View File

@ -32,6 +32,10 @@ type BackupStorageLocationSpec struct {
StorageType `json:",inline"`
// Default indicates this location is the default backup storage location.
// +optional
Default bool `json:"default,omitempty"`
// AccessMode defines the permissions for the backup storage location.
// +optional
AccessMode BackupStorageLocationAccessMode `json:"accessMode,omitempty"`
@ -96,6 +100,7 @@ type BackupStorageLocationStatus struct {
// +kubebuilder:printcolumn:name="Last Validated",type="date",JSONPath=".status.lastValidationTime",description="LastValidationTime is the last time the backup store location was validated"
// +kubebuilder:printcolumn:name="Access Mode",type="string",JSONPath=".spec.accessMode",description="Permissions for the backup storage location"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Default",type="boolean",JSONPath=".spec.default",description="Default backup storage location"
// BackupStorageLocation is a location where Velero stores backup objects
type BackupStorageLocation struct {

View File

@ -1,5 +1,5 @@
/*
Copyright 2017, 2019 the Velero contributors.
Copyright 2020 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.
@ -83,6 +83,12 @@ func (b *BackupStorageLocationBuilder) Prefix(val string) *BackupStorageLocation
return b
}
// Default sets the BackupStorageLocation's is default or not
func (b *BackupStorageLocationBuilder) Default(isDefault bool) *BackupStorageLocationBuilder {
b.object.Spec.Default = isDefault
return b
}
// AccessMode sets the BackupStorageLocation's access mode.
func (b *BackupStorageLocationBuilder) AccessMode(accessMode velerov1api.BackupStorageLocationAccessMode) *BackupStorageLocationBuilder {
b.object.Spec.AccessMode = accessMode

View File

@ -33,6 +33,7 @@ func NewCommand(f client.Factory) *cobra.Command {
NewCreateCommand(f, "create"),
NewDeleteCommand(f, "delete"),
NewGetCommand(f, "get"),
NewSetCommand(f, "set"),
)
return c

View File

@ -63,6 +63,7 @@ type CreateOptions struct {
Name string
Provider string
Bucket string
DefaultBackupStorageLocation bool
Prefix string
BackupSyncPeriod, ValidationFrequency time.Duration
Config flag.Map
@ -85,6 +86,7 @@ func NewCreateOptions() *CreateOptions {
func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) {
flags.StringVar(&o.Provider, "provider", o.Provider, "Name of the backup storage provider (e.g. aws, azure, gcp).")
flags.StringVar(&o.Bucket, "bucket", o.Bucket, "Name of the object storage bucket where backups should be stored.")
flags.BoolVar(&o.DefaultBackupStorageLocation, "default", o.DefaultBackupStorageLocation, "Sets this new location to be the new default backup storage location. Optional.")
flags.StringVar(&o.Prefix, "prefix", o.Prefix, "Prefix under which all Velero data should be stored within the bucket. Optional.")
flags.DurationVar(&o.BackupSyncPeriod, "backup-sync-period", o.BackupSyncPeriod, "How often to ensure all Velero backups in object storage exist as Backup API objects in the cluster. Optional. Set this to `0s` to disable sync. Default: 1 minute.")
flags.DurationVar(&o.ValidationFrequency, "validation-frequency", o.ValidationFrequency, "How often to verify if the backup storage location is valid. Optional. Set this to `0s` to disable sync. Default 1 minute.")
@ -162,6 +164,7 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error {
},
},
Config: o.Config.Data(),
Default: o.DefaultBackupStorageLocation,
AccessMode: velerov1api.BackupStorageLocationAccessMode(o.AccessMode.String()),
BackupSyncPeriod: backupSyncPeriod,
ValidationFrequency: validationFrequency,
@ -177,6 +180,25 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error {
return err
}
if o.DefaultBackupStorageLocation {
// There is one and only one default backup storage location.
// Disable the origin default backup storage location.
locations := new(velerov1api.BackupStorageLocationList)
if err := kbClient.List(context.Background(), locations, &kbclient.ListOptions{Namespace: f.Namespace()}); err != nil {
return errors.WithStack(err)
}
for _, location := range locations.Items {
if !location.Spec.Default {
continue
}
location.Spec.Default = false
if err := kbClient.Update(context.Background(), &location, &kbclient.UpdateOptions{}); err != nil {
return errors.WithStack(err)
}
break
}
}
if err := kbClient.Create(context.Background(), backupStorageLocation, &kbclient.CreateOptions{}); err != nil {
return errors.WithStack(err)
}

View File

@ -32,6 +32,7 @@ import (
func NewGetCommand(f client.Factory, use string) *cobra.Command {
var listOptions metav1.ListOptions
var showDefaultOnly bool
c := &cobra.Command{
Use: use,
@ -45,14 +46,21 @@ func NewGetCommand(f client.Factory, use string) *cobra.Command {
locations := new(velerov1api.BackupStorageLocationList)
if len(args) > 0 {
location := &velerov1api.BackupStorageLocation{}
for _, name := range args {
location := &velerov1api.BackupStorageLocation{}
err = kbClient.Get(context.Background(), kbclient.ObjectKey{
Namespace: f.Namespace(),
Name: name,
}, location)
cmd.CheckError(err)
locations.Items = append(locations.Items, *location)
if showDefaultOnly {
if location.Spec.Default {
locations.Items = append(locations.Items, *location)
}
} else {
locations.Items = append(locations.Items, *location)
}
}
} else {
err := kbClient.List(context.Background(), locations, &kbclient.ListOptions{
@ -60,6 +68,19 @@ func NewGetCommand(f client.Factory, use string) *cobra.Command {
Raw: &listOptions,
})
cmd.CheckError(err)
if showDefaultOnly {
for i := 0; i < len(locations.Items); i++ {
if locations.Items[i].Spec.Default {
continue
}
if i != len(locations.Items)-1 {
copy(locations.Items[i:], locations.Items[i+1:])
i = i - 1
}
locations.Items = locations.Items[:len(locations.Items)-1]
}
}
}
_, err = output.PrintWithFormat(c, locations)
@ -67,6 +88,7 @@ func NewGetCommand(f client.Factory, use string) *cobra.Command {
},
}
c.Flags().BoolVar(&showDefaultOnly, "default", false, "Displays the current default backup storage location.")
c.Flags().StringVarP(&listOptions.LabelSelector, "selector", "l", listOptions.LabelSelector, "Only show items matching this label selector.")
output.BindFlags(c.Flags())

View File

@ -0,0 +1,115 @@
/*
Copyright 2020 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 backuplocation
import (
"context"
"fmt"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
kbclient "sigs.k8s.io/controller-runtime/pkg/client"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/client"
"github.com/vmware-tanzu/velero/pkg/cmd"
)
func NewSetCommand(f client.Factory, use string) *cobra.Command {
o := NewSetOptions()
c := &cobra.Command{
Use: use + " NAME",
Short: "Set a backup storage location",
Args: cobra.ExactArgs(1),
Run: func(c *cobra.Command, args []string) {
cmd.CheckError(o.Complete(args, f))
cmd.CheckError(o.Run(c, f))
},
}
o.BindFlags(c.Flags())
return c
}
type SetOptions struct {
Name string
DefaultBackupStorageLocation bool
}
func NewSetOptions() *SetOptions {
return &SetOptions{}
}
func (o *SetOptions) BindFlags(flags *pflag.FlagSet) {
flags.BoolVar(&o.DefaultBackupStorageLocation, "default", o.DefaultBackupStorageLocation, "Sets this new location to be the new default backup storage location. Optional.")
}
func (o *SetOptions) Complete(args []string, f client.Factory) error {
o.Name = args[0]
return nil
}
func (o *SetOptions) Run(c *cobra.Command, f client.Factory) error {
kbClient, err := f.KubebuilderClient()
if err != nil {
return err
}
location := &velerov1api.BackupStorageLocation{}
err = kbClient.Get(context.Background(), kbclient.ObjectKey{
Namespace: f.Namespace(),
Name: o.Name,
}, location)
if err != nil {
return errors.WithStack(err)
}
if o.DefaultBackupStorageLocation {
// There is one and only one default backup storage location.
// Disable the origin default backup storage location.
locations := new(velerov1api.BackupStorageLocationList)
if err := kbClient.List(context.Background(), locations, &kbclient.ListOptions{Namespace: f.Namespace()}); err != nil {
return errors.WithStack(err)
}
for _, location := range locations.Items {
if !location.Spec.Default {
continue
}
if location.Name == o.Name {
// Do not update if the origin default BSL is the current one.
break
}
location.Spec.Default = false
if err := kbClient.Update(context.Background(), &location, &kbclient.UpdateOptions{}); err != nil {
return errors.WithStack(err)
}
break
}
}
location.Spec.Default = o.DefaultBackupStorageLocation
if err := kbClient.Update(context.Background(), location, &kbclient.UpdateOptions{}); err != nil {
return errors.WithStack(err)
}
fmt.Printf("Backup storage location %q configured successfully.\n", o.Name)
return nil
}

View File

@ -195,7 +195,7 @@ func NewCommand(f client.Factory) *cobra.Command {
command.Flags().BoolVar(&config.restoreOnly, "restore-only", config.restoreOnly, "Run in a mode where only restores are allowed; backups, schedules, and garbage-collection are all disabled. DEPRECATED: this flag will be removed in v2.0. Use read-only backup storage locations instead.")
command.Flags().StringSliceVar(&config.disabledControllers, "disable-controllers", config.disabledControllers, fmt.Sprintf("List of controllers to disable on startup. Valid values are %s", strings.Join(controller.DisableableControllers, ",")))
command.Flags().StringSliceVar(&config.restoreResourcePriorities, "restore-resource-priorities", config.restoreResourcePriorities, "Desired order of resource restores; any resource not in the list will be restored alphabetically after the prioritized resources.")
command.Flags().StringVar(&config.defaultBackupLocation, "default-backup-storage-location", config.defaultBackupLocation, "Name of the default backup storage location.")
command.Flags().StringVar(&config.defaultBackupLocation, "default-backup-storage-location", config.defaultBackupLocation, "Name of the default backup storage location. DEPRECATED: this flag will be removed in v2.0. Use \"velero backup-location set --default\" instead.")
command.Flags().DurationVar(&config.storeValidationFrequency, "store-validation-frequency", config.storeValidationFrequency, "How often to verify if the storage is valid. Optional. Set this to `0s` to disable sync. Default 1 minute.")
command.Flags().Var(&volumeSnapshotLocations, "default-volume-snapshot-locations", "List of unique volume providers and default volume snapshot location (provider1:location-01,provider2:location-02,...)")
command.Flags().Float32Var(&config.clientQPS, "client-qps", config.clientQPS, "Maximum number of requests per second by the server to the Kubernetes API once the burst limit has been reached.")
@ -713,7 +713,6 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
s.logger,
s.logLevel,
newPluginManager,
s.config.defaultBackupLocation,
s.metrics,
s.config.formatFlag.Parse(),
)

View File

@ -33,6 +33,7 @@ var (
{Name: "Phase"},
{Name: "Last Validated"},
{Name: "Access Mode"},
{Name: "Default"},
}
)
@ -50,6 +51,11 @@ func printBackupStorageLocation(location *velerov1api.BackupStorageLocation) []m
Object: runtime.RawExtension{Object: location},
}
isDefault := ""
if location.Spec.Default {
isDefault = "true"
}
bucketAndPrefix := location.Spec.ObjectStorage.Bucket
if location.Spec.ObjectStorage.Prefix != "" {
bucketAndPrefix += "/" + location.Spec.ObjectStorage.Prefix
@ -78,6 +84,7 @@ func printBackupStorageLocation(location *velerov1api.BackupStorageLocation) []m
status,
LastValidatedStr,
accessMode,
isDefault,
)
return []metav1.TableRow{row}

View File

@ -41,6 +41,7 @@ import (
snapshotv1beta1api "github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"
snapshotv1beta1listers "github.com/kubernetes-csi/external-snapshotter/v2/pkg/client/listers/volumesnapshot/v1beta1"
"github.com/vmware-tanzu/velero/internal/storage"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
pkgbackup "github.com/vmware-tanzu/velero/pkg/backup"
"github.com/vmware-tanzu/velero/pkg/discovery"
@ -345,6 +346,16 @@ func (c *backupController) prepareBackupRequest(backup *velerov1api.Backup) *pkg
// default storage location if not specified
if request.Spec.StorageLocation == "" {
request.Spec.StorageLocation = c.defaultBackupLocation
locationList, err := storage.ListBackupStorageLocations(context.Background(), c.kbClient, request.Namespace)
if err == nil {
for _, location := range locationList.Items {
if location.Spec.Default {
request.Spec.StorageLocation = location.Name
break
}
}
}
}
if request.Spec.DefaultVolumesToRestic == nil {

View File

@ -336,7 +336,7 @@ func TestDefaultBackupTTL(t *testing.T) {
}
func TestProcessBackupCompletions(t *testing.T) {
defaultBackupLocation := builder.ForBackupStorageLocation("velero", "loc-1").Bucket("store-1").Result()
defaultBackupLocation := builder.ForBackupStorageLocation("velero", "loc-1").Default(true).Bucket("store-1").Result()
now, err := time.Parse(time.RFC1123Z, time.RFC1123Z)
require.NoError(t, err)

View File

@ -67,13 +67,25 @@ func (r *BackupStorageLocationReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
defer pluginManager.CleanupClients()
var defaultFound bool
for _, location := range locationList.Items {
if location.Spec.Default {
defaultFound = true
break
}
}
var unavailableErrors []string
var anyVerified bool
for i := range locationList.Items {
location := &locationList.Items[i]
isDefault := location.Spec.Default
log := r.Log.WithField("controller", BackupStorageLocation).WithField(BackupStorageLocation, location.Name)
if location.Name == r.DefaultBackupLocationInfo.StorageLocation {
if !defaultFound && location.Name == r.DefaultBackupLocationInfo.StorageLocation {
// For backward-compatible, to configure the backup storage location as the default if
// none of the BSLs be marked as the default and the BSL name matches against the
// "velero server --default-backup-storage-location".
isDefault = true
defaultFound = true
}
@ -95,29 +107,28 @@ func (r *BackupStorageLocationReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
continue
}
// updates the default backup location
location.Spec.Default = isDefault
log.Info("Validating backup storage location")
anyVerified = true
if err := backupStore.IsValid(); err != nil {
log.Info("Backup location is invalid, marking as unavailable")
unavailableErrors = append(unavailableErrors, errors.Wrapf(err, "Backup location %q is unavailable", location.Name).Error())
if location.Name == r.DefaultBackupLocationInfo.StorageLocation {
log.Warnf("The specified default backup location named %q is unavailable; for convenience, be sure to configure it properly or make another backup location that is available the default", r.DefaultBackupLocationInfo.StorageLocation)
}
log.Info("Backup storage location is invalid, marking as unavailable")
unavailableErrors = append(unavailableErrors, errors.Wrapf(err, "Backup storage location %q is unavailable", location.Name).Error())
location.Status.Phase = velerov1api.BackupStorageLocationPhaseUnavailable
} else {
log.Info("Backup location valid, marking as available")
log.Info("Backup storage location valid, marking as available")
location.Status.Phase = velerov1api.BackupStorageLocationPhaseAvailable
}
location.Status.LastValidationTime = &metav1.Time{Time: time.Now().UTC()}
if err := patchHelper.Patch(r.Ctx, location); err != nil {
log.WithError(err).Error("Error updating backup location phase")
log.WithError(err).Error("Error updating backup storage location phase")
}
}
if !anyVerified {
log.Debug("No backup locations needed to be validated")
log.Debug("No backup storage locations needed to be validated")
}
r.logReconciledPhase(defaultFound, locationList, unavailableErrors)
@ -154,11 +165,11 @@ func (r *BackupStorageLocationReconciler) logReconciledPhase(defaultFound bool,
log.Errorf("Current backup storage locations available/unavailable/unknown: %v/%v/%v)", numAvailable, numUnavailable, numUnknown)
}
} else if numUnavailable > 0 { // some but not all BSL unavailable
log.Warnf("Invalid backup locations detected: available/unavailable/unknown: %v/%v/%v, %s)", numAvailable, numUnavailable, numUnknown, strings.Join(errs, "; "))
log.Warnf("Invalid backup storage locations detected: available/unavailable/unknown: %v/%v/%v, %s)", numAvailable, numUnavailable, numUnknown, strings.Join(errs, "; "))
}
if !defaultFound {
log.Warnf("The specified default backup location named %q was not found; for convenience, be sure to create one or make another backup location that is available the default", r.DefaultBackupLocationInfo.StorageLocation)
log.Warn("The default backup storage location was not found; for convenience, be sure to create one or make another backup location that is designated as the default")
}
}

View File

@ -46,19 +46,91 @@ var _ = Describe("Backup Storage Location Reconciler", func() {
It("Should successfully patch a backup storage location object status phase according to whether its storage is valid or not", func() {
tests := []struct {
backupLocation *velerov1api.BackupStorageLocation
isValidError error
expectedPhase velerov1api.BackupStorageLocationPhase
backupLocation *velerov1api.BackupStorageLocation
isValidError error
expectedIsDefault bool
expectedPhase velerov1api.BackupStorageLocationPhase
}{
{
backupLocation: builder.ForBackupStorageLocation("ns-1", "location-1").ValidationFrequency(1 * time.Second).Result(),
isValidError: nil,
expectedPhase: velerov1api.BackupStorageLocationPhaseAvailable,
backupLocation: builder.ForBackupStorageLocation("ns-1", "location-1").ValidationFrequency(1 * time.Second).Result(),
isValidError: nil,
expectedIsDefault: true,
expectedPhase: velerov1api.BackupStorageLocationPhaseAvailable,
},
{
backupLocation: builder.ForBackupStorageLocation("ns-1", "location-2").ValidationFrequency(1 * time.Second).Result(),
isValidError: errors.New("an error"),
expectedPhase: velerov1api.BackupStorageLocationPhaseUnavailable,
backupLocation: builder.ForBackupStorageLocation("ns-1", "location-2").ValidationFrequency(1 * time.Second).Result(),
isValidError: errors.New("an error"),
expectedIsDefault: false,
expectedPhase: velerov1api.BackupStorageLocationPhaseUnavailable,
},
}
// Setup
var (
pluginManager = &pluginmocks.Manager{}
backupStores = make(map[string]*persistencemocks.BackupStore)
)
pluginManager.On("CleanupClients").Return(nil)
locations := new(velerov1api.BackupStorageLocationList)
for i, test := range tests {
location := test.backupLocation
locations.Items = append(locations.Items, *location)
backupStores[location.Name] = &persistencemocks.BackupStore{}
backupStore := backupStores[location.Name]
backupStore.On("IsValid").Return(tests[i].isValidError)
}
// Setup reconciler
Expect(velerov1api.AddToScheme(scheme.Scheme)).To(Succeed())
r := BackupStorageLocationReconciler{
Ctx: ctx,
Client: fake.NewFakeClientWithScheme(scheme.Scheme, locations),
DefaultBackupLocationInfo: storage.DefaultBackupLocationInfo{
StorageLocation: "location-1",
StoreValidationFrequency: 0,
},
NewPluginManager: func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
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
},
Log: velerotest.NewLogger(),
}
actualResult, err := r.Reconcile(ctrl.Request{
NamespacedName: types.NamespacedName{Namespace: "ns-1"},
})
Expect(actualResult).To(BeEquivalentTo(ctrl.Result{Requeue: true}))
Expect(err).To(BeNil())
// Assertions
for i, location := range locations.Items {
key := client.ObjectKey{Name: location.Name, Namespace: location.Namespace}
instance := &velerov1api.BackupStorageLocation{}
err := r.Client.Get(ctx, key, instance)
Expect(err).To(BeNil())
Expect(instance.Spec.Default).To(BeIdenticalTo(tests[i].expectedIsDefault))
Expect(instance.Status.Phase).To(BeIdenticalTo(tests[i].expectedPhase))
}
})
It("Should successfully patch a backup storage location object spec default if the BSL is the default one", func() {
tests := []struct {
backupLocation *velerov1api.BackupStorageLocation
isValidError error
expectedIsDefault bool
}{
{
backupLocation: builder.ForBackupStorageLocation("ns-1", "location-1").ValidationFrequency(1 * time.Second).Default(false).Result(),
isValidError: nil,
expectedIsDefault: false,
},
{
backupLocation: builder.ForBackupStorageLocation("ns-1", "location-2").ValidationFrequency(1 * time.Second).Default(true).Result(),
isValidError: nil,
expectedIsDefault: true,
},
}
@ -108,28 +180,31 @@ var _ = Describe("Backup Storage Location Reconciler", func() {
instance := &velerov1api.BackupStorageLocation{}
err := r.Client.Get(ctx, key, instance)
Expect(err).To(BeNil())
Expect(instance.Status.Phase).To(BeIdenticalTo(tests[i].expectedPhase))
Expect(instance.Spec.Default).To(BeIdenticalTo(tests[i].expectedIsDefault))
}
})
It("Should not patch a backup storage location object status phase if the location's validation frequency is specifically set to zero", func() {
tests := []struct {
backupLocation *velerov1api.BackupStorageLocation
isValidError error
expectedPhase velerov1api.BackupStorageLocationPhase
wantErr bool
backupLocation *velerov1api.BackupStorageLocation
isValidError error
expectedIsDefault bool
expectedPhase velerov1api.BackupStorageLocationPhase
wantErr bool
}{
{
backupLocation: builder.ForBackupStorageLocation("ns-1", "location-1").ValidationFrequency(0).LastValidationTime(time.Now()).Result(),
isValidError: nil,
expectedPhase: "",
wantErr: false,
backupLocation: builder.ForBackupStorageLocation("ns-1", "location-1").ValidationFrequency(0).LastValidationTime(time.Now()).Result(),
isValidError: nil,
expectedIsDefault: false,
expectedPhase: "",
wantErr: false,
},
{
backupLocation: builder.ForBackupStorageLocation("ns-1", "location-2").ValidationFrequency(0).LastValidationTime(time.Now()).Result(),
isValidError: nil,
expectedPhase: "",
wantErr: false,
backupLocation: builder.ForBackupStorageLocation("ns-1", "location-2").ValidationFrequency(0).LastValidationTime(time.Now()).Result(),
isValidError: nil,
expectedIsDefault: false,
expectedPhase: "",
wantErr: false,
},
}
@ -178,6 +253,7 @@ var _ = Describe("Backup Storage Location Reconciler", func() {
instance := &velerov1api.BackupStorageLocation{}
err := r.Client.Get(ctx, key, instance)
Expect(err).To(BeNil())
Expect(instance.Spec.Default).To(BeIdenticalTo(tests[i].expectedIsDefault))
Expect(instance.Status.Phase).To(BeIdenticalTo(tests[i].expectedPhase))
}
})

View File

@ -1,5 +1,5 @@
/*
Copyright 2017, 2020 the Velero contributors.
Copyright 2020 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.
@ -129,7 +129,13 @@ func (c *backupSyncController) run() {
return
}
// sync the default location first, if it exists
// sync the default backup storage location first, if it exists
for _, location := range locationList.Items {
if location.Spec.Default {
c.defaultBackupLocation = location.Name
break
}
}
locations := orderedBackupLocations(&locationList, c.defaultBackupLocation)
pluginManager := c.newPluginManager(c.logger)

View File

@ -55,6 +55,7 @@ func defaultLocationsList(namespace string) []*velerov1api.BackupStorageLocation
Bucket: "bucket-1",
},
},
Default: true,
},
},
{

View File

@ -1,5 +1,5 @@
/*
Copyright 2017, 2019 the Velero contributors.
Copyright 2020 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.
@ -109,7 +109,6 @@ func NewRestoreController(
logger logrus.FieldLogger,
restoreLogLevel logrus.Level,
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager,
defaultBackupLocation string,
metrics *metrics.ServerMetrics,
logFormat logging.Format,
) Interface {
@ -124,7 +123,6 @@ func NewRestoreController(
kbClient: kbClient,
snapshotLocationLister: snapshotLocationLister,
restoreLogLevel: restoreLogLevel,
defaultBackupLocation: defaultBackupLocation,
metrics: metrics,
logFormat: logFormat,
clock: &clock.RealClock{},

View File

@ -1,5 +1,5 @@
/*
Copyright 2017, 2019 the Velero contributors.
Copyright 2020 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.
@ -117,7 +117,6 @@ func TestFetchBackupInfo(t *testing.T) {
logger,
logrus.InfoLevel,
func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
"default",
metrics.NewServerMetrics(),
formatFlag,
).(*restoreController)
@ -213,7 +212,6 @@ func TestProcessQueueItemSkips(t *testing.T) {
logger,
logrus.InfoLevel,
nil,
"default",
metrics.NewServerMetrics(),
formatFlag,
).(*restoreController)
@ -440,7 +438,6 @@ func TestProcessQueueItem(t *testing.T) {
logger,
logrus.InfoLevel,
func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
"default",
metrics.NewServerMetrics(),
formatFlag,
).(*restoreController)
@ -673,7 +670,6 @@ func TestvalidateAndCompleteWhenScheduleNameSpecified(t *testing.T) {
logger,
logrus.DebugLevel,
nil,
"default",
nil,
formatFlag,
).(*restoreController)

View File

@ -62,29 +62,34 @@ Alternately, since in this example there's only one possible volume snapshot loc
velero backup create full-cluster-backup
```
### Have some Velero backups go to a bucket in an eastern USA region, and others go to a bucket in a western USA region
### Have some Velero backups go to a bucket in an eastern USA region (default), and others go to a bucket in a western USA region
During server configuration:
```shell
velero backup-location create default \
velero backup-location create backups-primary \
--provider aws \
--bucket velero-backups \
--config region=us-east-1
--config region=us-east-1 \
--default
velero backup-location create s3-alt-region \
velero backup-location create backups-secondary \
--provider aws \
--bucket velero-backups-alt \
--bucket velero-backups \
--config region=us-west-1
```
You can alter which backup storage location as default by setting the `--default` flag under the
`velero backup-location set` command to configure another location to be the default backup storage location.
```shell
velero backup-location set backups-secondary --default
```
Once the defaulted backup storage location existed under `velero backup-location get --default`, then changes the default backup storage location name by `velero server --default-backup-storage-location` takes no effects anymore because the velero backup storage location controller prefers to use velero client-side setting. However, if there is no defaulted backup storage location under `velero backup-location get --default`, then changes the default backup storage location name by `velero server --default-backup-storage-location` would work.
During backup creation:
```shell
# The Velero server will automatically store backups in the backup storage location named "default" if
# one is not specified when creating the backup. You can alter which backup storage location is used
# by default by setting the --default-backup-storage-location flag on the `velero server` command (run
# by the Velero deployment) to the name of a different backup storage location.
velero backup create full-cluster-backup
```
@ -92,7 +97,7 @@ Or:
```shell
velero backup create full-cluster-alternate-location-backup \
--storage-location s3-alt-region
--storage-location backups-secondary
```
### For volume providers that support it (like Portworx), have some snapshots be stored locally on the cluster and have others be stored in the cloud
@ -135,10 +140,11 @@ If you don't have a use case for more than one location, it's still easy to use
During server configuration:
```shell
velero backup-location create default \
velero backup-location create backups-primary \
--provider aws \
--bucket velero-backups \
--config region=us-west-1
--config region=us-west-1 \
--default
velero snapshot-location create ebs-us-west-1 \
--provider aws \

View File

@ -0,0 +1,85 @@
---
title: "Upgrading to Velero 1.6"
layout: docs
---
## Prerequisites
- Velero [v1.5.x][5] installed.
If you're not yet running at least Velero v1.5, see the following:
- [Upgrading to v1.1][1]
- [Upgrading to v1.2][2]
- [Upgrading to v1.3][3]
- [Upgrading to v1.4][4]
- [Upgrading to v1.5][5]
## Instructions
1. Install the Velero v1.6 command-line interface (CLI) by following the [instructions here][0].
Verify that you've properly installed it by running:
```bash
velero version --client-only
```
You should see the following output:
```bash
Client:
Version: v1.6.0
Git commit: <git SHA>
```
1. Update the Velero custom resource definitions (CRDs) to include schema changes across all CRDs that are at the core of the new features in this release:
```bash
velero install --crds-only --dry-run -o yaml | kubectl apply -f -
```
**NOTE:** If you are upgrading Velero in Kubernetes 1.14.x or earlier, you will need to use `kubectl apply`'s `--validate=false` option when applying the CRD configuration above. See [issue 2077][6] and [issue 2311][7] for more context.
1. Update the container image used by the Velero deployment and, optionally, the restic daemon set:
```bash
kubectl set image deployment/velero \
velero=velero/velero:v1.6.0 \
--namespace velero
# optional, if using the restic daemon set
kubectl set image daemonset/restic \
restic=velero/velero:v1.6.0 \
--namespace velero
```
1. Confirm that the deployment is up and running with the correct version by running:
```bash
velero version
```
You should see the following output:
```bash
Client:
Version: v1.6.0
Git commit: <git SHA>
Server:
Version: v1.6.0
```
1. We've deprecated the way to indicate the default backup storage location according to the backup storage location name on the velero server-side `velero server --default-backup-storage-location`, but instead configure the default backup storage location at the velero client-side, please refer to the [About locations][9] on how to indicate which backup storage location is the default one. Moreover, during the velero upgrading process, the velero backup storage location controller helps you configure which backup storage location name matches against the backup storage location name on the velero server-side `velero server --default-backup-storage-location`, then sets the BackupStorageLocation custom resource `.spec.default` to `true`.
[0]: basic-install.md#install-the-cli
[1]: https://velero.io/docs/v1.1.0/upgrade-to-1.1/
[2]: https://velero.io/docs/v1.2.0/upgrade-to-1.2/
[3]: https://velero.io/docs/v1.3.2/upgrade-to-1.3/
[4]: https://velero.io/docs/v1.4/upgrade-to-1.4/
[5]: https://velero.io/docs/v1.5/upgrade-to-1.5
[6]: https://github.com/vmware-tanzu/velero/releases/tag/v1.4.2
[7]: https://github.com/vmware-tanzu/velero/issues/2077
[8]: https://github.com/vmware-tanzu/velero/issues/2311
[9]: https://velero.io/docs/v1.6/locations