From 39014232722ecbe9f121d573e70ec0c2e9514f27 Mon Sep 17 00:00:00 2001 From: Janet Kuo Date: Mon, 22 Feb 2016 14:28:28 -0800 Subject: [PATCH] Report actual replicas in deployment status --- pkg/controller/deployment/deployment_controller.go | 4 ++-- pkg/util/deployment/deployment.go | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/controller/deployment/deployment_controller.go b/pkg/controller/deployment/deployment_controller.go index b1eaa67897f..761b1807d78 100644 --- a/pkg/controller/deployment/deployment_controller.go +++ b/pkg/controller/deployment/deployment_controller.go @@ -1042,8 +1042,8 @@ func (dc *DeploymentController) updateDeploymentStatus(allRSs []*extensions.Repl } func (dc *DeploymentController) calculateStatus(allRSs []*extensions.ReplicaSet, newRS *extensions.ReplicaSet, deployment extensions.Deployment) (totalReplicas, updatedReplicas, availableReplicas, unavailableReplicas int, err error) { - totalReplicas = deploymentutil.GetReplicaCountForReplicaSets(allRSs) - updatedReplicas = deploymentutil.GetReplicaCountForReplicaSets([]*extensions.ReplicaSet{newRS}) + totalReplicas = deploymentutil.GetActualReplicaCountForReplicaSets(allRSs) + updatedReplicas = deploymentutil.GetActualReplicaCountForReplicaSets([]*extensions.ReplicaSet{newRS}) minReadySeconds := deployment.Spec.MinReadySeconds availableReplicas, err = deploymentutil.GetAvailablePodsForReplicaSets(dc.client, allRSs, minReadySeconds) if err != nil { diff --git a/pkg/util/deployment/deployment.go b/pkg/util/deployment/deployment.go index 5f5baa782e3..5eb20b33f8a 100644 --- a/pkg/util/deployment/deployment.go +++ b/pkg/util/deployment/deployment.go @@ -177,6 +177,15 @@ func GetReplicaCountForReplicaSets(replicaSets []*extensions.ReplicaSet) int { return totalReplicaCount } +// GetActualReplicaCountForReplicaSets returns the sum of actual replicas of the given replica sets. +func GetActualReplicaCountForReplicaSets(replicaSets []*extensions.ReplicaSet) int { + totalReplicaCount := 0 + for _, rs := range replicaSets { + totalReplicaCount += rs.Status.Replicas + } + return totalReplicaCount +} + // Returns the number of available pods corresponding to the given replica sets. func GetAvailablePodsForReplicaSets(c clientset.Interface, rss []*extensions.ReplicaSet, minReadySeconds int) (int, error) { allPods, err := GetPodsForReplicaSets(c, rss)