Skip to content

Commit

Permalink
adding updatedAvailableReplicas field (#1317)
Browse files Browse the repository at this point in the history
* adding updatedAvailableReplicas field

Signed-off-by: ntishchauhan0022 <nitishchauhan0022@gmail.com>

* resolving linting error and some check for updatedavailabel replica

Signed-off-by: ntishchauhan0022 <nitishchauhan0022@gmail.com>

* fixing typo

Signed-off-by: ntishchauhan0022 <nitishchauhan0022@gmail.com>

---------

Signed-off-by: ntishchauhan0022 <nitishchauhan0022@gmail.com>
  • Loading branch information
nitishchauhan0022 committed Jul 6, 2023
1 parent d16f01b commit 24a4b7f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 0 deletions.
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 ||
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++
}
}
// 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++
}
}
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 UpdatedAvailableReplicas correctly")
}
}

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

0 comments on commit 24a4b7f

Please sign in to comment.