Add pod exec backup hooks

Signed-off-by: Andy Goldstein <andy.goldstein@gmail.com>
This commit is contained in:
Andy Goldstein
2017-10-20 10:20:59 -04:00
parent efcb32059a
commit 901f8e1302
32 changed files with 4006 additions and 1425 deletions
+26 -8
View File
@@ -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",
+3 -5
View File
@@ -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())
}
+2 -7
View File
@@ -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)
}
+3 -4
View File
@@ -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())
}
+29
View File
@@ -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)
}