Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add updatedReplicas to Status #83

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? are we not concerned this will make it flaky?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timeout is shared by integration-test and e2e-test, 1 minute is too long for waiting integration test to fail if we have. We can fasten this if necessary, but right now, 30s is enough for what I'm testing. (I added some optimizations like update the name rather than the image which will slow down the rolling update process)

interval = time.Millisecond * 250
)

Expand Down
Loading