Skip to content

Commit fe21b64

Browse files
authored
Merge pull request vmware-tanzu#20 from sseago/fusor-dev-rebase6
Rebase against upstream again after SkipRestore feature accepted upstream
2 parents f364e97 + 484b39c commit fe21b64

26 files changed

+363
-53
lines changed

changelogs/unreleased/1246-skriss

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
don't remove storageclass from a persistent volume when restoring it

changelogs/unreleased/1280-fabito

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Collect 3 new metrics: backup_deletion_{attempt|failure|success}_total

changelogs/unreleased/1293-fabito

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gracefully handle failed API groups from the discovery API
File renamed without changes.

changelogs/unreleased/1336-sseago

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for allowing a RestoreItemAction to skip item restore.

changelogs/unreleased/1337-skriss

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
velero backup logs & velero restore logs: show helpful error message if backup/restore does not exist or is not finished processing

changelogs/unreleased/1338-skriss

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aws/azure/gcp: fail fast if unsupported keys are provided in BackupStorageLocation/VolumeSnapshotLocation config

docs/support-matrix.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ _Note that these providers are not regularly tested by the Velero team._
2121
* Ceph RADOS v12.2.7
2222
* [DigitalOcean][7]
2323
* Quobyte
24+
* [NooBaa][16]
2425

2526
_Some storage providers, like Quobyte, may need a different [signature algorithm version][15]._
2627

@@ -56,3 +57,4 @@ After you publish your plugin, open a PR that adds your plugin to the appropriat
5657
[13]: https://portworx.slack.com/messages/px-k8s
5758
[14]: https://github.com/portworx/ark-plugin/issues
5859
[15]: api-types/backupstoragelocation.md#aws
60+
[16]: http://www.noobaa.com/

pkg/cloudprovider/aws/object_store.go

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"github.com/aws/aws-sdk-go/service/s3/s3manager"
3030
"github.com/pkg/errors"
3131
"github.com/sirupsen/logrus"
32+
33+
"github.com/heptio/velero/pkg/cloudprovider"
3234
)
3335

