mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-19 14:34:17 +00:00
Add pod exec backup hooks
Signed-off-by: Andy Goldstein <andy.goldstein@gmail.com>
This commit is contained in:
@@ -17,6 +17,8 @@ limitations under the License.
|
||||
package collections
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
@@ -70,13 +72,33 @@ func (ie *IncludesExcludes) ShouldInclude(s string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
return ie.includes.Has("*") || ie.includes.Has(s)
|
||||
// len=0 means include everything
|
||||
return ie.includes.Len() == 0 || ie.includes.Has("*") || ie.includes.Has(s)
|
||||
}
|
||||
|
||||
// IncludeEverything returns true if the Includes list is '*'
|
||||
// and the Excludes list is empty, or false otherwise.
|
||||
// IncludesString returns a string containing all of the includes, separated by commas, or * if the
|
||||
// list is empty.
|
||||
func (ie *IncludesExcludes) IncludesString() string {
|
||||
return asString(ie.GetIncludes())
|
||||
}
|
||||
|
||||
// ExcludesString returns a string containing all of the excludes, separated by commas, or * if the
|
||||
// list is empty.
|
||||
func (ie *IncludesExcludes) ExcludesString() string {
|
||||
return asString(ie.GetExcludes())
|
||||
}
|
||||
|
||||
func asString(in []string) string {
|
||||
if len(in) == 0 {
|
||||
return "*"
|
||||
}
|
||||
return strings.Join(in, ", ")
|
||||
}
|
||||
|
||||
// IncludeEverything returns true if the includes list is empty or '*'
|
||||
// and the excludes list is empty, or false otherwise.
|
||||
func (ie *IncludesExcludes) IncludeEverything() bool {
|
||||
return ie.excludes.Len() == 0 && ie.includes.Len() == 1 && ie.includes.Has("*")
|
||||
return ie.excludes.Len() == 0 && (ie.includes.Len() == 0 || (ie.includes.Len() == 1 && ie.includes.Has("*")))
|
||||
}
|
||||
|
||||
// ValidateIncludesExcludes checks provided lists of included and excluded
|
||||
@@ -91,10 +113,6 @@ func ValidateIncludesExcludes(includesList, excludesList []string) []error {
|
||||
includes := sets.NewString(includesList...)
|
||||
excludes := sets.NewString(excludesList...)
|
||||
|
||||
if includes.Len() == 0 {
|
||||
errs = append(errs, errors.New("includes list cannot be empty"))
|
||||
}
|
||||
|
||||
if includes.Len() > 1 && includes.Has("*") {
|
||||
errs = append(errs, errors.New("includes list must either contain '*' only, or a non-empty list of items"))
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ func TestShouldInclude(t *testing.T) {
|
||||
should bool
|
||||
}{
|
||||
{
|
||||
name: "empty - don't include anything",
|
||||
name: "empty - include everything",
|
||||
check: "foo",
|
||||
should: false,
|
||||
should: true,
|
||||
},
|
||||
{
|
||||
name: "include *",
|
||||
@@ -97,9 +97,8 @@ func TestValidateIncludesExcludes(t *testing.T) {
|
||||
expected []error
|
||||
}{
|
||||
{
|
||||
name: "include nothing not allowed",
|
||||
name: "empty includes (everything) is allowed",
|
||||
includes: []string{},
|
||||
expected: []error{errors.New("includes list cannot be empty")},
|
||||
},
|
||||
{
|
||||
name: "include everything",
|
||||
|
||||
@@ -32,12 +32,10 @@ import (
|
||||
)
|
||||
|
||||
// NamespaceAndName returns a string in the format <namespace>/<name>
|
||||
func NamespaceAndName(metaAccessor metav1.ObjectMetaAccessor) string {
|
||||
objMeta := metaAccessor.GetObjectMeta()
|
||||
if objMeta == nil {
|
||||
return ""
|
||||
func NamespaceAndName(objMeta metav1.Object) string {
|
||||
if objMeta.GetNamespace() == "" {
|
||||
return objMeta.GetName()
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s/%s", objMeta.GetNamespace(), objMeta.GetName())
|
||||
}
|
||||
|
||||
|
||||
@@ -34,13 +34,8 @@ type FakeDynamicFactory struct {
|
||||
|
||||
var _ client.DynamicFactory = &FakeDynamicFactory{}
|
||||
|
||||
func (df *FakeDynamicFactory) ClientForGroupVersionResource(gvr schema.GroupVersionResource, resource metav1.APIResource, namespace string) (client.Dynamic, error) {
|
||||
args := df.Called(gvr, resource, namespace)
|
||||
return args.Get(0).(client.Dynamic), args.Error(1)
|
||||
}
|
||||
|
||||
func (df *FakeDynamicFactory) ClientForGroupVersionKind(gvk schema.GroupVersionKind, resource metav1.APIResource, namespace string) (client.Dynamic, error) {
|
||||
args := df.Called(gvk, resource, namespace)
|
||||
func (df *FakeDynamicFactory) ClientForGroupVersionResource(gv schema.GroupVersion, resource metav1.APIResource, namespace string) (client.Dynamic, error) {
|
||||
args := df.Called(gv, resource, namespace)
|
||||
return args.Get(0).(client.Dynamic), args.Error(1)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,7 @@ limitations under the License.
|
||||
package test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
@@ -38,12 +37,12 @@ func (m *FakeMapper) ResourceFor(input schema.GroupVersionResource) (schema.Grou
|
||||
}, nil
|
||||
}
|
||||
if m.Resources == nil {
|
||||
return schema.GroupVersionResource{}, errors.New("invalid resource")
|
||||
return schema.GroupVersionResource{}, errors.Errorf("invalid resource %q", input.String())
|
||||
}
|
||||
|
||||
if gr, found := m.Resources[input]; found {
|
||||
return gr, nil
|
||||
}
|
||||
|
||||
return schema.GroupVersionResource{}, errors.New("invalid resource")
|
||||
return schema.GroupVersionResource{}, errors.Errorf("invalid resource %q", input.String())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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 (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func NewLogger() *logrus.Entry {
|
||||
logger := logrus.New()
|
||||
logger.Out = ioutil.Discard
|
||||
return logrus.NewEntry(logger)
|
||||
}
|
||||
Reference in New Issue
Block a user