diff --git a/pkg/cmd/cli/restore/logs.go b/pkg/cmd/cli/restore/logs.go index 2a0eb352a..64ffff1f5 100644 --- a/pkg/cmd/cli/restore/logs.go +++ b/pkg/cmd/cli/restore/logs.go @@ -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 +}