From 06b5af449f043d76f01876607010402beb4354c3 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Thu, 9 Aug 2018 15:08:50 -0700 Subject: [PATCH] add create and get CLI commands for backup locations Signed-off-by: Steve Kriss --- docs/cli-reference/ark.md | 1 + docs/cli-reference/ark_backup-location.md | 35 +++++ .../ark_backup-location_create.md | 45 ++++++ docs/cli-reference/ark_backup-location_get.md | 41 ++++++ docs/cli-reference/ark_create.md | 1 + .../ark_create_backup-location.md | 45 ++++++ docs/cli-reference/ark_get.md | 1 + .../cli-reference/ark_get_backup-locations.md | 41 ++++++ pkg/cmd/ark/ark.go | 2 + pkg/cmd/cli/backuplocation/backup_location.go | 38 +++++ pkg/cmd/cli/backuplocation/create.go | 134 ++++++++++++++++++ pkg/cmd/cli/backuplocation/get.go | 66 +++++++++ pkg/cmd/cli/create/create.go | 2 + pkg/cmd/cli/get/get.go | 5 + .../output/backup_storage_location_printer.go | 71 ++++++++++ pkg/cmd/util/output/output.go | 2 + 16 files changed, 530 insertions(+) create mode 100644 docs/cli-reference/ark_backup-location.md create mode 100644 docs/cli-reference/ark_backup-location_create.md create mode 100644 docs/cli-reference/ark_backup-location_get.md create mode 100644 docs/cli-reference/ark_create_backup-location.md create mode 100644 docs/cli-reference/ark_get_backup-locations.md create mode 100644 pkg/cmd/cli/backuplocation/backup_location.go create mode 100644 pkg/cmd/cli/backuplocation/create.go create mode 100644 pkg/cmd/cli/backuplocation/get.go create mode 100644 pkg/cmd/util/output/backup_storage_location_printer.go diff --git a/docs/cli-reference/ark.md b/docs/cli-reference/ark.md index f6a77e6a2..eee6a7949 100644 --- a/docs/cli-reference/ark.md +++ b/docs/cli-reference/ark.md @@ -31,6 +31,7 @@ operations can also be performed as 'ark backup get' and 'ark schedule create'. ### SEE ALSO * [ark backup](ark_backup.md) - Work with backups +* [ark backup-location](ark_backup-location.md) - Work with backup storage locations * [ark bug](ark_bug.md) - Report an Ark bug * [ark client](ark_client.md) - Ark client related commands * [ark completion](ark_completion.md) - Output shell completion code for the specified shell (bash or zsh) diff --git a/docs/cli-reference/ark_backup-location.md b/docs/cli-reference/ark_backup-location.md new file mode 100644 index 000000000..f371f3b2d --- /dev/null +++ b/docs/cli-reference/ark_backup-location.md @@ -0,0 +1,35 @@ +## ark backup-location + +Work with backup storage locations + +### Synopsis + + +Work with backup storage locations + +### Options + +``` + -h, --help help for backup-location +``` + +### 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](ark.md) - Back up and restore Kubernetes cluster resources. +* [ark backup-location create](ark_backup-location_create.md) - Create a backup storage location +* [ark backup-location get](ark_backup-location_get.md) - Get backup storage locations + diff --git a/docs/cli-reference/ark_backup-location_create.md b/docs/cli-reference/ark_backup-location_create.md new file mode 100644 index 000000000..126c9dfd2 --- /dev/null +++ b/docs/cli-reference/ark_backup-location_create.md @@ -0,0 +1,45 @@ +## ark backup-location create + +Create a backup storage location + +### Synopsis + + +Create a backup storage location + +``` +ark backup-location create NAME [flags] +``` + +### Options + +``` + --bucket string name of the object storage bucket where backups should be stored + --config mapStringString configuration key-value pairs + -h, --help help for create + --label-columns stringArray a comma-separated list of labels to be displayed as columns + --labels mapStringString labels to apply to the backup storage location + -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'. + --prefix string prefix under which all Ark data should be stored within the bucket. Optional. + --provider string name of the backup storage provider (e.g. aws, azure, gcp) + --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 backup-location](ark_backup-location.md) - Work with backup storage locations + diff --git a/docs/cli-reference/ark_backup-location_get.md b/docs/cli-reference/ark_backup-location_get.md new file mode 100644 index 000000000..5f878f62f --- /dev/null +++ b/docs/cli-reference/ark_backup-location_get.md @@ -0,0 +1,41 @@ +## ark backup-location get + +Get backup storage locations + +### Synopsis + + +Get backup storage locations + +``` +ark backup-location 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 backup-location](ark_backup-location.md) - Work with backup storage locations + diff --git a/docs/cli-reference/ark_create.md b/docs/cli-reference/ark_create.md index fc7934f14..2676f1041 100644 --- a/docs/cli-reference/ark_create.md +++ b/docs/cli-reference/ark_create.md @@ -31,6 +31,7 @@ Create ark resources ### SEE ALSO * [ark](ark.md) - Back up and restore Kubernetes cluster resources. * [ark create backup](ark_create_backup.md) - Create a backup +* [ark create backup-location](ark_create_backup-location.md) - Create a backup storage location * [ark create restore](ark_create_restore.md) - Create a restore * [ark create schedule](ark_create_schedule.md) - Create a schedule diff --git a/docs/cli-reference/ark_create_backup-location.md b/docs/cli-reference/ark_create_backup-location.md new file mode 100644 index 000000000..96cb1ec46 --- /dev/null +++ b/docs/cli-reference/ark_create_backup-location.md @@ -0,0 +1,45 @@ +## ark create backup-location + +Create a backup storage location + +### Synopsis + + +Create a backup storage location + +``` +ark create backup-location NAME [flags] +``` + +### Options + +``` + --bucket string name of the object storage bucket where backups should be stored + --config mapStringString configuration key-value pairs + -h, --help help for backup-location + --label-columns stringArray a comma-separated list of labels to be displayed as columns + --labels mapStringString labels to apply to the backup storage location + -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'. + --prefix string prefix under which all Ark data should be stored within the bucket. Optional. + --provider string name of the backup storage provider (e.g. aws, azure, gcp) + --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 create](ark_create.md) - Create ark resources + diff --git a/docs/cli-reference/ark_get.md b/docs/cli-reference/ark_get.md index 4a91e8a66..e0a542ff0 100644 --- a/docs/cli-reference/ark_get.md +++ b/docs/cli-reference/ark_get.md @@ -30,6 +30,7 @@ Get ark resources ### SEE ALSO * [ark](ark.md) - Back up and restore Kubernetes cluster resources. +* [ark get backup-locations](ark_get_backup-locations.md) - Get backup storage locations * [ark get backups](ark_get_backups.md) - Get backups * [ark get restores](ark_get_restores.md) - Get restores * [ark get schedules](ark_get_schedules.md) - Get schedules diff --git a/docs/cli-reference/ark_get_backup-locations.md b/docs/cli-reference/ark_get_backup-locations.md new file mode 100644 index 000000000..4aa3a5061 --- /dev/null +++ b/docs/cli-reference/ark_get_backup-locations.md @@ -0,0 +1,41 @@ +## ark get backup-locations + +Get backup storage locations + +### Synopsis + + +Get backup storage locations + +``` +ark get backup-locations [flags] +``` + +### Options + +``` + -h, --help help for backup-locations + --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 get](ark_get.md) - Get ark resources + diff --git a/pkg/cmd/ark/ark.go b/pkg/cmd/ark/ark.go index f3c324484..ddf4532db 100644 --- a/pkg/cmd/ark/ark.go +++ b/pkg/cmd/ark/ark.go @@ -23,6 +23,7 @@ import ( "github.com/heptio/ark/pkg/client" "github.com/heptio/ark/pkg/cmd/cli/backup" + "github.com/heptio/ark/pkg/cmd/cli/backuplocation" "github.com/heptio/ark/pkg/cmd/cli/bug" cliclient "github.com/heptio/ark/pkg/cmd/cli/client" "github.com/heptio/ark/pkg/cmd/cli/completion" @@ -71,6 +72,7 @@ operations can also be performed as 'ark backup get' and 'ark schedule create'.` completion.NewCommand(), restic.NewCommand(f), bug.NewCommand(), + backuplocation.NewCommand(f), ) // add the glog flags diff --git a/pkg/cmd/cli/backuplocation/backup_location.go b/pkg/cmd/cli/backuplocation/backup_location.go new file mode 100644 index 000000000..8c0fd8b91 --- /dev/null +++ b/pkg/cmd/cli/backuplocation/backup_location.go @@ -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 backuplocation + +import ( + "github.com/spf13/cobra" + + "github.com/heptio/ark/pkg/client" +) + +func NewCommand(f client.Factory) *cobra.Command { + c := &cobra.Command{ + Use: "backup-location", + Short: "Work with backup storage locations", + Long: "Work with backup storage locations", + } + + c.AddCommand( + NewCreateCommand(f, "create"), + NewGetCommand(f, "get"), + ) + + return c +} diff --git a/pkg/cmd/cli/backuplocation/create.go b/pkg/cmd/cli/backuplocation/create.go new file mode 100644 index 000000000..d67a193b2 --- /dev/null +++ b/pkg/cmd/cli/backuplocation/create.go @@ -0,0 +1,134 @@ +/* +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 backuplocation + +import ( + "fmt" + + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + 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/flag" + "github.com/heptio/ark/pkg/cmd/util/output" +) + +func NewCreateCommand(f client.Factory, use string) *cobra.Command { + o := NewCreateOptions() + + c := &cobra.Command{ + Use: use + " NAME", + Short: "Create a backup storage location", + Args: cobra.ExactArgs(1), + Run: func(c *cobra.Command, args []string) { + cmd.CheckError(o.Complete(args, f)) + cmd.CheckError(o.Validate(c, args, f)) + cmd.CheckError(o.Run(c, f)) + }, + } + + o.BindFlags(c.Flags()) + output.BindFlags(c.Flags()) + output.ClearOutputFlagDefault(c) + + return c +} + +type CreateOptions struct { + Name string + Provider string + Bucket string + Prefix string + Config flag.Map + Labels flag.Map +} + +func NewCreateOptions() *CreateOptions { + return &CreateOptions{ + Config: flag.NewMap(), + } +} + +func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) { + flags.StringVar(&o.Provider, "provider", o.Provider, "name of the backup storage provider (e.g. aws, azure, gcp)") + flags.StringVar(&o.Bucket, "bucket", o.Bucket, "name of the object storage bucket where backups should be stored") + flags.StringVar(&o.Prefix, "prefix", o.Prefix, "prefix under which all Ark data should be stored within the bucket. Optional.") + flags.Var(&o.Config, "config", "configuration key-value pairs") + flags.Var(&o.Labels, "labels", "labels to apply to the backup storage location") +} + +func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Factory) error { + if err := output.ValidateFlags(c); err != nil { + return err + } + + if o.Provider == "" { + return errors.New("--provider is required") + } + + if o.Bucket == "" { + return errors.New("--bucket is required") + } + + return nil +} + +func (o *CreateOptions) Complete(args []string, f client.Factory) error { + o.Name = args[0] + return nil +} + +func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { + backupStorageLocation := &api.BackupStorageLocation{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: f.Namespace(), + Name: o.Name, + Labels: o.Labels.Data(), + }, + Spec: api.BackupStorageLocationSpec{ + Provider: o.Provider, + StorageType: api.StorageType{ + ObjectStorage: &api.ObjectStorageLocation{ + Bucket: o.Bucket, + Prefix: o.Prefix, + }, + }, + Config: o.Config.Data(), + }, + } + + if printed, err := output.PrintWithFormat(c, backupStorageLocation); printed || err != nil { + return err + } + + client, err := f.Client() + if err != nil { + return err + } + + if _, err := client.ArkV1().BackupStorageLocations(backupStorageLocation.Namespace).Create(backupStorageLocation); err != nil { + return errors.WithStack(err) + } + + fmt.Printf("Backup storage location %q configured successfully.\n", backupStorageLocation.Name) + return nil +} diff --git a/pkg/cmd/cli/backuplocation/get.go b/pkg/cmd/cli/backuplocation/get.go new file mode 100644 index 000000000..5573eea43 --- /dev/null +++ b/pkg/cmd/cli/backuplocation/get.go @@ -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 backuplocation + +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 backup storage locations", + Run: func(c *cobra.Command, args []string) { + err := output.ValidateFlags(c) + cmd.CheckError(err) + + arkClient, err := f.Client() + cmd.CheckError(err) + + var locations *api.BackupStorageLocationList + if len(args) > 0 { + locations = new(api.BackupStorageLocationList) + for _, name := range args { + location, err := arkClient.Ark().BackupStorageLocations(f.Namespace()).Get(name, metav1.GetOptions{}) + cmd.CheckError(err) + locations.Items = append(locations.Items, *location) + } + } else { + locations, err = arkClient.ArkV1().BackupStorageLocations(f.Namespace()).List(listOptions) + cmd.CheckError(err) + } + + _, err = output.PrintWithFormat(c, locations) + 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 +} diff --git a/pkg/cmd/cli/create/create.go b/pkg/cmd/cli/create/create.go index c22d2494d..83881dbdf 100644 --- a/pkg/cmd/cli/create/create.go +++ b/pkg/cmd/cli/create/create.go @@ -21,6 +21,7 @@ import ( "github.com/heptio/ark/pkg/client" "github.com/heptio/ark/pkg/cmd/cli/backup" + "github.com/heptio/ark/pkg/cmd/cli/backuplocation" "github.com/heptio/ark/pkg/cmd/cli/restore" "github.com/heptio/ark/pkg/cmd/cli/schedule" ) @@ -36,6 +37,7 @@ func NewCommand(f client.Factory) *cobra.Command { backup.NewCreateCommand(f, "backup"), schedule.NewCreateCommand(f, "schedule"), restore.NewCreateCommand(f, "restore"), + backuplocation.NewCreateCommand(f, "backup-location"), ) return c diff --git a/pkg/cmd/cli/get/get.go b/pkg/cmd/cli/get/get.go index ac565b72f..27b3eee55 100644 --- a/pkg/cmd/cli/get/get.go +++ b/pkg/cmd/cli/get/get.go @@ -21,6 +21,7 @@ import ( "github.com/heptio/ark/pkg/client" "github.com/heptio/ark/pkg/cmd/cli/backup" + "github.com/heptio/ark/pkg/cmd/cli/backuplocation" "github.com/heptio/ark/pkg/cmd/cli/restore" "github.com/heptio/ark/pkg/cmd/cli/schedule" ) @@ -41,10 +42,14 @@ func NewCommand(f client.Factory) *cobra.Command { restoreCommand := restore.NewGetCommand(f, "restores") restoreCommand.Aliases = []string{"restore"} + backupLocationCommand := backuplocation.NewGetCommand(f, "backup-locations") + backupLocationCommand.Aliases = []string{"backup-location"} + c.AddCommand( backupCommand, scheduleCommand, restoreCommand, + backupLocationCommand, ) return c diff --git a/pkg/cmd/util/output/backup_storage_location_printer.go b/pkg/cmd/util/output/backup_storage_location_printer.go new file mode 100644 index 000000000..7fa0d773e --- /dev/null +++ b/pkg/cmd/util/output/backup_storage_location_printer.go @@ -0,0 +1,71 @@ +/* +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 ( + backupStorageLocationColumns = []string{"NAME", "PROVIDER", "BUCKET/PREFIX"} +) + +func printBackupStorageLocationList(list *v1.BackupStorageLocationList, w io.Writer, options printers.PrintOptions) error { + for i := range list.Items { + if err := printBackupStorageLocation(&list.Items[i], w, options); err != nil { + return err + } + } + return nil +} + +func printBackupStorageLocation(location *v1.BackupStorageLocation, w io.Writer, options printers.PrintOptions) error { + name := printers.FormatResourceName(options.Kind, location.Name, options.WithKind) + + if options.WithNamespace { + if _, err := fmt.Fprintf(w, "%s\t", location.Namespace); err != nil { + return err + } + } + + bucketAndPrefix := location.Spec.ObjectStorage.Bucket + if location.Spec.ObjectStorage.Prefix != "" { + bucketAndPrefix += "/" + location.Spec.ObjectStorage.Prefix + } + + if _, err := fmt.Fprintf( + w, + "%s\t%s\t%s", + name, + location.Spec.Provider, + bucketAndPrefix, + ); err != nil { + return err + } + + if _, err := fmt.Fprint(w, printers.AppendLabels(location.Labels, options.ColumnLabels)); err != nil { + return err + } + + _, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, location.Labels)) + return err +} diff --git a/pkg/cmd/util/output/output.go b/pkg/cmd/util/output/output.go index de8d2433d..02c651054 100644 --- a/pkg/cmd/util/output/output.go +++ b/pkg/cmd/util/output/output.go @@ -143,6 +143,8 @@ func printTable(cmd *cobra.Command, obj runtime.Object) (bool, error) { printer.Handler(scheduleColumns, nil, printScheduleList) printer.Handler(resticRepoColumns, nil, printResticRepo) printer.Handler(resticRepoColumns, nil, printResticRepoList) + printer.Handler(backupStorageLocationColumns, nil, printBackupStorageLocation) + printer.Handler(backupStorageLocationColumns, nil, printBackupStorageLocationList) err = printer.PrintObj(obj, os.Stdout) if err != nil {