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