From aeb221eafe4ccaa979509038b70dcd4874002578 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Thu, 20 Sep 2018 11:02:22 -0400 Subject: [PATCH] Add printer for snapshot locations Signed-off-by: Wayne Witzel III --- pkg/cmd/util/output/output.go | 2 + .../volume_snapshot_location_printer.go | 65 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 pkg/cmd/util/output/volume_snapshot_location_printer.go diff --git a/pkg/cmd/util/output/output.go b/pkg/cmd/util/output/output.go index 02c651054a..3d6802e84d 100644 --- a/pkg/cmd/util/output/output.go +++ b/pkg/cmd/util/output/output.go @@ -145,6 +145,8 @@ func printTable(cmd *cobra.Command, obj runtime.Object) (bool, error) { printer.Handler(resticRepoColumns, nil, printResticRepoList) printer.Handler(backupStorageLocationColumns, nil, printBackupStorageLocation) printer.Handler(backupStorageLocationColumns, nil, printBackupStorageLocationList) + printer.Handler(volumeSnapshotLocationColumns, nil, printVolumeSnapshotLocation) + printer.Handler(volumeSnapshotLocationColumns, nil, printVolumeSnapshotLocationList) err = printer.PrintObj(obj, os.Stdout) if err != nil { diff --git a/pkg/cmd/util/output/volume_snapshot_location_printer.go b/pkg/cmd/util/output/volume_snapshot_location_printer.go new file mode 100644 index 0000000000..29d831d220 --- /dev/null +++ b/pkg/cmd/util/output/volume_snapshot_location_printer.go @@ -0,0 +1,65 @@ +/* +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 ( + volumeSnapshotLocationColumns = []string{"NAME", "PROVIDER"} +) + +func printVolumeSnapshotLocationList(list *v1.VolumeSnapshotLocationList, w io.Writer, options printers.PrintOptions) error { + for i := range list.Items { + if err := printVolumeSnapshotLocation(&list.Items[i], w, options); err != nil { + return err + } + } + return nil +} + +func printVolumeSnapshotLocation(location *v1.VolumeSnapshotLocation, 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 + } + } + + if _, err := fmt.Fprintf( + w, + "%s\t%s", + name, + location.Spec.Provider, + ); 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 +}