Skip to content

Commit 3ad0acb

Browse files
committed
[deployment/statefulset] add IsReady func
Adds IsRead() for deployment and statefulset which can be used to validate when a deployment for the current Generation is fully provisioned and e.g. no rollout in progress. Jira: OSPRH-14472 Signed-off-by: Martin Schuppert <[email protected]>
1 parent 5a4c5f4 commit 3ad0acb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

modules/common/deployment/deployment.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,14 @@ func GetDeploymentWithName(
127127

128128
return depl, nil
129129
}
130+
131+
// IsReady - validates when deployment is ready deployed to whats being requested
132+
// - the requested replicas in the spec matches the ReadyReplicas of the status
133+
// - the Status.Replicas match Status.ReadyReplicas. if a deployment update is in progress, Replicas > ReadyReplicas
134+
// - both when the Generatation of the object matches the ObservedGeneration of the Status
135+
func IsReady(deployment appsv1.Deployment) bool {
136+
return deployment.Spec.Replicas != nil &&
137+
*deployment.Spec.Replicas == deployment.Status.ReadyReplicas &&
138+
deployment.Status.Replicas == deployment.Status.ReadyReplicas &&
139+
deployment.Generation == deployment.Status.ObservedGeneration
140+
}

modules/common/statefulset/statefulset.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,12 @@ func (s *StatefulSet) Delete(
138138

139139
return nil
140140
}
141+
142+
// IsReady - validates when deployment is ready deployed to whats being requested
143+
// - the requested replicas in the spec matches the ReadyReplicas of the status
144+
// - both when the Generatation of the object matches the ObservedGeneration of the Status
145+
func IsReady(deployment appsv1.StatefulSet) bool {
146+
return deployment.Spec.Replicas != nil &&
147+
*deployment.Spec.Replicas == deployment.Status.ReadyReplicas &&
148+
deployment.Generation == deployment.Status.ObservedGeneration
149+
}

0 commit comments

Comments
 (0)