3436
const (
@@ -62,6 +64,17 @@ func isValidSignatureVersion(signatureVersion string) bool {
6264
}
6365

6466
func (o *ObjectStore) Init(config map[string]string) error {
67+
if err := cloudprovider.ValidateObjectStoreConfigKeys(config,
68+
regionKey,
69+
s3URLKey,
70+
publicURLKey,
71+
kmsKeyIDKey,
72+
s3ForcePathStyleKey,
73+
signatureVersionKey,
74+
); err != nil {
75+
return err
76+
}
77+
6578
var (
6679
region = config[regionKey]
6780
s3URL = config[s3URLKey]

pkg/cloudprovider/aws/volume_snapshotter.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2017 the Velero contributors.
2+
Copyright 2017, 2019 the Velero contributors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -32,6 +32,8 @@ import (
3232
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3333
"k8s.io/apimachinery/pkg/runtime"
3434
"k8s.io/apimachinery/pkg/util/sets"
35+
36+
"github.com/heptio/velero/pkg/cloudprovider"
3537
)
3638

3739
const regionKey = "region"
@@ -64,6 +66,10 @@ func NewVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter {
6466
}
6567

6668
func (b *VolumeSnapshotter) Init(config map[string]string) error {
69+
if err := cloudprovider.ValidateVolumeSnapshotterConfigKeys(config, regionKey); err != nil {
70+
return err
71+
}
72+
6773
region := config[regionKey]
6874
if region == "" {
6975
return errors.Errorf("missing %s in aws configuration", regionKey)

pkg/cloudprovider/azure/object_store.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2017 the Velero contributors.
2+
Copyright 2017, 2019 the Velero contributors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -29,6 +29,8 @@ import (
2929
"github.com/Azure/go-autorest/autorest/azure"
3030
"github.com/pkg/errors"
3131
"github.com/sirupsen/logrus"
32+
33+
"github.com/heptio/velero/pkg/cloudprovider"
3234
)
3335

3436
const (
@@ -99,6 +101,10 @@ func mapLookup(data map[string]string) func(string) string {
99101
}
100102

101103
func (o *ObjectStore) Init(config map[string]string) error {
104+
if err := cloudprovider.ValidateObjectStoreConfigKeys(config, resourceGroupConfigKey, storageAccountConfigKey); err != nil {
105+
return err
106+
}
107+
102108
storageAccountKey, err := getStorageAccountKey(config)
103109
if err != nil {
104110
return err

pkg/cloudprovider/azure/volume_snapshotter.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2017 the Velero contributors.
2+
Copyright 2017, 2019 the Velero contributors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -34,6 +34,8 @@ import (
3434
v1 "k8s.io/api/core/v1"
3535
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3636
"k8s.io/apimachinery/pkg/runtime"
37+
38+
"github.com/heptio/velero/pkg/cloudprovider"
3739
)
3840

3941
const (
@@ -70,6 +72,10 @@ func NewVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter {
7072
}
7173

7274
func (b *VolumeSnapshotter) Init(config map[string]string) error {
75+
if err := cloudprovider.ValidateVolumeSnapshotterConfigKeys(config, resourceGroupConfigKey, apiTimeoutConfigKey); err != nil {
76+
return err
77+
}
78+
7379
// 1. we need AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID, AZURE_RESOURCE_GROUP
7480
envVars, err := getRequiredValues(os.Getenv, tenantIDEnvVar, clientIDEnvVar, clientSecretEnvVar, subscriptionIDEnvVar, resourceGroupEnvVar)
7581
if err != nil {

pkg/cloudprovider/config.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright 2019 the Velero contributors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cloudprovider
18+
19+
import (
20+
"github.com/pkg/errors"
21+
"k8s.io/apimachinery/pkg/util/sets"
22+
)
23+
24+
// ValidateObjectStoreConfigKeys ensures that an object store's config
25+
// is valid by making sure each `config` key is in the `validKeys` list.
26+
// The special key "bucket" is always considered valid.
27+
func ValidateObjectStoreConfigKeys(config map[string]string, validKeys ...string) error {
28+
// `bucket` is automatically added to all object store config by
29+
// velero, so add it as a valid key.
30+
return validateConfigKeys(config, append(validKeys, "bucket")...)
31+
}
32+
33+
// ValidateVolumeSnapshotterConfigKeys ensures that a volume snapshotter's
34+
// config is valid by making sure each `config` key is in the `validKeys` list.
35+
func ValidateVolumeSnapshotterConfigKeys(config map[string]string, validKeys ...string) error {
36+
return validateConfigKeys(config, validKeys...)
37+
}
38+
39+
func validateConfigKeys(config map[string]string, validKeys ...string) error {
40+
validKeysSet := sets.NewString(validKeys...)
41+
42+
var invalidKeys []string
43+
for k := range config {
44+
if !validKeysSet.Has(k) {
45+
invalidKeys = append(invalidKeys, k)
46+
}
47+
}
48+
49+
if len(invalidKeys) > 0 {
50+
return errors.Errorf("config has invalid keys %v; valid keys are %v", invalidKeys, validKeys)
51+
}
52+
53+
return nil
54+
}

pkg/cloudprovider/config_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2019 the Velero contributors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cloudprovider
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestValidateConfigKeys(t *testing.T) {
26+
assert.NoError(t, validateConfigKeys(nil))
27+
assert.NoError(t, validateConfigKeys(map[string]string{}))
28+
assert.NoError(t, validateConfigKeys(map[string]string{"foo": "bar"}, "foo"))
29+
assert.NoError(t, validateConfigKeys(map[string]string{"foo": "bar", "bar": "baz"}, "foo", "bar"))
30+
31+
assert.Error(t, validateConfigKeys(map[string]string{"foo": "bar"}))
32+
assert.Error(t, validateConfigKeys(map[string]string{"foo": "bar"}, "Foo"))
33+
assert.Error(t, validateConfigKeys(map[string]string{"foo": "bar", "boo": ""}, "foo"))
34+
35+
assert.NoError(t, ValidateObjectStoreConfigKeys(map[string]string{"bucket": "foo"}))
36+
assert.Error(t, ValidateVolumeSnapshotterConfigKeys(map[string]string{"bucket": "foo"}))
37+
}

pkg/cloudprovider/gcp/object_store.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2017 the Velero contributors.
2+
Copyright 2017, 2019 the Velero contributors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -29,6 +29,8 @@ import (
2929
"golang.org/x/oauth2/google"
3030
"google.golang.org/api/iterator"
3131
"google.golang.org/api/option"
32+
33+
"github.com/heptio/velero/pkg/cloudprovider"
3234
)
3335

3436
const credentialsEnvVar = "GOOGLE_APPLICATION_CREDENTIALS"
@@ -60,6 +62,10 @@ func NewObjectStore(logger logrus.FieldLogger) *ObjectStore {
6062
}
6163

6264
func (o *ObjectStore) Init(config map[string]string) error {
65+
if err := cloudprovider.ValidateObjectStoreConfigKeys(config); err != nil {
66+
return err
67+
}
68+
6369
credentialsFile := os.Getenv(credentialsEnvVar)
6470
if credentialsFile == "" {
6571
return errors.Errorf("%s is undefined", credentialsEnvVar)

pkg/cloudprovider/gcp/volume_snapshotter.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2017 the Velero contributors.
2+
Copyright 2017, 2019 the Velero contributors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -33,6 +33,8 @@ import (
3333
v1 "k8s.io/api/core/v1"
3434
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3535
"k8s.io/apimachinery/pkg/runtime"
36+
37+
"github.com/heptio/velero/pkg/cloudprovider"
3638
)
3739

3840
const (
@@ -51,6 +53,10 @@ func NewVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter {
5153
}
5254

5355
func (b *VolumeSnapshotter) Init(config map[string]string) error {
56+
if err := cloudprovider.ValidateVolumeSnapshotterConfigKeys(config); err != nil {
57+
return err
58+
}
59+
5460
project, err := extractProjectFromCreds()
5561
if err != nil {
5662
return err

pkg/cmd/cli/backup/logs.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"time"
2222

2323
"github.com/spf13/cobra"
24+
apierrors "k8s.io/apimachinery/pkg/api/errors"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2426

2527
v1 "github.com/heptio/velero/pkg/apis/velero/v1"
2628
"github.com/heptio/velero/pkg/client"
@@ -36,10 +38,24 @@ func NewLogsCommand(f client.Factory) *cobra.Command {
3638
Short: "Get backup logs",
3739
Args: cobra.ExactArgs(1),
3840
Run: func(c *cobra.Command, args []string) {
41+
backupName := args[0]
42+
3943
veleroClient, err := f.Client()
4044
cmd.CheckError(err)
4145

42-
err = downloadrequest.Stream(veleroClient.VeleroV1(), f.Namespace(), args[0], v1.DownloadTargetKindBackupLog, os.Stdout, timeout)
46+
backup, err := veleroClient.VeleroV1().Backups(f.Namespace()).Get(backupName, metav1.GetOptions{})
47+
if apierrors.IsNotFound(err) {
48+
cmd.Exit("Backup %q does not exist.", backupName)
49+
} else if err != nil {
50+
cmd.Exit("Error checking for backup %q: %v", backupName, err)
51+
}
52+
53+
if backup.Status.Phase != v1.BackupPhaseCompleted && backup.Status.Phase != v1.BackupPhaseFailed {
54+
cmd.Exit("Logs for backup %q are not available until it's finished processing. Please wait "+
55+
"until the backup has a phase of Completed or Failed and try again.", backupName)
56+
}
57+
58+
err = downloadrequest.Stream(veleroClient.VeleroV1(), f.Namespace(), backupName, v1.DownloadTargetKindBackupLog, os.Stdout, timeout)
4359
cmd.CheckError(err)
4460
},
4561
}

0 commit comments

Comments
 (0)