@@ -73,6 +73,16 @@ func (d *DeploymentConfigDescriber) Describe(namespace, name string, settings kc
73
73
74
74
return tabbedString (func (out * tabwriter.Writer ) error {
75
75
formatMeta (out , deploymentConfig .ObjectMeta )
76
+ var (
77
+ deploymentsHistory []kapi.ReplicationController
78
+ activeDeploymentName string
79
+ )
80
+
81
+ if d .config == nil {
82
+ if rcs , err := d .kubeClient .ReplicationControllers (namespace ).List (kapi.ListOptions {LabelSelector : deployutil .ConfigSelector (deploymentConfig .Name )}); err == nil {
83
+ deploymentsHistory = rcs .Items
84
+ }
85
+ }
76
86
77
87
if deploymentConfig .Status .LatestVersion == 0 {
78
88
formatString (out , "Latest Version" , "Not deployed" )
@@ -83,34 +93,41 @@ func (d *DeploymentConfigDescriber) Describe(namespace, name string, settings kc
83
93
printDeploymentConfigSpec (d .kubeClient , * deploymentConfig , out )
84
94
fmt .Fprintln (out )
85
95
86
- deploymentName := deployutil .LatestDeploymentNameForConfig (deploymentConfig )
87
- deployment , err := d .kubeClient .ReplicationControllers (namespace ).Get (deploymentName )
88
- if err != nil {
89
- if kerrors .IsNotFound (err ) {
90
- formatString (out , "Latest Deployment" , "<none>" )
91
- } else {
92
- formatString (out , "Latest Deployment" , fmt .Sprintf ("error: %v" , err ))
96
+ latestDeploymentName := deployutil .LatestDeploymentNameForConfig (deploymentConfig )
97
+ if activeDeployment := deployutil .ActiveDeployment (deploymentConfig , deploymentsHistory ); activeDeployment != nil {
98
+ activeDeploymentName = activeDeployment .Name
99
+ }
100
+
101
+ var deployment * kapi.ReplicationController
102
+ isNotDeployed := len (deploymentsHistory ) == 0
103
+ for _ , item := range deploymentsHistory {
104
+ if item .Name == latestDeploymentName {
105
+ deployment = & item
93
106
}
107
+ }
108
+
109
+ if isNotDeployed {
110
+ formatString (out , "Latest Deployment" , "<none>" )
94
111
} else {
95
112
header := fmt .Sprintf ("Deployment #%d (latest)" , deployutil .DeploymentVersionFor (deployment ))
96
- printDeploymentRc (deployment , d .kubeClient , out , header , true )
113
+ // Show details if the current deployment is the active one or it is the
114
+ // initial deployment.
115
+ printDeploymentRc (deployment , d .kubeClient , out , header , (deployment .Name == activeDeploymentName ) || len (deploymentsHistory ) == 1 )
97
116
}
117
+
98
118
// We don't show the deployment history when running `oc rollback --dry-run`.
99
- if d .config == nil {
100
- deploymentsHistory , err := d .kubeClient .ReplicationControllers (namespace ).List (kapi.ListOptions {LabelSelector : labels .Everything ()})
101
- if err == nil {
102
- sorted := deploymentsHistory .Items
103
- sort .Sort (sort .Reverse (rcutils .OverlappingControllers (sorted )))
104
- counter := 1
105
- for _ , item := range sorted {
106
- if item .Name != deploymentName && deploymentConfig .Name == deployutil .DeploymentConfigNameFor (& item ) {
107
- header := fmt .Sprintf ("Deployment #%d" , deployutil .DeploymentVersionFor (& item ))
108
- printDeploymentRc (& item , d .kubeClient , out , header , false )
109
- counter ++
110
- }
111
- if counter == maxDisplayDeployments {
112
- break
113
- }
119
+ if d .config == nil && ! isNotDeployed {
120
+ sorted := deploymentsHistory
121
+ sort .Sort (sort .Reverse (rcutils .OverlappingControllers (sorted )))
122
+ counter := 1
123
+ for _ , item := range sorted {
124
+ if item .Name != latestDeploymentName && deploymentConfig .Name == deployutil .DeploymentConfigNameFor (& item ) {
125
+ header := fmt .Sprintf ("Deployment #%d" , deployutil .DeploymentVersionFor (& item ))
126
+ printDeploymentRc (& item , d .kubeClient , out , header , item .Name == activeDeploymentName )
127
+ counter ++
128
+ }
129
+ if counter == maxDisplayDeployments {
130
+ break
114
131
}
115
132
}
116
133
}
0 commit comments