mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-07-19 22:42:44 +00:00
add restic repo getter and reorg restic cmds
Signed-off-by: Steve Kriss <steve@heptio.com>
This commit is contained in:
@@ -38,7 +38,7 @@ operations can also be performed as 'ark backup get' and 'ark schedule create'.
|
||||
* [ark describe](ark_describe.md) - Describe ark resources
|
||||
* [ark get](ark_get.md) - Get ark resources
|
||||
* [ark plugin](ark_plugin.md) - Work with plugins
|
||||
* [ark restic](ark_restic.md) - Work with restic repositories
|
||||
* [ark restic](ark_restic.md) - Work with restic
|
||||
* [ark restore](ark_restore.md) - Work with restores
|
||||
* [ark schedule](ark_schedule.md) - Work with schedules
|
||||
* [ark server](ark_server.md) - Run the ark server
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
## ark restic
|
||||
|
||||
Work with restic repositories
|
||||
Work with restic
|
||||
|
||||
### Synopsis
|
||||
|
||||
|
||||
Work with restic repositories
|
||||
Work with restic
|
||||
|
||||
### Options
|
||||
|
||||
@@ -30,6 +30,6 @@ Work with restic repositories
|
||||
|
||||
### SEE ALSO
|
||||
* [ark](ark.md) - Back up and restore Kubernetes cluster resources.
|
||||
* [ark restic init-repository](ark_restic_init-repository.md) - initialize a restic repository for a specified namespace
|
||||
* [ark restic repo](ark_restic_repo.md) - Work with restic repositories
|
||||
* [ark restic server](ark_restic_server.md) - Run the ark restic server
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
## ark restic repo
|
||||
|
||||
Work with restic repositories
|
||||
|
||||
### Synopsis
|
||||
|
||||
|
||||
Work with restic repositories
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for repo
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
--alsologtostderr log to standard error as well as files
|
||||
--kubeconfig string Path to the kubeconfig file to use to talk to the Kubernetes apiserver. If unset, try the environment variable KUBECONFIG, as well as in-cluster configuration
|
||||
--kubecontext string The context to use to talk to the Kubernetes apiserver. If unset defaults to whatever your current-context is (kubectl config current-context)
|
||||
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
|
||||
--log_dir string If non-empty, write log files in this directory
|
||||
--logtostderr log to standard error instead of files
|
||||
-n, --namespace string The namespace in which Ark should operate (default "heptio-ark")
|
||||
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
|
||||
-v, --v Level log level for V logs
|
||||
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
* [ark restic](ark_restic.md) - Work with restic
|
||||
* [ark restic repo get](ark_restic_repo_get.md) - Get restic repositories
|
||||
* [ark restic repo init](ark_restic_repo_init.md) - initialize a restic repository for a specified namespace
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
## ark restic repo get
|
||||
|
||||
Get restic repositories
|
||||
|
||||
### Synopsis
|
||||
|
||||
|
||||
Get restic repositories
|
||||
|
||||
```
|
||||
ark restic repo get [flags]
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for get
|
||||
--label-columns stringArray a comma-separated list of labels to be displayed as columns
|
||||
-o, --output string Output display format. For create commands, display the object but do not send it to the server. Valid formats are 'table', 'json', and 'yaml'. (default "table")
|
||||
-l, --selector string only show items matching this label selector
|
||||
--show-labels show labels in the last column
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
--alsologtostderr log to standard error as well as files
|
||||
--kubeconfig string Path to the kubeconfig file to use to talk to the Kubernetes apiserver. If unset, try the environment variable KUBECONFIG, as well as in-cluster configuration
|
||||
--kubecontext string The context to use to talk to the Kubernetes apiserver. If unset defaults to whatever your current-context is (kubectl config current-context)
|
||||
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
|
||||
--log_dir string If non-empty, write log files in this directory
|
||||
--logtostderr log to standard error instead of files
|
||||
-n, --namespace string The namespace in which Ark should operate (default "heptio-ark")
|
||||
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
|
||||
-v, --v Level log level for V logs
|
||||
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
* [ark restic repo](ark_restic_repo.md) - Work with restic repositories
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
## ark restic init-repository
|
||||
## ark restic repo init
|
||||
|
||||
initialize a restic repository for a specified namespace
|
||||
|
||||
@@ -8,13 +8,13 @@ initialize a restic repository for a specified namespace
|
||||
initialize a restic repository for a specified namespace
|
||||
|
||||
```
|
||||
ark restic init-repository NAMESPACE [flags]
|
||||
ark restic repo init NAMESPACE [flags]
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for init-repository
|
||||
-h, --help help for init
|
||||
--key-data string Encryption key for the restic repository. Optional; if unset, Ark will generate a random key for you.
|
||||
--key-file string Path to file containing the encryption key for the restic repository. Optional; if unset, Ark will generate a random key for you.
|
||||
--key-size int Size of the generated key for the restic repository (default 1024)
|
||||
@@ -36,5 +36,5 @@ ark restic init-repository NAMESPACE [flags]
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
* [ark restic](ark_restic.md) - Work with restic repositories
|
||||
* [ark restic repo](ark_restic_repo.md) - Work with restic repositories
|
||||
|
||||
@@ -34,5 +34,5 @@ ark restic server [flags]
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
* [ark restic](ark_restic.md) - Work with restic repositories
|
||||
* [ark restic](ark_restic.md) - Work with restic
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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 repo
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
api "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/output"
|
||||
)
|
||||
|
||||
func NewGetCommand(f client.Factory, use string) *cobra.Command {
|
||||
var listOptions metav1.ListOptions
|
||||
|
||||
c := &cobra.Command{
|
||||
Use: use,
|
||||
Short: "Get restic repositories",
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
err := output.ValidateFlags(c)
|
||||
cmd.CheckError(err)
|
||||
|
||||
arkClient, err := f.Client()
|
||||
cmd.CheckError(err)
|
||||
|
||||
var repos *api.ResticRepositoryList
|
||||
if len(args) > 0 {
|
||||
repos = new(api.ResticRepositoryList)
|
||||
for _, name := range args {
|
||||
repo, err := arkClient.Ark().ResticRepositories(f.Namespace()).Get(name, metav1.GetOptions{})
|
||||
cmd.CheckError(err)
|
||||
repos.Items = append(repos.Items, *repo)
|
||||
}
|
||||
} else {
|
||||
repos, err = arkClient.ArkV1().ResticRepositories(f.Namespace()).List(listOptions)
|
||||
cmd.CheckError(err)
|
||||
}
|
||||
|
||||
_, err = output.PrintWithFormat(c, repos)
|
||||
cmd.CheckError(err)
|
||||
},
|
||||
}
|
||||
|
||||
c.Flags().StringVarP(&listOptions.LabelSelector, "selector", "l", listOptions.LabelSelector, "only show items matching this label selector")
|
||||
|
||||
output.BindFlags(c.Flags())
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package restic
|
||||
package repo
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
@@ -34,11 +34,11 @@ import (
|
||||
"github.com/heptio/ark/pkg/util/filesystem"
|
||||
)
|
||||
|
||||
func NewInitRepositoryCommand(f client.Factory) *cobra.Command {
|
||||
func NewInitCommand(f client.Factory) *cobra.Command {
|
||||
o := NewInitRepositoryOptions()
|
||||
|
||||
c := &cobra.Command{
|
||||
Use: "init-repository NAMESPACE",
|
||||
Use: "init NAMESPACE",
|
||||
Short: "initialize a restic repository for a specified namespace",
|
||||
Long: "initialize a restic repository for a specified namespace",
|
||||
Args: cobra.ExactArgs(1),
|
||||
@@ -1,4 +1,20 @@
|
||||
package restic
|
||||
/*
|
||||
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 repo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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 repo
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/heptio/ark/pkg/client"
|
||||
)
|
||||
|
||||
func NewRepositoryCommand(f client.Factory) *cobra.Command {
|
||||
c := &cobra.Command{
|
||||
Use: "repo",
|
||||
Short: "Work with restic repositories",
|
||||
Long: "Work with restic repositories",
|
||||
}
|
||||
|
||||
c.AddCommand(
|
||||
NewInitCommand(f),
|
||||
NewGetCommand(f, "get"),
|
||||
)
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -20,17 +20,18 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/heptio/ark/pkg/client"
|
||||
"github.com/heptio/ark/pkg/cmd/cli/restic/repo"
|
||||
)
|
||||
|
||||
func NewCommand(f client.Factory) *cobra.Command {
|
||||
c := &cobra.Command{
|
||||
Use: "restic",
|
||||
Short: "Work with restic repositories",
|
||||
Long: "Work with restic repositories",
|
||||
Short: "Work with restic",
|
||||
Long: "Work with restic",
|
||||
}
|
||||
|
||||
c.AddCommand(
|
||||
NewInitRepositoryCommand(f),
|
||||
repo.NewRepositoryCommand(f),
|
||||
NewServerCommand(f),
|
||||
)
|
||||
|
||||
|
||||
@@ -141,6 +141,8 @@ func printTable(cmd *cobra.Command, obj runtime.Object) (bool, error) {
|
||||
printer.Handler(restoreColumns, nil, printRestoreList)
|
||||
printer.Handler(scheduleColumns, nil, printSchedule)
|
||||
printer.Handler(scheduleColumns, nil, printScheduleList)
|
||||
printer.Handler(resticRepoColumns, nil, printResticRepo)
|
||||
printer.Handler(resticRepoColumns, nil, printResticRepoList)
|
||||
|
||||
err = printer.PrintObj(obj, os.Stdout)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
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 output
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"k8s.io/kubernetes/pkg/printers"
|
||||
|
||||
"github.com/heptio/ark/pkg/apis/ark/v1"
|
||||
)
|
||||
|
||||
var (
|
||||
resticRepoColumns = []string{"NAME", "STATUS", "LAST MAINTENANCE"}
|
||||
)
|
||||
|
||||
func printResticRepoList(list *v1.ResticRepositoryList, w io.Writer, options printers.PrintOptions) error {
|
||||
for i := range list.Items {
|
||||
if err := printResticRepo(&list.Items[i], w, options); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func printResticRepo(repo *v1.ResticRepository, w io.Writer, options printers.PrintOptions) error {
|
||||
name := printers.FormatResourceName(options.Kind, repo.Name, options.WithKind)
|
||||
|
||||
if options.WithNamespace {
|
||||
if _, err := fmt.Fprintf(w, "%s\t", repo.Namespace); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
status := repo.Status.Phase
|
||||
if status == "" {
|
||||
status = v1.ResticRepositoryPhaseNew
|
||||
}
|
||||
|
||||
lastMaintenance := repo.Status.LastMaintenanceTime.String()
|
||||
if repo.Status.LastMaintenanceTime.IsZero() {
|
||||
lastMaintenance = "<never>"
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprintf(
|
||||
w,
|
||||
"%s\t%s\t%s",
|
||||
name,
|
||||
status,
|
||||
lastMaintenance,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprint(w, printers.AppendLabels(repo.Labels, options.ColumnLabels)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, repo.Labels))
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user