Skip to content

Commit fb1679e

Browse files
committed
apps: record cause of rollout and deployer pods timestamps back to rc
1 parent bd5b800 commit fb1679e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

pkg/apps/apis/apps/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ const (
3737
// annotation value is the name of the deployer Pod which will act upon the ReplicationController
3838
// to implement the deployment behavior.
3939
DeploymentPodAnnotation = "openshift.io/deployer-pod.name"
40+
// DeployerPodCreatedAtAnnotation is an annotation on a deployment that
41+
// records the time in RFC3339 format of when the deployer pod for this particular
42+
// deployment was created.
43+
DeployerPodCreatedAtAnnotation = "openshift.io/deployer-pod.created-at"
44+
// DeployerPodStartedAtAnnotation is an annotation on a deployment that
45+
// records the time in RFC3339 format of when the deployer pod for this particular
46+
// deployment was started.
47+
DeployerPodStartedAtAnnotation = "openshift.io/deployer-pod.started-at"
48+
// DeployerPodCompletedAtAnnotation is an annotation on deployment that records
49+
// the time in RFC3339 format of when the deployer pod finished.
50+
DeployerPodCompletedAtAnnotation = "openshift.io/deployer-pod.completed-at"
4051
// DeploymentIgnorePodAnnotation is an annotation on a deployment config that will bypass creating
4152
// a deployment pod with the deployment. The caller is responsible for setting the deployment
4253
// status and running the deployment process.

pkg/apps/controller/deployer/deployer_controller.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ func (c *DeploymentController) handle(deployment *v1.ReplicationController, will
149149
return actionableError(fmt.Sprintf("couldn't create deployer pod for %q: %v", deployutil.LabelForDeploymentV1(deployment), err))
150150
}
151151
updatedAnnotations[deployapi.DeploymentPodAnnotation] = deploymentPod.Name
152+
updatedAnnotations[deployapi.DeployerPodCreatedAtAnnotation] = deploymentPod.CreationTimestamp.String()
153+
if deploymentPod.Status.StartTime != nil {
154+
updatedAnnotations[deployapi.DeployerPodStartedAtAnnotation] = deploymentPod.Status.StartTime.String()
155+
}
152156
nextStatus = deployapi.DeploymentStatusPending
153157
glog.V(4).Infof("Created deployer pod %q for %q", deploymentPod.Name, deployutil.LabelForDeploymentV1(deployment))
154158

@@ -176,6 +180,10 @@ func (c *DeploymentController) handle(deployment *v1.ReplicationController, will
176180
} else {
177181
// Update to pending or to the appropriate status relative to the existing validated deployer pod.
178182
updatedAnnotations[deployapi.DeploymentPodAnnotation] = deployer.Name
183+
updatedAnnotations[deployapi.DeployerPodCreatedAtAnnotation] = deployer.CreationTimestamp.String()
184+
if deployer.Status.StartTime != nil {
185+
updatedAnnotations[deployapi.DeployerPodStartedAtAnnotation] = deployer.Status.StartTime.String()
186+
}
179187
nextStatus = nextStatusComp(nextStatus, deployapi.DeploymentStatusPending)
180188
}
181189
}
@@ -293,16 +301,35 @@ func (c *DeploymentController) nextStatus(pod *v1.Pod, deployment *v1.Replicatio
293301
}
294302
// Sync the internal replica annotation with the target so that we can
295303
// distinguish deployer updates from other scaling events.
304+
completedTimestamp := getPodTerminatedTimestamp(pod)
305+
if completedTimestamp != nil {
306+
updatedAnnotations[deployapi.DeployerPodCompletedAtAnnotation] = completedTimestamp.String()
307+
}
296308
updatedAnnotations[deployapi.DeploymentReplicasAnnotation] = updatedAnnotations[deployapi.DesiredReplicasAnnotation]
297309
delete(updatedAnnotations, deployapi.DesiredReplicasAnnotation)
298310
return deployapi.DeploymentStatusComplete
299311

300312
case v1.PodFailed:
313+
completedTimestamp := getPodTerminatedTimestamp(pod)
314+
if completedTimestamp != nil {
315+
updatedAnnotations[deployapi.DeployerPodCompletedAtAnnotation] = completedTimestamp.String()
316+
}
301317
return deployapi.DeploymentStatusFailed
302318
}
303319
return deployapi.DeploymentStatusNew
304320
}
305321

322+
// getPodTerminatedTimestamp gets the first terminated container in a pod and
323+
// return its termination timestamp.
324+
func getPodTerminatedTimestamp(pod *v1.Pod) *metav1.Time {
325+
for _, c := range pod.Status.ContainerStatuses {
326+
if t := c.State.Terminated; t != nil {
327+
return &t.FinishedAt
328+
}
329+
}
330+
return nil
331+
}
332+
306333
func nextStatusComp(fromDeployer, fromPath deployapi.DeploymentStatus) deployapi.DeploymentStatus {
307334
if deployutil.CanTransitionPhase(fromPath, fromDeployer) {
308335
return fromDeployer

0 commit comments

Comments
 (0)