Feat: add ObservedGeneration to GameServerSet (#13)

* Feat: add observed generation

Signed-off-by: Yin Da <yd219913@alibaba-inc.com>

* Chore: refactor and add status equality check

Signed-off-by: Yin Da <yd219913@alibaba-inc.com>

Signed-off-by: Yin Da <yd219913@alibaba-inc.com>
This commit is contained in:
Somefive 2022-11-09 14:33:31 +08:00 committed by GitHub
parent 082ee009be
commit 99968badfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 7 deletions

View File

@ -128,6 +128,9 @@ type ScaleStrategy struct {
// GameServerSetStatus defines the observed state of GameServerSet
type GameServerSetStatus struct {
// The generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// replicas from advancedStatefulSet
Replicas int32 `json:"replicas"`
ReadyReplicas int32 `json:"readyReplicas"`

View File

@ -638,6 +638,10 @@ spec:
maintainingReplicas:
format: int32
type: integer
observedGeneration:
description: The generation observed by the controller.
format: int64
type: integer
readyReplicas:
format: int32
type: integer

View File

@ -18,11 +18,15 @@ package gameserverset
import (
"context"
"sort"
"strconv"
"sync"
"time"
kruiseV1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1"
kruiseV1beta1 "github.com/openkruise/kruise-api/apps/v1beta1"
gameKruiseV1alpha1 "github.com/openkruise/kruise-game/apis/v1alpha1"
"github.com/openkruise/kruise-game/pkg/util"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@ -30,10 +34,9 @@ import (
"k8s.io/klog/v2"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
"sort"
"strconv"
"sync"
"time"
gameKruiseV1alpha1 "github.com/openkruise/kruise-game/apis/v1alpha1"
"github.com/openkruise/kruise-game/pkg/util"
)
type Control interface {
@ -364,8 +367,11 @@ func (manager *GameServerSetManager) SyncStatus() error {
MaintainingReplicas: pointer.Int32Ptr(int32(maintainingGs)),
WaitToBeDeletedReplicas: pointer.Int32Ptr(int32(waitToBeDeletedGs)),
LabelSelector: asts.Status.LabelSelector,
ObservedGeneration: gss.GetGeneration(),
}
if equality.Semantic.DeepEqual(gss.Status, status) {
return nil
}
patchStatus := map[string]interface{}{"status": status}
jsonPatch, err := json.Marshal(patchStatus)
if err != nil {