forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
printer.go
204 lines (180 loc) · 6.08 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package describe
import (
"fmt"
"io"
"strings"
kctl "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
buildapi "github.com/openshift/origin/pkg/build/api"
deployapi "github.com/openshift/origin/pkg/deploy/api"
imageapi "github.com/openshift/origin/pkg/image/api"
projectapi "github.com/openshift/origin/pkg/project/api"
routeapi "github.com/openshift/origin/pkg/route/api"
templateapi "github.com/openshift/origin/pkg/template/api"
)
var (
buildColumns = []string{"NAME", "TYPE", "STATUS", "POD"}
buildConfigColumns = []string{"NAME", "TYPE", "SOURCE"}
imageColumns = []string{"NAME", "DOCKER REF"}
imageRepositoryColumns = []string{"NAME", "DOCKER REPO", "TAGS"}
projectColumns = []string{"NAME", "DISPLAY NAME", "NAMESPACE"}
routeColumns = []string{"NAME", "HOST/PORT", "PATH", "SERVICE", "LABELS"}
deploymentColumns = []string{"NAME", "STATUS", "CAUSE"}
deploymentConfigColumns = []string{"NAME", "TRIGGERS", "LATEST VERSION"}
parameterColumns = []string{"NAME", "DESCRIPTION", "GENERATOR", "VALUE"}
)
func NewHumanReadablePrinter(noHeaders bool) *kctl.HumanReadablePrinter {
p := kctl.NewHumanReadablePrinter(noHeaders)
p.Handler(buildColumns, printBuild)
p.Handler(buildColumns, printBuildList)
p.Handler(buildConfigColumns, printBuildConfig)
p.Handler(buildConfigColumns, printBuildConfigList)
p.Handler(imageColumns, printImage)
p.Handler(imageColumns, printImageList)
p.Handler(imageRepositoryColumns, printImageRepository)
p.Handler(imageRepositoryColumns, printImageRepositoryList)
p.Handler(projectColumns, printProject)
p.Handler(projectColumns, printProjectList)
p.Handler(routeColumns, printRoute)
p.Handler(routeColumns, printRouteList)
p.Handler(deploymentColumns, printDeployment)
p.Handler(deploymentColumns, printDeploymentList)
p.Handler(deploymentConfigColumns, printDeploymentConfig)
p.Handler(deploymentConfigColumns, printDeploymentConfigList)
p.Handler(parameterColumns, printParameters)
return p
}
func printParameters(t *templateapi.Template, w io.Writer) error {
for _, p := range t.Parameters {
value := p.Value
if len(p.Generate) != 0 {
value = p.From
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", p.Name, p.Description, p.Generate, value)
if err != nil {
return err
}
}
return nil
}
func printBuild(build *buildapi.Build, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", build.Name, build.Parameters.Strategy.Type, build.Status, build.PodName)
return err
}
func printBuildList(buildList *buildapi.BuildList, w io.Writer) error {
for _, build := range buildList.Items {
if err := printBuild(&build, w); err != nil {
return err
}
}
return nil
}
func printBuildConfig(bc *buildapi.BuildConfig, w io.Writer) error {
if bc.Parameters.Strategy.Type == buildapi.CustomBuildStrategyType {
_, err := fmt.Fprintf(w, "%s\t%v\t%s\n", bc.Name, bc.Parameters.Strategy.Type, bc.Parameters.Strategy.CustomStrategy.Image)
return err
}
_, err := fmt.Fprintf(w, "%s\t%v\t%s\n", bc.Name, bc.Parameters.Strategy.Type, bc.Parameters.Source.Git.URI)
return err
}
func printBuildConfigList(buildList *buildapi.BuildConfigList, w io.Writer) error {
for _, buildConfig := range buildList.Items {
if err := printBuildConfig(&buildConfig, w); err != nil {
return err
}
}
return nil
}
func printImage(image *imageapi.Image, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\n", image.Name, image.DockerImageReference)
return err
}
func printImageList(images *imageapi.ImageList, w io.Writer) error {
for _, image := range images.Items {
if err := printImage(&image, w); err != nil {
return err
}
}
return nil
}
func printImageRepository(repo *imageapi.ImageRepository, w io.Writer) error {
tags := ""
if len(repo.Tags) > 0 {
var t []string
for tag := range repo.Tags {
t = append(t, tag)
}
tags = strings.Join(t, ",")
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\n", repo.Name, repo.Status.DockerImageRepository, tags)
return err
}
func printImageRepositoryList(repos *imageapi.ImageRepositoryList, w io.Writer) error {
for _, repo := range repos.Items {
if err := printImageRepository(&repo, w); err != nil {
return err
}
}
return nil
}
func printProject(project *projectapi.Project, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\n", project.Name, project.DisplayName, project.Namespace)
return err
}
func printProjectList(projects *projectapi.ProjectList, w io.Writer) error {
for _, project := range projects.Items {
if err := printProject(&project, w); err != nil {
return err
}
}
return nil
}
func printRoute(route *routeapi.Route, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", route.Name, route.Host, route.Path, route.ServiceName, labels.Set(route.Labels))
return err
}
func printRouteList(routeList *routeapi.RouteList, w io.Writer) error {
for _, route := range routeList.Items {
if err := printRoute(&route, w); err != nil {
return err
}
}
return nil
}
func printDeployment(d *deployapi.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 *deployapi.DeploymentList, w io.Writer) error {
for _, d := range list.Items {
if err := printDeployment(&d, w); err != nil {
return err
}
}
return nil
}
func printDeploymentConfig(dc *deployapi.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 *deployapi.DeploymentConfigList, w io.Writer) error {
for _, dc := range list.Items {
if err := printDeploymentConfig(&dc, w); err != nil {
return err
}
}
return nil
}