Skip to content

Commit

Permalink
Add updatedReplicas to Status (#83)
Browse files Browse the repository at this point in the history
* Add updatedReplicas to status

Signed-off-by: kerthcet <[email protected]>

* Change replica type from int to int32

Signed-off-by: kerthcet <[email protected]>

* fix comments

Signed-off-by: kerthcet <[email protected]>

---------

Signed-off-by: kerthcet <[email protected]>
  • Loading branch information
kerthcet authored Apr 8, 2024
1 parent b8940e0 commit 6038aeb
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 59 deletions.
7 changes: 5 additions & 2 deletions api/leaderworkerset/v1/leaderworkerset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,13 @@ type LeaderWorkerSetStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty"`

// ReadyReplicas track the number of groups that are in ready state.
ReadyReplicas int `json:"readyReplicas,omitempty"`
ReadyReplicas int32 `json:"readyReplicas,omitempty"`

// UpdatedReplicas track the number of groups that have been updated.
UpdatedReplicas int32 `json:"updatedReplicas,omitempty"`

// Replicas track the active total number of groups.
Replicas int `json:"replicas,omitempty"`
Replicas int32 `json:"replicas,omitempty"`

// HPAPodSelector for pods that belong to the LeaderWorkerSet object, this is
// needed for HPA to know what pods belong to the LeaderWorkerSet object. Here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15403,9 +15403,16 @@ spec:
readyReplicas:
description: ReadyReplicas track the number of groups that are in
ready state.
format: int32
type: integer
replicas:
description: Replicas track the active total number of groups.
format: int32
type: integer
updatedReplicas:
description: UpdatedReplicas track the number of groups that have
been updated.
format: int32
type: integer
type: object
type: object
Expand Down
26 changes: 18 additions & 8 deletions pkg/controllers/leaderworkerset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ func (r *LeaderWorkerSetReconciler) updateConditions(ctx context.Context, lws *l

updateStatus := false
readyCount := 0
updatedCount := 0
templateHash := utils.LeaderWorkerTemplateHash(lws)

// Iterate through all statefulsets.
Expand All @@ -355,27 +356,36 @@ func (r *LeaderWorkerSetReconciler) updateConditions(ctx context.Context, lws *l
}

// this is the worker statefulset.
if sts.Labels[leaderworkerset.TemplateRevisionHashKey] == templateHash && statefulsetutils.StatefulsetReady(sts) {
if statefulsetutils.StatefulsetReady(sts) {

// the worker pods are OK.
// need to check leader pod for this group.
var leaderPod corev1.Pod
if err := r.Get(ctx, client.ObjectKey{Namespace: lws.Namespace, Name: sts.Name}, &leaderPod); err != nil {
log.Error(err, "Fetching leader pod")
return false, err
}
if leaderPod.Labels[leaderworkerset.TemplateRevisionHashKey] == templateHash && podutils.PodRunningAndReady(leaderPod) {
// set to progressing.
if podutils.PodRunningAndReady(leaderPod) {
readyCount++

if sts.Labels[leaderworkerset.TemplateRevisionHashKey] == templateHash && leaderPod.Labels[leaderworkerset.TemplateRevisionHashKey] == templateHash {
updatedCount++
}
}
}
}

if lws.Status.ReadyReplicas != readyCount {
lws.Status.ReadyReplicas = readyCount
if lws.Status.ReadyReplicas != int32(readyCount) {
lws.Status.ReadyReplicas = int32(readyCount)
updateStatus = true
}

if lws.Status.UpdatedReplicas != int32(updatedCount) {
lws.Status.UpdatedReplicas = int32(updatedCount)
updateStatus = true
}

condition := makeCondition(readyCount == int(*lws.Spec.Replicas))
condition := makeCondition(updatedCount == int(*lws.Spec.Replicas))
updateCondition := setCondition(lws, condition)
// if condition changed, record events
if updateCondition {
Expand All @@ -398,8 +408,8 @@ func (r *LeaderWorkerSetReconciler) updateStatus(ctx context.Context, lws *leade

// retrieve the current number of replicas -- the number of leaders
replicas := int(*sts.Spec.Replicas)
if lws.Status.Replicas != replicas {
lws.Status.Replicas = replicas
if lws.Status.Replicas != int32(replicas) {
lws.Status.Replicas = int32(replicas)
updateStatus = true
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
)

const (
timeout = 1 * time.Minute
timeout = 30 * time.Second
interval = time.Millisecond * 250
)

Expand Down
Loading

0 comments on commit 6038aeb

Please sign in to comment.