mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-04-25 10:10:33 +00:00
Merge pull request #391 from containscafeine/handle-restore-missing-error
Introduce validation logic to `ark restore logs`
This commit is contained in:
@@ -22,10 +22,13 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/heptio/ark/pkg/apis/ark/v1"
|
||||
"github.com/heptio/ark/pkg/client"
|
||||
"github.com/heptio/ark/pkg/cmd"
|
||||
"github.com/heptio/ark/pkg/cmd/util/downloadrequest"
|
||||
arkclient "github.com/heptio/ark/pkg/generated/clientset/versioned"
|
||||
)
|
||||
|
||||
func NewLogsCommand(f client.Factory) *cobra.Command {
|
||||
@@ -36,9 +39,11 @@ func NewLogsCommand(f client.Factory) *cobra.Command {
|
||||
Short: "Get restore logs",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
l := NewLogsOptions()
|
||||
cmd.CheckError(l.Complete(args))
|
||||
cmd.CheckError(l.Validate(f))
|
||||
arkClient, err := f.Client()
|
||||
cmd.CheckError(err)
|
||||
|
||||
err = downloadrequest.Stream(arkClient.ArkV1(), f.Namespace(), args[0], v1.DownloadTargetKindRestoreLog, os.Stdout, timeout)
|
||||
cmd.CheckError(err)
|
||||
},
|
||||
@@ -48,3 +53,35 @@ func NewLogsCommand(f client.Factory) *cobra.Command {
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
// LogsOptions contains the fields required to retrieve logs of a restore
|
||||
type LogsOptions struct {
|
||||
RestoreName string
|
||||
|
||||
client arkclient.Interface
|
||||
}
|
||||
|
||||
// NewLogsOptions returns a new instance of LogsOptions
|
||||
func NewLogsOptions() *LogsOptions {
|
||||
return &LogsOptions{}
|
||||
}
|
||||
|
||||
// Complete fills in LogsOptions with the given parameters, like populating the
|
||||
// restore name from the input args
|
||||
func (l *LogsOptions) Complete(args []string) error {
|
||||
l.RestoreName = args[0]
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate validates the LogsOptions against the cluster, like validating if
|
||||
// the given restore exists in the cluster or not
|
||||
func (l *LogsOptions) Validate(f client.Factory) error {
|
||||
c, err := f.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
l.client = c
|
||||
|
||||
_, err = l.client.ArkV1().Restores(f.Namespace()).Get(l.RestoreName, metav1.GetOptions{})
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user