Skip to content

Commit

Permalink
Add printer for snapshot locations
Browse files Browse the repository at this point in the history
Signed-off-by: Wayne Witzel III <wayne@riotousliving.com>
  • Loading branch information
wwitzel3 authored and skriss committed Oct 17, 2018
1 parent ffc612a commit aeb221e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/cmd/util/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
65 changes: 65 additions & 0 deletions pkg/cmd/util/output/volume_snapshot_location_printer.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit aeb221e

Please sign in to comment.