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

adding updatedAvailableReplicas field #1317

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions apis/apps/v1alpha1/cloneset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ type CloneSetStatus struct {
// indicated by updateRevision and have a Ready Condition.
UpdatedReadyReplicas int32 `json:"updatedReadyReplicas"`

// UpdatedAvailableReplicas is the number of Pods created by the CloneSet controller from the CloneSet version
// indicated by updateRevision and have a Ready Condition for at least minReadySeconds.
UpdatedAvailableReplicas int32 `json:"updatedAvailableReplicas"`

// ExpectedUpdatedReplicas is the number of Pods that should be updated by CloneSet controller.
// This field is calculated via Replicas - Partition.
ExpectedUpdatedReplicas int32 `json:"expectedUpdatedReplicas,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions apis/apps/v1beta1/statefulset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ type StatefulSetStatus struct {
// updatedReadyReplicas is the number of updated Pods created by the StatefulSet controller that have a Ready Condition.
UpdatedReadyReplicas int32 `json:"updatedReadyReplicas,omitempty"`

// updatedAvailableReplicas is the number of updated Pods created by the StatefulSet controller that have a Ready condition
//for atleast minReadySeconds.
UpdatedAvailableReplicas int32 `json:"updatedAvailableReplicas,omitempty"`

// currentRevision, if not empty, indicates the version of the StatefulSet used to generate Pods in the
// sequence [0,currentReplicas).
CurrentRevision string `json:"currentRevision,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/apps.kruise.io_clonesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ spec:
description: UpdateRevision, if not empty, indicates the latest revision
of the CloneSet.
type: string
updatedAvailableReplicas:
description: UpdatedAvailableReplicas is the number of Pods created
by the CloneSet controller from the CloneSet version indicated by
updateRevision and have a Ready Condition for at least minReadySeconds.
format: int32
type: integer
updatedReadyReplicas:
description: UpdatedReadyReplicas is the number of Pods created by
the CloneSet controller from the CloneSet version indicated by updateRevision
Expand All @@ -513,6 +519,7 @@ spec:
- availableReplicas
- readyReplicas
- replicas
- updatedAvailableReplicas
- updatedReadyReplicas
- updatedReplicas
type: object
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/apps.kruise.io_statefulsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,12 @@ spec:
description: updateRevision, if not empty, indicates the version of
the StatefulSet used to generate Pods in the sequence [replicas-updatedReplicas,replicas)
type: string
updatedAvailableReplicas:
description: updatedAvailableReplicas is the number of updated Pods
created by the StatefulSet controller that have a Ready condition
for atleast minReadySeconds.
format: int32
type: integer
updatedReadyReplicas:
description: updatedReadyReplicas is the number of updated Pods created
by the StatefulSet controller that have a Ready Condition.
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/cloneset/cloneset_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (r *realStatusUpdater) inconsistentStatus(cs *appsv1alpha1.CloneSet, newSta
newStatus.AvailableReplicas != oldStatus.AvailableReplicas ||
newStatus.UpdatedReadyReplicas != oldStatus.UpdatedReadyReplicas ||
newStatus.UpdatedReplicas != oldStatus.UpdatedReplicas ||
newStatus.UpdatedAvailableReplicas != oldStatus.UpdatedAvailableReplicas ||
nitishchauhan0022 marked this conversation as resolved.
Show resolved Hide resolved
newStatus.ExpectedUpdatedReplicas != oldStatus.ExpectedUpdatedReplicas ||
newStatus.UpdateRevision != oldStatus.UpdateRevision ||
newStatus.CurrentRevision != oldStatus.CurrentRevision ||
Expand All @@ -99,6 +100,9 @@ func (r *realStatusUpdater) calculateStatus(cs *appsv1alpha1.CloneSet, newStatus
if clonesetutils.EqualToRevisionHash("", pod, newStatus.UpdateRevision) && coreControl.IsPodUpdateReady(pod, 0) {
newStatus.UpdatedReadyReplicas++
}
if clonesetutils.EqualToRevisionHash("", pod, newStatus.UpdateRevision) && sync.IsPodAvailable(coreControl, pod, cs.Spec.MinReadySeconds) {
newStatus.UpdatedAvailableReplicas++
nitishchauhan0022 marked this conversation as resolved.
Show resolved Hide resolved
}
}
// Consider the update revision as stable if revisions of all pods are consistent to it, no need to wait all of them ready
if newStatus.UpdatedReplicas == newStatus.Replicas {
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/statefulset/stateful_set_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet(
status.ReadyReplicas++
if getPodRevision(pods[i]) == updateRevision.Name {
status.UpdatedReadyReplicas++
if avail, _ := isRunningAndAvailable(pods[i], minReadySeconds); avail {
status.UpdatedAvailableReplicas++
}
Copy link
Member

Choose a reason for hiding this comment

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

File have many checks for set.Status.UpdatedReplicas, and i think you can add UpdatedAvailableReplicas checks.

}
if avail, _ := isRunningAndAvailable(pods[i], minReadySeconds); avail {
status.AvailableReplicas++
Expand Down
21 changes: 21 additions & 0 deletions pkg/controller/statefulset/stateful_set_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ func CreatesPods(t *testing.T, set *appsv1beta1.StatefulSet, invariants invarian
if set.Status.UpdatedReplicas != 3 {
t.Error("Failed to set UpdatedReplicas correctly")
}
if set.Status.UpdatedAvailableReplicas != 3 {
t.Error("Failed to set UpdatedAvailbleReplicas correctly")
nitishchauhan0022 marked this conversation as resolved.
Show resolved Hide resolved
}
}

func ScalesUp(t *testing.T, set *appsv1beta1.StatefulSet, invariants invariantFunc) {
Expand Down Expand Up @@ -257,6 +260,9 @@ func ScalesUp(t *testing.T, set *appsv1beta1.StatefulSet, invariants invariantFu
if set.Status.UpdatedReplicas != 4 {
t.Error("Failed to set updatedReplicas correctly")
}
if set.Status.UpdatedAvailableReplicas != 4 {
t.Error("Failed to set updatedAvailableReplicas correctly")
}
}

func ScalesDown(t *testing.T, set *appsv1beta1.StatefulSet, invariants invariantFunc) {
Expand Down Expand Up @@ -295,6 +301,9 @@ func ScalesDown(t *testing.T, set *appsv1beta1.StatefulSet, invariants invariant
if set.Status.UpdatedReplicas != 0 {
t.Error("Failed to set updatedReplicas correctly")
}
if set.Status.UpdatedAvailableReplicas != 0 {
t.Error("Failed to set updatedAvailableReplicas correctly")
}
}

func ReplacesPods(t *testing.T, set *appsv1beta1.StatefulSet, invariants invariantFunc) {
Expand Down Expand Up @@ -459,6 +468,9 @@ func CreatePodFailure(t *testing.T, set *appsv1beta1.StatefulSet, invariants inv
if set.Status.UpdatedReplicas != 3 {
t.Error("Failed to updatedReplicas correctly")
}
if set.Status.UpdatedAvailableReplicas != 4 {
t.Error("Failed to set updatedAvailableReplicas correctly")
}
}

func UpdatePodFailure(t *testing.T, set *appsv1beta1.StatefulSet, invariants invariantFunc) {
Expand Down Expand Up @@ -489,6 +501,9 @@ func UpdatePodFailure(t *testing.T, set *appsv1beta1.StatefulSet, invariants inv
if set.Status.UpdatedReplicas != 3 {
t.Error("Failed to set updatedReplicas correctly")
}
if set.Status.UpdatedAvailableReplicas != 3 {
t.Error("Failed to set updatedAvailableReplicas correctly")
}

// now mutate a pod's identity
pods, err := om.podsLister.List(labels.Everything())
Expand Down Expand Up @@ -543,6 +558,9 @@ func UpdateSetStatusFailure(t *testing.T, set *appsv1beta1.StatefulSet, invarian
if set.Status.UpdatedReplicas != 3 {
t.Error("Failed to set updatedReplicas to 3")
}
if set.Status.UpdatedAvailableReplicas != 4 {
t.Error("Failed to set updatedAvailableReplicas correctly")
}
}

func PodRecreateDeleteFailure(t *testing.T, set *appsv1beta1.StatefulSet, invariants invariantFunc) {
Expand Down Expand Up @@ -637,6 +655,9 @@ func TestStatefulSetControlScaleDownDeleteError(t *testing.T) {
if set.Status.UpdatedReplicas != 0 {
t.Error("Failed to set updatedReplicas to 0")
}
if set.Status.UpdatedAvailableReplicas != 0 {
t.Error("Failed to set updatedAvailableReplicas to 0")
}
})
}

Expand Down