Add printer for snapshot locations

Signed-off-by: Wayne Witzel III <wayne@riotousliving.com>
pull/948/head
Wayne Witzel III 2018-09-20 11:02:22 -04:00 committed by Steve Kriss
parent ffc612ac13
commit aeb221eafe
2 changed files with 67 additions and 0 deletions

View File

@ -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 {

View File

@ -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
}