Skip to content

Commit

Permalink
merge update request of status and extra status for cloneset (openkru…
Browse files Browse the repository at this point in the history
…ise#1278)

Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
Co-authored-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
  • Loading branch information
2 people authored and 李龙峰 committed Sep 12, 2023
1 parent 89033ca commit e838682
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
26 changes: 17 additions & 9 deletions pkg/controller/cloneset/cloneset_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cloneset

import (
"context"
"fmt"

appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
clonesetcore "github.com/openkruise/kruise/pkg/controller/cloneset/core"
Expand Down Expand Up @@ -46,25 +47,32 @@ type realStatusUpdater struct {

func (r *realStatusUpdater) UpdateCloneSetStatus(cs *appsv1alpha1.CloneSet, newStatus *appsv1alpha1.CloneSetStatus, pods []*v1.Pod) error {
r.calculateStatus(cs, newStatus, pods)
if r.inconsistentStatus(cs, newStatus) {
klog.Infof("To update CloneSet status for %s/%s, replicas=%d ready=%d available=%d updated=%d updatedReady=%d, revisions current=%s update=%s",
cs.Namespace, cs.Name, newStatus.Replicas, newStatus.ReadyReplicas, newStatus.AvailableReplicas, newStatus.UpdatedReplicas, newStatus.UpdatedReadyReplicas, newStatus.CurrentRevision, newStatus.UpdateRevision)
if err := r.updateStatus(cs, newStatus); err != nil {
return err
}
extraStatus, modified, err := clonesetcore.New(cs).ExtraStatusCalculation(newStatus, pods)
if err != nil {
return fmt.Errorf("failed to calculate extra status for cloneSet %s/%s: %v", cs.Namespace, cs.Name, err)
}

return clonesetcore.New(cs).ExtraStatusCalculation(newStatus, pods)
if !modified && !r.inconsistentStatus(cs, newStatus) {
return nil
}
klog.Infof("To update CloneSet status for %s/%s, replicas=%d ready=%d available=%d updated=%d updatedReady=%d, revisions current=%s update=%s",
cs.Namespace, cs.Name, newStatus.Replicas, newStatus.ReadyReplicas, newStatus.AvailableReplicas, newStatus.UpdatedReplicas, newStatus.UpdatedReadyReplicas, newStatus.CurrentRevision, newStatus.UpdateRevision)
return r.updateStatus(cs, newStatus, extraStatus)
}

func (r *realStatusUpdater) updateStatus(cs *appsv1alpha1.CloneSet, newStatus *appsv1alpha1.CloneSetStatus) error {
func (r *realStatusUpdater) updateStatus(cs *appsv1alpha1.CloneSet, newStatus *appsv1alpha1.CloneSetStatus, extraStatus map[string]string) error {
return retry.RetryOnConflict(retry.DefaultBackoff, func() error {
clone := &appsv1alpha1.CloneSet{}
if err := r.Get(context.TODO(), types.NamespacedName{Namespace: cs.Namespace, Name: cs.Name}, clone); err != nil {
return err
}
clone.Status = *newStatus
clone.Annotations = cs.Annotations
if clone.Annotations == nil {
clone.Annotations = map[string]string{}
}
for key, value := range extraStatus {
clone.Annotations[key] = value
}
return r.Status().Update(context.TODO(), clone)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/cloneset/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Control interface {
IsPodUpdateReady(pod *v1.Pod, minReadySeconds int32) bool
GetPodsSortFunc(pods []*v1.Pod, waitUpdateIndexes []int) func(i, j int) bool
GetUpdateOptions() *inplaceupdate.UpdateOptions
ExtraStatusCalculation(status *appsv1alpha1.CloneSetStatus, pods []*v1.Pod) error
ExtraStatusCalculation(status *appsv1alpha1.CloneSetStatus, pods []*v1.Pod) (map[string]string, bool, error)

// validation
ValidateCloneSetUpdate(oldCS, newCS *appsv1alpha1.CloneSet) error
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/cloneset/core/cloneset_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ func (c *commonControl) ValidateCloneSetUpdate(oldCS, newCS *appsv1alpha1.CloneS
return nil
}

func (c *commonControl) ExtraStatusCalculation(status *appsv1alpha1.CloneSetStatus, pods []*v1.Pod) error {
return nil
func (c *commonControl) ExtraStatusCalculation(status *appsv1alpha1.CloneSetStatus, pods []*v1.Pod) (map[string]string, bool, error) {
return nil, false, nil
}

func (c *commonControl) IgnorePodUpdateEvent(oldPod, curPod *v1.Pod) bool {
Expand Down

0 comments on commit e838682

Please sign in to comment.