@@ -29,13 +29,15 @@ type DeploymentConfigDescriber struct {
29
29
type deploymentDescriberClient interface {
30
30
getDeploymentConfig (namespace , name string ) (* deployapi.DeploymentConfig , error )
31
31
getDeployment (namespace , name string ) (* kapi.ReplicationController , error )
32
+ listDeployments (namespace string , selector labels.Selector ) (* kapi.ReplicationControllerList , error )
32
33
listPods (namespace string , selector labels.Selector ) (* kapi.PodList , error )
33
34
listEvents (deploymentConfig * deployapi.DeploymentConfig ) (* kapi.EventList , error )
34
35
}
35
36
36
37
type genericDeploymentDescriberClient struct {
37
38
getDeploymentConfigFunc func (namespace , name string ) (* deployapi.DeploymentConfig , error )
38
39
getDeploymentFunc func (namespace , name string ) (* kapi.ReplicationController , error )
40
+ listDeploymentsFunc func (namespace string , selector labels.Selector ) (* kapi.ReplicationControllerList , error )
39
41
listPodsFunc func (namespace string , selector labels.Selector ) (* kapi.PodList , error )
40
42
listEventsFunc func (deploymentConfig * deployapi.DeploymentConfig ) (* kapi.EventList , error )
41
43
}
@@ -48,6 +50,10 @@ func (c *genericDeploymentDescriberClient) getDeployment(namespace, name string)
48
50
return c .getDeploymentFunc (namespace , name )
49
51
}
50
52
53
+ func (c * genericDeploymentDescriberClient ) listDeployments (namespace string , selector labels.Selector ) (* kapi.ReplicationControllerList , error ) {
54
+ return c .listDeploymentsFunc (namespace , selector )
55
+ }
56
+
51
57
func (c * genericDeploymentDescriberClient ) listPods (namespace string , selector labels.Selector ) (* kapi.PodList , error ) {
52
58
return c .listPodsFunc (namespace , selector )
53
59
}
@@ -253,19 +259,24 @@ func getPodStatusForDeployment(deployment *kapi.ReplicationController, client de
253
259
return
254
260
}
255
261
256
- type LatestDeploymentDescriber struct {
262
+ type LatestDeploymentsDescriber struct {
263
+ size int
257
264
client deploymentDescriberClient
258
265
}
259
266
260
- func NewLatestDeploymentDescriber (client client.Interface , kclient kclient.Interface ) * LatestDeploymentDescriber {
261
- return & LatestDeploymentDescriber {
267
+ func NewLatestDeploymentsDescriber (client client.Interface , kclient kclient.Interface , size int ) * LatestDeploymentsDescriber {
268
+ return & LatestDeploymentsDescriber {
269
+ size : size ,
262
270
client : & genericDeploymentDescriberClient {
263
271
getDeploymentConfigFunc : func (namespace , name string ) (* deployapi.DeploymentConfig , error ) {
264
272
return client .DeploymentConfigs (namespace ).Get (name )
265
273
},
266
274
getDeploymentFunc : func (namespace , name string ) (* kapi.ReplicationController , error ) {
267
275
return kclient .ReplicationControllers (namespace ).Get (name )
268
276
},
277
+ listDeploymentsFunc : func (namespace string , selector labels.Selector ) (* kapi.ReplicationControllerList , error ) {
278
+ return kclient .ReplicationControllers (namespace ).List (selector )
279
+ },
269
280
listPodsFunc : func (namespace string , selector labels.Selector ) (* kapi.PodList , error ) {
270
281
return kclient .Pods (namespace ).List (selector , fields .Everything ())
271
282
},
@@ -276,66 +287,56 @@ func NewLatestDeploymentDescriber(client client.Interface, kclient kclient.Inter
276
287
}
277
288
}
278
289
279
- func (d * LatestDeploymentDescriber ) Describe (namespace , name string ) (string , error ) {
290
+ func (d * LatestDeploymentsDescriber ) Describe (namespace , name string ) (string , error ) {
280
291
config , err := d .client .getDeploymentConfig (namespace , name )
281
292
if err != nil {
282
293
return "" , err
283
294
}
284
295
285
- deploymentName := deployutil .LatestDeploymentNameForConfig (config )
286
- deployment , err := d .client .getDeployment (config .Namespace , deploymentName )
287
- if err != nil && ! kerrors .IsNotFound (err ) {
288
- return "" , err
296
+ var deployments []kapi.ReplicationController
297
+ if d .size > 1 {
298
+ list , err := d .client .listDeployments (namespace , labels .Everything ())
299
+ if err != nil && ! kerrors .IsNotFound (err ) {
300
+ return "" , err
301
+ }
302
+ deployments = list .Items
303
+ } else {
304
+ deploymentName := deployutil .LatestDeploymentNameForConfig (config )
305
+ deployment , err := d .client .getDeployment (config .Namespace , deploymentName )
306
+ if err != nil && ! kerrors .IsNotFound (err ) {
307
+ return "" , err
308
+ }
309
+ if deployment != nil {
310
+ deployments = []kapi.ReplicationController {* deployment }
311
+ }
289
312
}
290
313
291
314
g := graph .New ()
292
315
deploy := graph .DeploymentConfig (g , config )
293
- if deployment != nil {
294
- graph .JoinDeployments (deploy .(* graph.DeploymentConfigNode ), []kapi. ReplicationController { * deployment } )
316
+ if len ( deployments ) > 0 {
317
+ graph .JoinDeployments (deploy .(* graph.DeploymentConfigNode ), deployments )
295
318
}
296
319
297
320
return tabbedString (func (out * tabwriter.Writer ) error {
298
321
indent := " "
299
- fmt .Fprintf (out , "Latest deployment for %s/%s:\n " , namespace , name )
300
- printLines (out , indent , 1 , d .describeDeployment (deploy .(* graph.DeploymentConfigNode ))... )
322
+ node := deploy .(* graph.DeploymentConfigNode )
323
+ nDeployments := len (node .Deployments ) + 1
324
+ var msg string
325
+ if d .size == 1 || nDeployments == 1 {
326
+ msg = fmt .Sprintf ("Latest deployment for %s/%s:\n " , namespace , name )
327
+ } else {
328
+ if nDeployments > d .size {
329
+ msg = fmt .Sprintf ("Latest %v deployments for %s/%s:\n " , d .size , namespace , name )
330
+ } else {
331
+ msg = fmt .Sprintf ("All %v deployments for %s/%s:\n " , nDeployments , namespace , name )
332
+ }
333
+ }
334
+ descriptions := describeDeployments (node , d .size )
335
+ printLines (out , indent , 0 , append ([]string {msg }, descriptions ... )... )
301
336
return nil
302
337
})
303
338
}
304
339
305
- func (d * LatestDeploymentDescriber ) describeDeployment (node * graph.DeploymentConfigNode ) []string {
306
- if node == nil {
307
- return nil
308
- }
309
- out := []string {}
310
-
311
- if node .ActiveDeployment == nil {
312
- on , auto := describeDeploymentConfigTriggers (node .DeploymentConfig )
313
- if node .DeploymentConfig .LatestVersion == 0 {
314
- out = append (out , fmt .Sprintf ("#1 waiting %s. Run osc deploy --latest to deploy now." , on ))
315
- } else if auto {
316
- out = append (out , fmt .Sprintf ("#%d pending %s. Run osc deploy --latest to deploy now." , node .DeploymentConfig .LatestVersion , on ))
317
- }
318
- // TODO: detect new image available?
319
- } else {
320
- out = append (out , d .describeDeploymentStatus (node .ActiveDeployment ))
321
- }
322
- return out
323
- }
324
-
325
- func (d * LatestDeploymentDescriber ) describeDeploymentStatus (deploy * kapi.ReplicationController ) string {
326
- timeAt := strings .ToLower (formatRelativeTime (deploy .CreationTimestamp .Time ))
327
- switch s := deploy .Annotations [deployapi .DeploymentStatusAnnotation ]; deployapi .DeploymentStatus (s ) {
328
- case deployapi .DeploymentStatusFailed :
329
- // TODO: encode fail time in the rc
330
- return fmt .Sprintf ("#%s failed %s ago. You can restart this deployment with osc deploy --retry." , deploy .Annotations [deployapi .DeploymentVersionAnnotation ], timeAt )
331
- case deployapi .DeploymentStatusComplete :
332
- // TODO: pod status output
333
- return fmt .Sprintf ("#%s deployed %s ago" , deploy .Annotations [deployapi .DeploymentVersionAnnotation ], timeAt )
334
- default :
335
- return fmt .Sprintf ("#%s deployment %s %s ago" , deploy .Annotations [deployapi .DeploymentVersionAnnotation ], strings .ToLower (s ), timeAt )
336
- }
337
- }
338
-
339
340
// DeploymentDescriber generates information about a deployment
340
341
// DEPRECATED.
341
342
type DeploymentDescriber struct {
0 commit comments