From ce04ee617058d57c553d27f0966b91e1e900bb18 Mon Sep 17 00:00:00 2001 From: Michail Kargakis Date: Fri, 2 Dec 2016 17:32:34 +0100 Subject: [PATCH] extensions: add readyReplicas in Deployments --- pkg/apis/extensions/types.go | 4 ++++ pkg/apis/extensions/v1beta1/types.go | 4 ++++ pkg/apis/extensions/validation/validation.go | 1 + pkg/controller/deployment/sync.go | 1 + pkg/controller/deployment/util/deployment_util.go | 11 +++++++++++ 5 files changed, 21 insertions(+) diff --git a/pkg/apis/extensions/types.go b/pkg/apis/extensions/types.go index 2083f73ba3d..2a18b06e557 100644 --- a/pkg/apis/extensions/types.go +++ b/pkg/apis/extensions/types.go @@ -312,6 +312,10 @@ type DeploymentStatus struct { // +optional UpdatedReplicas int32 + // Total number of ready pods targeted by this deployment. + // +optional + ReadyReplicas int32 + // Total number of available pods (ready for at least minReadySeconds) targeted by this deployment. // +optional AvailableReplicas int32 diff --git a/pkg/apis/extensions/v1beta1/types.go b/pkg/apis/extensions/v1beta1/types.go index 18e9b909d74..7c1ee3c5ee1 100644 --- a/pkg/apis/extensions/v1beta1/types.go +++ b/pkg/apis/extensions/v1beta1/types.go @@ -397,6 +397,10 @@ type DeploymentStatus struct { // +optional UpdatedReplicas int32 `json:"updatedReplicas,omitempty" protobuf:"varint,3,opt,name=updatedReplicas"` + // Total number of ready pods targeted by this deployment. + // +optional + ReadyReplicas int32 `json:"readyReplicas,omitempty"` + // Total number of available pods (ready for at least minReadySeconds) targeted by this deployment. // +optional AvailableReplicas int32 `json:"availableReplicas,omitempty" protobuf:"varint,4,opt,name=availableReplicas"` diff --git a/pkg/apis/extensions/validation/validation.go b/pkg/apis/extensions/validation/validation.go index b9b92491ae6..9434163f7ba 100644 --- a/pkg/apis/extensions/validation/validation.go +++ b/pkg/apis/extensions/validation/validation.go @@ -281,6 +281,7 @@ func ValidateDeploymentStatus(status *extensions.DeploymentStatus, fldPath *fiel allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(status.ObservedGeneration, fldPath.Child("observedGeneration"))...) allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(status.Replicas), fldPath.Child("replicas"))...) allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(status.UpdatedReplicas), fldPath.Child("updatedReplicas"))...) + allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(status.ReadyReplicas), fldPath.Child("readyReplicas"))...) allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(status.AvailableReplicas), fldPath.Child("availableReplicas"))...) allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(status.UnavailableReplicas), fldPath.Child("unavailableReplicas"))...) return allErrs diff --git a/pkg/controller/deployment/sync.go b/pkg/controller/deployment/sync.go index 547594d7e9d..69354703c0e 100644 --- a/pkg/controller/deployment/sync.go +++ b/pkg/controller/deployment/sync.go @@ -595,6 +595,7 @@ func calculateStatus(allRSs []*extensions.ReplicaSet, newRS *extensions.ReplicaS ObservedGeneration: deployment.Generation, Replicas: deploymentutil.GetActualReplicaCountForReplicaSets(allRSs), UpdatedReplicas: deploymentutil.GetActualReplicaCountForReplicaSets([]*extensions.ReplicaSet{newRS}), + ReadyReplicas: deploymentutil.GetReadyReplicaCountForReplicaSets(allRSs), AvailableReplicas: availableReplicas, UnavailableReplicas: unavailableReplicas, } diff --git a/pkg/controller/deployment/util/deployment_util.go b/pkg/controller/deployment/util/deployment_util.go index d6ea22d5cfa..2c36874f2fc 100644 --- a/pkg/controller/deployment/util/deployment_util.go +++ b/pkg/controller/deployment/util/deployment_util.go @@ -782,6 +782,17 @@ func GetActualReplicaCountForReplicaSets(replicaSets []*extensions.ReplicaSet) i return totalActualReplicas } +// GetReadyReplicaCountForReplicaSets returns the number of ready pods corresponding to the given replica sets. +func GetReadyReplicaCountForReplicaSets(replicaSets []*extensions.ReplicaSet) int32 { + totalReadyReplicas := int32(0) + for _, rs := range replicaSets { + if rs != nil { + totalReadyReplicas += rs.Status.ReadyReplicas + } + } + return totalReadyReplicas +} + // GetAvailableReplicaCountForReplicaSets returns the number of available pods corresponding to the given replica sets. func GetAvailableReplicaCountForReplicaSets(replicaSets []*extensions.ReplicaSet) int32 { totalAvailableReplicas := int32(0)