mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-19 06:26:44 +00:00
add restic integration for doing pod volume backups/restores
Signed-off-by: Steve Kriss <steve@heptio.com>
This commit is contained in:
@@ -18,15 +18,13 @@ package flag
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
)
|
||||
|
||||
// Enum is a Cobra-compatible wrapper for defining
|
||||
// a string flag that can be one of a specified set
|
||||
// of values.
|
||||
type Enum struct {
|
||||
allowedValues sets.String
|
||||
allowedValues []string
|
||||
value string
|
||||
}
|
||||
|
||||
@@ -35,7 +33,7 @@ type Enum struct {
|
||||
// none is set.
|
||||
func NewEnum(defaultValue string, allowedValues ...string) *Enum {
|
||||
return &Enum{
|
||||
allowedValues: sets.NewString(allowedValues...),
|
||||
allowedValues: allowedValues,
|
||||
value: defaultValue,
|
||||
}
|
||||
}
|
||||
@@ -50,12 +48,14 @@ func (e *Enum) String() string {
|
||||
// receiver. It returns an error if the string
|
||||
// is not an allowed value.
|
||||
func (e *Enum) Set(s string) error {
|
||||
if !e.allowedValues.Has(s) {
|
||||
return errors.Errorf("invalid value: %q", s)
|
||||
for _, val := range e.allowedValues {
|
||||
if val == s {
|
||||
e.value = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
e.value = s
|
||||
return nil
|
||||
return errors.Errorf("invalid value: %q", s)
|
||||
}
|
||||
|
||||
// Type returns a string representation of the
|
||||
@@ -66,3 +66,9 @@ func (e *Enum) Type() string {
|
||||
// the possible options.
|
||||
return ""
|
||||
}
|
||||
|
||||
// AllowedValues returns a slice of the flag's valid
|
||||
// values.
|
||||
func (e *Enum) AllowedValues() []string {
|
||||
return e.allowedValues
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright 2018 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 signals
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// CancelOnShutdown starts a goroutine that will call cancelFunc when
|
||||
// either SIGINT or SIGTERM is received
|
||||
func CancelOnShutdown(cancelFunc context.CancelFunc, logger logrus.FieldLogger) {
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
sig := <-sigs
|
||||
logger.Infof("Received signal %s, shutting down", sig)
|
||||
cancelFunc()
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user