Skip to content

Commit 1fdcf8a

Browse files
author
OpenShift Bot
authored
Merge pull request #9896 from mfojtik/active-deployment
Merged by openshift-bot
2 parents 8c3efc0 + 3836743 commit 1fdcf8a

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

pkg/cmd/cli/describe/deployments.go

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ func (d *DeploymentConfigDescriber) Describe(namespace, name string, settings kc
7373

7474
return tabbedString(func(out *tabwriter.Writer) error {
7575
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+
}
7686

7787
if deploymentConfig.Status.LatestVersion == 0 {
7888
formatString(out, "Latest Version", "Not deployed")
@@ -83,34 +93,41 @@ func (d *DeploymentConfigDescriber) Describe(namespace, name string, settings kc
8393
printDeploymentConfigSpec(d.kubeClient, *deploymentConfig, out)
8494
fmt.Fprintln(out)
8595

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
93106
}
107+
}
108+
109+
if isNotDeployed {
110+
formatString(out, "Latest Deployment", "<none>")
94111
} else {
95112
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)
97116
}
117+
98118
// 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
114131
}
115132
}
116133
}

0 commit comments

Comments
 (0)