-
Notifications
You must be signed in to change notification settings - Fork 0
/
printer.go
65 lines (54 loc) · 1.74 KB
/
printer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package client
import (
"fmt"
"io"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/openshift/origin/pkg/deploy/api"
)
var deploymentColumns = []string{"Name", "Status", "Cause"}
var deploymentConfigColumns = []string{"Name", "Triggers", "LatestVersion"}
// RegisterPrintHandlers registers human-readable printers for deploy types.
func RegisterPrintHandlers(printer *kubectl.HumanReadablePrinter) {
printer.Handler(deploymentColumns, printDeployment)
printer.Handler(deploymentColumns, printDeploymentList)
printer.Handler(deploymentConfigColumns, printDeploymentConfig)
printer.Handler(deploymentConfigColumns, printDeploymentConfigList)
}
func printDeployment(d *api.Deployment, w io.Writer) error {
causes := util.StringSet{}
if d.Details != nil {
for _, cause := range d.Details.Causes {
causes.Insert(string(cause.Type))
}
}
cStr := strings.Join(causes.List(), ", ")
_, err := fmt.Fprintf(w, "%s\t%s\t%s\n", d.Name, d.Status, cStr)
return err
}
func printDeploymentList(list *api.DeploymentList, w io.Writer) error {
for _, d := range list.Items {
if err := printDeployment(&d, w); err != nil {
return err
}
}
return nil
}
func printDeploymentConfig(dc *api.DeploymentConfig, w io.Writer) error {
triggers := util.StringSet{}
for _, trigger := range dc.Triggers {
triggers.Insert(string(trigger.Type))
}
tStr := strings.Join(triggers.List(), ", ")
_, err := fmt.Fprintf(w, "%s\t%s\t%v\n", dc.Name, tStr, dc.LatestVersion)
return err
}
func printDeploymentConfigList(list *api.DeploymentConfigList, w io.Writer) error {
for _, dc := range list.Items {
if err := printDeploymentConfig(&dc, w); err != nil {
return err
}
}
return nil
}