Skip to content

Commit 70e4bf6

Browse files
author
OpenShift Bot
authored
Merge pull request #11291 from kargakis/oc-status-fix
Merged by openshift-bot
2 parents 1b65aa5 + d18bc8e commit 70e4bf6

File tree

4 files changed

+168
-20
lines changed

4 files changed

+168
-20
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
apiVersion: v1
2+
items:
3+
- apiVersion: v1
4+
kind: DeploymentConfig
5+
metadata:
6+
name: example
7+
spec:
8+
replicas: 3
9+
selector:
10+
name: example
11+
strategy:
12+
type: Rolling
13+
template:
14+
metadata:
15+
labels:
16+
name: example
17+
spec:
18+
containers:
19+
- command:
20+
- /bin/sleep
21+
- "100"
22+
image: docker.io/centos:centos7
23+
name: myapp
24+
test: false
25+
triggers:
26+
- type: ConfigChange
27+
status:
28+
availableReplicas: 1
29+
details:
30+
causes:
31+
- type: ConfigChange
32+
message: config change
33+
latestVersion: 2
34+
replicas: 3
35+
updatedReplicas: 2
36+
- apiVersion: v1
37+
kind: ReplicationController
38+
metadata:
39+
annotations:
40+
openshift.io/deployer-pod.name: example-1-deploy
41+
openshift.io/deployment-config.latest-version: "1"
42+
openshift.io/deployment-config.name: example
43+
openshift.io/deployment.phase: Complete
44+
openshift.io/deployment.replicas: "1"
45+
openshift.io/deployment.status-reason: config change
46+
openshift.io/encoded-deployment-config: |
47+
{"kind":"DeploymentConfig","apiVersion":"v1","metadata":{"name":"example","namespace":"myproject","selfLink":"/oapi/v1/namespaces/myproject/deploymentconfigs/example","uid":"6d298d51-9486-11e6-b581-080027242396","resourceVersion":"1173","generation":2,"creationTimestamp":"2016-10-17T16:26:15Z"},"spec":{"strategy":{"type":"Rolling","rollingParams":{"updatePeriodSeconds":1,"intervalSeconds":1,"timeoutSeconds":600,"maxUnavailable":"25%","maxSurge":"25%","pre":{"failurePolicy":"Abort","execNewPod":{"command":["/bin/echo","test pre hook executed"],"containerName":"myapp"}}},"resources":{}},"triggers":[{"type":"ConfigChange"}],"replicas":1,"test":false,"selector":{"name":"example"},"template":{"metadata":{"creationTimestamp":null,"labels":{"name":"example"}},"spec":{"containers":[{"name":"myapp","image":"docker.io/centos:centos7","command":["/bin/sleep","100"],"resources":{},"terminationMessagePath":"/dev/termination-log","imagePullPolicy":"IfNotPresent"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","securityContext":{}}}},"status":{"latestVersion":1,"observedGeneration":1,"details":{"message":"config change","causes":[{"type":"ConfigChange"}]},"conditions":[{"type":"Available","status":"False","lastTransitionTime":"2016-10-17T16:26:15Z","message":"Deployment config does not have minimum availability."}]}}
48+
creationTimestamp: 2016-04-07T04:11:25Z
49+
generation: 2
50+
labels:
51+
openshift.io/deployment-config.name: example
52+
name: example-1
53+
spec:
54+
replicas: 2
55+
selector:
56+
deployment: example-1
57+
deploymentconfig: example
58+
name: example
59+
template:
60+
metadata:
61+
annotations:
62+
openshift.io/deployment-config.latest-version: "1"
63+
openshift.io/deployment-config.name: example
64+
openshift.io/deployment.name: example-1
65+
creationTimestamp: null
66+
labels:
67+
deployment: example-1
68+
deploymentconfig: example
69+
name: example
70+
spec:
71+
containers:
72+
- command:
73+
- /bin/sleep
74+
- "100"
75+
image: docker.io/centos:centos7
76+
imagePullPolicy: IfNotPresent
77+
name: myapp
78+
status:
79+
fullyLabeledReplicas: 2
80+
observedGeneration: 2
81+
readyReplicas: 1
82+
replicas: 2
83+
- apiVersion: v1
84+
kind: ReplicationController
85+
metadata:
86+
annotations:
87+
openshift.io/deployer-pod.name: example-2-deploy
88+
openshift.io/deployment-config.latest-version: "2"
89+
openshift.io/deployment-config.name: example
90+
openshift.io/deployment.phase: Running
91+
openshift.io/deployment.replicas: "3"
92+
openshift.io/deployment.status-reason: manual change
93+
openshift.io/encoded-deployment-config: |
94+
{"kind":"DeploymentConfig","apiVersion":"v1","metadata":{"name":"example","namespace":"myproject","selfLink":"/oapi/v1/namespaces/myproject/deploymentconfigs/example","uid":"6d298d51-9486-11e6-b581-080027242396","resourceVersion":"1314","generation":5,"creationTimestamp":"2016-10-17T16:26:15Z"},"spec":{"strategy":{"type":"Rolling","rollingParams":{"updatePeriodSeconds":1,"intervalSeconds":1,"timeoutSeconds":600,"maxUnavailable":"25%","maxSurge":"25%"},"resources":{}},"triggers":[{"type":"ConfigChange"}],"replicas":3,"test":false,"selector":{"name":"example"},"template":{"metadata":{"creationTimestamp":null,"labels":{"name":"example"}},"spec":{"containers":[{"name":"myapp","image":"docker.io/centos:centos7","command":["/bin/sleep","100"],"resources":{},"terminationMessagePath":"/dev/termination-log","imagePullPolicy":"IfNotPresent"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","securityContext":{}}}},"status":{"latestVersion":2,"observedGeneration":4,"replicas":3,"updatedReplicas":3,"availableReplicas":2,"unavailableReplicas":1,"details":{"message":"manual change","causes":[{"type":"Manual"}]},"conditions":[{"type":"Available","status":"False","lastTransitionTime":"2016-10-17T16:29:55Z","message":"Deployment config does not have minimum availability."},{"type":"Progressing","status":"True","lastTransitionTime":"2016-10-17T16:29:55Z","reason":"NewReplicationControllerAvailable","message":"Replication controller \"example-1\" has completed progressing"}]}}
95+
creationTimestamp: 2016-04-07T04:11:55Z
96+
generation: 4
97+
labels:
98+
openshift.io/deployment-config.name: example
99+
name: example-2
100+
spec:
101+
replicas: 1
102+
selector:
103+
deployment: example-2
104+
deploymentconfig: example
105+
name: example
106+
template:
107+
metadata:
108+
annotations:
109+
openshift.io/deployment-config.latest-version: "2"
110+
openshift.io/deployment-config.name: example
111+
openshift.io/deployment.name: example-2
112+
creationTimestamp: null
113+
labels:
114+
deployment: example-2
115+
deploymentconfig: example
116+
name: example
117+
spec:
118+
containers:
119+
- command:
120+
- /bin/sleep
121+
- "100"
122+
image: docker.io/centos:centos7
123+
imagePullPolicy: IfNotPresent
124+
name: myapp
125+
status:
126+
fullyLabeledReplicas: 1
127+
readyReplicas: 0
128+
replicas: 1
129+
kind: List
130+
metadata: {}

pkg/api/graph/test/new-project-deployed-app.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ items:
130130
restartPolicy: Always
131131
status:
132132
replicas: 2
133+
readyReplicas: 2
133134
- apiVersion: v1
134135
kind: ReplicationController
135136
metadata:
@@ -187,6 +188,7 @@ items:
187188
restartPolicy: Always
188189
status:
189190
replicas: 1
191+
readyReplicas: 1
190192
- apiVersion: v1
191193
kind: DeploymentConfig
192194
metadata:
@@ -362,6 +364,7 @@ items:
362364
restartPolicy: Always
363365
status:
364366
replicas: 1
367+
readyReplicas: 1
365368
- apiVersion: v1
366369
kind: DeploymentConfig
367370
metadata:

pkg/cmd/cli/describe/projectstatus.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,52 +1013,53 @@ func describeDeployments(f formatter, dcNode *deploygraph.DeploymentConfigNode,
10131013
return out
10141014
}
10151015

1016-
func describeDeploymentStatus(deploy *kapi.ReplicationController, first, test bool, restartCount int32) string {
1017-
timeAt := strings.ToLower(formatRelativeTime(deploy.CreationTimestamp.Time))
1018-
status := deployutil.DeploymentStatusFor(deploy)
1019-
version := deployutil.DeploymentVersionFor(deploy)
1016+
func describeDeploymentStatus(rc *kapi.ReplicationController, first, test bool, restartCount int32) string {
1017+
timeAt := strings.ToLower(formatRelativeTime(rc.CreationTimestamp.Time))
1018+
status := deployutil.DeploymentStatusFor(rc)
1019+
version := deployutil.DeploymentVersionFor(rc)
10201020
maybeCancelling := ""
1021-
if deployutil.IsDeploymentCancelled(deploy) && !deployutil.IsTerminatedDeployment(deploy) {
1021+
if deployutil.IsDeploymentCancelled(rc) && !deployutil.IsTerminatedDeployment(rc) {
10221022
maybeCancelling = " (cancelling)"
10231023
}
10241024

10251025
switch status {
10261026
case deployapi.DeploymentStatusFailed:
1027-
reason := deployutil.DeploymentStatusReasonFor(deploy)
1027+
reason := deployutil.DeploymentStatusReasonFor(rc)
10281028
if len(reason) > 0 {
10291029
reason = fmt.Sprintf(": %s", reason)
10301030
}
10311031
// TODO: encode fail time in the rc
1032-
return fmt.Sprintf("deployment #%d failed %s ago%s%s", version, timeAt, reason, describePodSummaryInline(deploy.Status.Replicas, deploy.Spec.Replicas, false, restartCount))
1032+
return fmt.Sprintf("deployment #%d failed %s ago%s%s", version, timeAt, reason, describePodSummaryInline(rc.Status.ReadyReplicas, rc.Status.Replicas, rc.Spec.Replicas, false, restartCount))
10331033
case deployapi.DeploymentStatusComplete:
10341034
// TODO: pod status output
10351035
if test {
10361036
return fmt.Sprintf("test deployment #%d deployed %s ago", version, timeAt)
10371037
}
1038-
return fmt.Sprintf("deployment #%d deployed %s ago%s", version, timeAt, describePodSummaryInline(deploy.Status.Replicas, deploy.Spec.Replicas, first, restartCount))
1038+
return fmt.Sprintf("deployment #%d deployed %s ago%s", version, timeAt, describePodSummaryInline(rc.Status.ReadyReplicas, rc.Status.Replicas, rc.Spec.Replicas, first, restartCount))
10391039
case deployapi.DeploymentStatusRunning:
10401040
format := "deployment #%d running%s for %s%s"
10411041
if test {
10421042
format = "test deployment #%d running%s for %s%s"
10431043
}
1044-
return fmt.Sprintf(format, version, maybeCancelling, timeAt, describePodSummaryInline(deploy.Status.Replicas, deploy.Spec.Replicas, false, restartCount))
1044+
return fmt.Sprintf(format, version, maybeCancelling, timeAt, describePodSummaryInline(rc.Status.ReadyReplicas, rc.Status.Replicas, rc.Spec.Replicas, false, restartCount))
10451045
default:
1046-
return fmt.Sprintf("deployment #%d %s%s %s ago%s", version, strings.ToLower(string(status)), maybeCancelling, timeAt, describePodSummaryInline(deploy.Status.Replicas, deploy.Spec.Replicas, false, restartCount))
1046+
return fmt.Sprintf("deployment #%d %s%s %s ago%s", version, strings.ToLower(string(status)), maybeCancelling, timeAt, describePodSummaryInline(rc.Status.ReadyReplicas, rc.Status.Replicas, rc.Spec.Replicas, false, restartCount))
10471047
}
10481048
}
10491049

10501050
func describePetSetStatus(p *kapps.PetSet) string {
10511051
timeAt := strings.ToLower(formatRelativeTime(p.CreationTimestamp.Time))
1052-
return fmt.Sprintf("created %s ago%s", timeAt, describePodSummaryInline(int32(p.Status.Replicas), int32(p.Spec.Replicas), false, 0))
1052+
// TODO: Replace first argument in describePodSummaryInline with ReadyReplicas once that's a thing for pet sets.
1053+
return fmt.Sprintf("created %s ago%s", timeAt, describePodSummaryInline(int32(p.Status.Replicas), int32(p.Status.Replicas), int32(p.Spec.Replicas), false, 0))
10531054
}
10541055

10551056
func describeRCStatus(rc *kapi.ReplicationController) string {
10561057
timeAt := strings.ToLower(formatRelativeTime(rc.CreationTimestamp.Time))
1057-
return fmt.Sprintf("rc/%s created %s ago%s", rc.Name, timeAt, describePodSummaryInline(rc.Status.Replicas, rc.Spec.Replicas, false, 0))
1058+
return fmt.Sprintf("rc/%s created %s ago%s", rc.Name, timeAt, describePodSummaryInline(rc.Status.ReadyReplicas, rc.Status.Replicas, rc.Spec.Replicas, false, 0))
10581059
}
10591060

1060-
func describePodSummaryInline(actual, requested int32, includeEmpty bool, restartCount int32) string {
1061-
s := describePodSummary(actual, requested, includeEmpty, restartCount)
1061+
func describePodSummaryInline(ready, actual, requested int32, includeEmpty bool, restartCount int32) string {
1062+
s := describePodSummary(ready, requested, includeEmpty, restartCount)
10621063
if len(s) == 0 {
10631064
return s
10641065
}
@@ -1072,25 +1073,25 @@ func describePodSummaryInline(actual, requested int32, includeEmpty bool, restar
10721073
return fmt.Sprintf(" - %s%s", s, change)
10731074
}
10741075

1075-
func describePodSummary(actual, requested int32, includeEmpty bool, restartCount int32) string {
1076+
func describePodSummary(ready, requested int32, includeEmpty bool, restartCount int32) string {
10761077
var restartWarn string
10771078
if restartCount > 0 {
10781079
restartWarn = fmt.Sprintf(" (warning: %d restarts)", restartCount)
10791080
}
1080-
if actual == requested {
1081+
if ready == requested {
10811082
switch {
1082-
case actual == 0:
1083+
case ready == 0:
10831084
if !includeEmpty {
10841085
return ""
10851086
}
10861087
return "0 pods"
1087-
case actual > 1:
1088-
return fmt.Sprintf("%d pods", actual) + restartWarn
1088+
case ready > 1:
1089+
return fmt.Sprintf("%d pods", ready) + restartWarn
10891090
default:
10901091
return "1 pod" + restartWarn
10911092
}
10921093
}
1093-
return fmt.Sprintf("%d/%d pods", actual, requested) + restartWarn
1094+
return fmt.Sprintf("%d/%d pods", ready, requested) + restartWarn
10941095
}
10951096

10961097
func describeDeploymentConfigTriggers(config *deployapi.DeploymentConfig) (string, bool) {

pkg/cmd/cli/describe/projectstatus_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,20 @@ func TestProjectStatus(t *testing.T) {
367367
`View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.`,
368368
},
369369
},
370+
"deployment with unavailable pods": {
371+
File: "available-deployment.yaml",
372+
Extra: []runtime.Object{
373+
&projectapi.Project{
374+
ObjectMeta: kapi.ObjectMeta{Name: "example", Namespace: ""},
375+
},
376+
},
377+
ErrFn: func(err error) bool { return err == nil },
378+
Contains: []string{
379+
"deployment #2 running for 30 seconds - 0/1 pods\n",
380+
"deployment #1 deployed about a minute ago - 1/2 pods",
381+
},
382+
Time: mustParseTime("2016-04-07T04:12:25Z"),
383+
},
370384
}
371385
oldTimeFn := timeNowFn
372386
defer func() { timeNowFn = oldTimeFn }()

0 commit comments

Comments
 (0)