Merge pull request #302 from ncdc/check-backup-before-creating-restore
Error if backup missing when creating a restorepull/296/head
commit
fcbc7bd570
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/heptio/ark/pkg/cmd"
|
"github.com/heptio/ark/pkg/cmd"
|
||||||
"github.com/heptio/ark/pkg/cmd/util/flag"
|
"github.com/heptio/ark/pkg/cmd/util/flag"
|
||||||
"github.com/heptio/ark/pkg/cmd/util/output"
|
"github.com/heptio/ark/pkg/cmd/util/output"
|
||||||
|
arkclient "github.com/heptio/ark/pkg/generated/clientset/versioned"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCreateCommand(f client.Factory, use string) *cobra.Command {
|
func NewCreateCommand(f client.Factory, use string) *cobra.Command {
|
||||||
|
@ -40,7 +41,7 @@ func NewCreateCommand(f client.Factory, use string) *cobra.Command {
|
||||||
Use: use + " BACKUP",
|
Use: use + " BACKUP",
|
||||||
Short: "Create a restore",
|
Short: "Create a restore",
|
||||||
Run: func(c *cobra.Command, args []string) {
|
Run: func(c *cobra.Command, args []string) {
|
||||||
cmd.CheckError(o.Validate(c, args))
|
cmd.CheckError(o.Validate(c, args, f))
|
||||||
cmd.CheckError(o.Complete(args))
|
cmd.CheckError(o.Complete(args))
|
||||||
cmd.CheckError(o.Run(c, f))
|
cmd.CheckError(o.Run(c, f))
|
||||||
},
|
},
|
||||||
|
@ -64,6 +65,8 @@ type CreateOptions struct {
|
||||||
NamespaceMappings flag.Map
|
NamespaceMappings flag.Map
|
||||||
Selector flag.LabelSelector
|
Selector flag.LabelSelector
|
||||||
IncludeClusterResources flag.OptionalBool
|
IncludeClusterResources flag.OptionalBool
|
||||||
|
|
||||||
|
client arkclient.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCreateOptions() *CreateOptions {
|
func NewCreateOptions() *CreateOptions {
|
||||||
|
@ -93,7 +96,7 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) {
|
||||||
f.NoOptDefVal = "true"
|
f.NoOptDefVal = "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *CreateOptions) Validate(c *cobra.Command, args []string) error {
|
func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Factory) error {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return errors.New("you must specify only one argument, the backup's name")
|
return errors.New("you must specify only one argument, the backup's name")
|
||||||
}
|
}
|
||||||
|
@ -102,6 +105,17 @@ func (o *CreateOptions) Validate(c *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client, err := f.Client()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
o.client = client
|
||||||
|
|
||||||
|
_, err = o.client.ArkV1().Backups(f.Namespace()).Get(args[0], metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,9 +125,9 @@ func (o *CreateOptions) Complete(args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error {
|
func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error {
|
||||||
arkClient, err := f.Client()
|
if o.client == nil {
|
||||||
if err != nil {
|
// This should never happen
|
||||||
return err
|
return errors.New("Ark client is not set; unable to proceed")
|
||||||
}
|
}
|
||||||
|
|
||||||
restore := &api.Restore{
|
restore := &api.Restore{
|
||||||
|
@ -139,7 +153,7 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
restore, err = arkClient.ArkV1().Restores(restore.Namespace).Create(restore)
|
restore, err := o.client.ArkV1().Restores(restore.Namespace).Create(restore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue