Skip to content

Commit

Permalink
apps: record cause of rollout and deployer pods timestamps back to rc
Browse files Browse the repository at this point in the history
  • Loading branch information
mfojtik committed Oct 2, 2017
1 parent bd5b800 commit fb1679e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/apps/apis/apps/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ const (
// annotation value is the name of the deployer Pod which will act upon the ReplicationController
// to implement the deployment behavior.
DeploymentPodAnnotation = "openshift.io/deployer-pod.name"
// DeployerPodCreatedAtAnnotation is an annotation on a deployment that
// records the time in RFC3339 format of when the deployer pod for this particular
// deployment was created.
DeployerPodCreatedAtAnnotation = "openshift.io/deployer-pod.created-at"
// DeployerPodStartedAtAnnotation is an annotation on a deployment that
// records the time in RFC3339 format of when the deployer pod for this particular
// deployment was started.
DeployerPodStartedAtAnnotation = "openshift.io/deployer-pod.started-at"
// DeployerPodCompletedAtAnnotation is an annotation on deployment that records
// the time in RFC3339 format of when the deployer pod finished.
DeployerPodCompletedAtAnnotation = "openshift.io/deployer-pod.completed-at"
// DeploymentIgnorePodAnnotation is an annotation on a deployment config that will bypass creating
// a deployment pod with the deployment. The caller is responsible for setting the deployment
// status and running the deployment process.
Expand Down
27 changes: 27 additions & 0 deletions pkg/apps/controller/deployer/deployer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func (c *DeploymentController) handle(deployment *v1.ReplicationController, will
return actionableError(fmt.Sprintf("couldn't create deployer pod for %q: %v", deployutil.LabelForDeploymentV1(deployment), err))
}
updatedAnnotations[deployapi.DeploymentPodAnnotation] = deploymentPod.Name
updatedAnnotations[deployapi.DeployerPodCreatedAtAnnotation] = deploymentPod.CreationTimestamp.String()
if deploymentPod.Status.StartTime != nil {
updatedAnnotations[deployapi.DeployerPodStartedAtAnnotation] = deploymentPod.Status.StartTime.String()
}
nextStatus = deployapi.DeploymentStatusPending
glog.V(4).Infof("Created deployer pod %q for %q", deploymentPod.Name, deployutil.LabelForDeploymentV1(deployment))

Expand Down Expand Up @@ -176,6 +180,10 @@ func (c *DeploymentController) handle(deployment *v1.ReplicationController, will
} else {
// Update to pending or to the appropriate status relative to the existing validated deployer pod.
updatedAnnotations[deployapi.DeploymentPodAnnotation] = deployer.Name
updatedAnnotations[deployapi.DeployerPodCreatedAtAnnotation] = deployer.CreationTimestamp.String()
if deployer.Status.StartTime != nil {
updatedAnnotations[deployapi.DeployerPodStartedAtAnnotation] = deployer.Status.StartTime.String()
}
nextStatus = nextStatusComp(nextStatus, deployapi.DeploymentStatusPending)
}
}
Expand Down Expand Up @@ -293,16 +301,35 @@ func (c *DeploymentController) nextStatus(pod *v1.Pod, deployment *v1.Replicatio
}
// Sync the internal replica annotation with the target so that we can
// distinguish deployer updates from other scaling events.
completedTimestamp := getPodTerminatedTimestamp(pod)
if completedTimestamp != nil {
updatedAnnotations[deployapi.DeployerPodCompletedAtAnnotation] = completedTimestamp.String()
}
updatedAnnotations[deployapi.DeploymentReplicasAnnotation] = updatedAnnotations[deployapi.DesiredReplicasAnnotation]
delete(updatedAnnotations, deployapi.DesiredReplicasAnnotation)
return deployapi.DeploymentStatusComplete

case v1.PodFailed:
completedTimestamp := getPodTerminatedTimestamp(pod)
if completedTimestamp != nil {
updatedAnnotations[deployapi.DeployerPodCompletedAtAnnotation] = completedTimestamp.String()
}
return deployapi.DeploymentStatusFailed
}
return deployapi.DeploymentStatusNew
}

// getPodTerminatedTimestamp gets the first terminated container in a pod and
// return its termination timestamp.
func getPodTerminatedTimestamp(pod *v1.Pod) *metav1.Time {
for _, c := range pod.Status.ContainerStatuses {
if t := c.State.Terminated; t != nil {
return &t.FinishedAt
}
}
return nil
}

func nextStatusComp(fromDeployer, fromPath deployapi.DeploymentStatus) deployapi.DeploymentStatus {
if deployutil.CanTransitionPhase(fromPath, fromDeployer) {
return fromDeployer
Expand Down

0 comments on commit fb1679e

Please sign in to comment.