Skip to content

Commit aeb221e

Browse files
Wayne Witzel IIIskriss
authored andcommitted
Add printer for snapshot locations
Signed-off-by: Wayne Witzel III <wayne@riotousliving.com>
1 parent ffc612a commit aeb221e

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

pkg/cmd/util/output/output.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ func printTable(cmd *cobra.Command, obj runtime.Object) (bool, error) {
145145
printer.Handler(resticRepoColumns, nil, printResticRepoList)
146146
printer.Handler(backupStorageLocationColumns, nil, printBackupStorageLocation)
147147
printer.Handler(backupStorageLocationColumns, nil, printBackupStorageLocationList)
148+
printer.Handler(volumeSnapshotLocationColumns, nil, printVolumeSnapshotLocation)
149+
printer.Handler(volumeSnapshotLocationColumns, nil, printVolumeSnapshotLocationList)
148150

149151
err = printer.PrintObj(obj, os.Stdout)
150152
if err != nil {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Copyright 2018 the Heptio Ark contributors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package output
18+
19+
import (
20+
"fmt"
21+
"io"
22+
23+
"k8s.io/kubernetes/pkg/printers"
24+
25+
"github.com/heptio/ark/pkg/apis/ark/v1"
26+
)
27+
28+
var (
29+
volumeSnapshotLocationColumns = []string{"NAME", "PROVIDER"}
30+
)
31+
32+
func printVolumeSnapshotLocationList(list *v1.VolumeSnapshotLocationList, w io.Writer, options printers.PrintOptions) error {
33+
for i := range list.Items {
34+
if err := printVolumeSnapshotLocation(&list.Items[i], w, options); err != nil {
35+
return err
36+
}
37+
}
38+
return nil
39+
}
40+
41+
func printVolumeSnapshotLocation(location *v1.VolumeSnapshotLocation, w io.Writer, options printers.PrintOptions) error {
42+
name := printers.FormatResourceName(options.Kind, location.Name, options.WithKind)
43+
44+
if options.WithNamespace {
45+
if _, err := fmt.Fprintf(w, "%s\t", location.Namespace); err != nil {
46+
return err
47+
}
48+
}
49+
50+
if _, err := fmt.Fprintf(
51+
w,
52+
"%s\t%s",
53+
name,
54+
location.Spec.Provider,
55+
); err != nil {
56+
return err
57+
}
58+
59+
if _, err := fmt.Fprint(w, printers.AppendLabels(location.Labels, options.ColumnLabels)); err != nil {
60+
return err
61+
}
62+
63+
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, location.Labels))
64+
return err
65+
}

0 commit comments

Comments
 (0)