Skip to content
Open
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
1 change: 1 addition & 0 deletions apis/v1alpha1/gameserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
GameServerUpdatePriorityKey = "game.kruise.io/gs-update-priority"
GameServerDeletePriorityKey = "game.kruise.io/gs-delete-priority"
GameServerDeletingKey = "game.kruise.io/gs-deleting"
GameServerUpdatingContainersKey = "game.kruise.io/gs-updating-containers"
GameServerNetworkType = "game.kruise.io/network-type"
GameServerNetworkConf = "game.kruise.io/network-conf"
GameServerNetworkDisabled = "game.kruise.io/network-disabled"
Expand Down
12 changes: 6 additions & 6 deletions config/crd/bases/game.kruise.io_gameservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ spec:
image:
description: |-
Image indicates the image of the container to update.
When Image updated, pod.spec.containers[*].image will be updated immediately.
When Image is updated, pod.spec.containers[*].image will be updated immediately.
type: string
name:
description: Name indicates the name of the container to update.
type: string
resources:
description: |-
Resources indicates the resources of the container to update.
When Resources updated, pod.spec.containers[*].Resources will be not updated immediately,
which will be updated when pod recreate.
When Resources are updated, pod.spec.containers[*].Resources will not be updated immediately,
which will be updated when the pod is recreated.
properties:
claims:
description: |-
Expand Down Expand Up @@ -176,7 +176,7 @@ spec:
type: string
message:
description: Human-readable message indicating details about
last transition.
the last transition.
type: string
reason:
description: Unique, one-word, CamelCase reason for the condition's
Expand Down Expand Up @@ -1672,8 +1672,8 @@ spec:
name:
type: string
result:
description: Result indicate the probe message returned by the
script
description: Result indicates the probe message returned by
the script
type: string
status:
type: string
Expand Down
14 changes: 7 additions & 7 deletions config/crd/bases/game.kruise.io_gameserversets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
jsonPath: .spec.replicas
name: DESIRED
type: integer
- description: The number of currently all GameServers.
- description: The total number of current GameServers.
jsonPath: .status.currentReplicas
name: CURRENT
type: integer
Expand Down Expand Up @@ -794,7 +794,7 @@ spec:
image:
description: |-
Image indicates the image of the container to update.
When Image updated, pod.spec.containers[*].image will be updated immediately.
When Image is updated, pod.spec.containers[*].image will be updated immediately.
type: string
name:
description: Name indicates the name of the container
Expand All @@ -803,8 +803,8 @@ spec:
resources:
description: |-
Resources indicates the resources of the container to update.
When Resources updated, pod.spec.containers[*].Resources will be not updated immediately,
which will be updated when pod recreate.
When Resources are updated, pod.spec.containers[*].Resources will not be updated immediately,
which will be updated when the pod is recreated.
properties:
claims:
description: |-
Expand Down Expand Up @@ -882,8 +882,8 @@ spec:
type: string
result:
description: |-
Result indicate the probe message returned by the script.
When Result is defined, it would exec action only when the according Result is actually returns.
Result indicates the probe message returned by the script.
When Result is defined, it would exec action only when the corresponding Result is actually returned.
type: string
state:
type: boolean
Expand Down Expand Up @@ -957,7 +957,7 @@ spec:
description: |-
UnorderedUpdate contains strategies for non-ordered update.
If it is not nil, pods will be updated with non-ordered sequence.
Noted that UnorderedUpdate can only be allowed to work with Parallel podManagementPolicy
Note that UnorderedUpdate can only be allowed to work with Parallel podManagementPolicy
UnorderedUpdate *kruiseV1beta1.UnorderedUpdateStrategy `json:"unorderedUpdate,omitempty"`
InPlaceUpdateStrategy contains strategies for in-place update.
properties:
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/gameserver/gameserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (r *GameServerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
tracing.AttrGameServerSetName(gss.GetName()),
tracing.AttrGameServerName(gs.GetName()),
))
err = gsm.SyncGsToPod(ctx)
err = gsm.SyncGsToPod(ctx, gss)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "SyncGsToPod failed")
Expand Down
33 changes: 27 additions & 6 deletions pkg/controllers/gameserver/gameserver_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const (
type Control interface {
// SyncGsToPod compares the pod with GameServer, and decide whether to update the pod based on the results.
// When the fields of the pod is different from that of GameServer, pod will be updated.
SyncGsToPod(context.Context) error
SyncGsToPod(context.Context, *gameKruiseV1alpha1.GameServerSet) error
// SyncPodToGs compares the GameServer with pod, and update the GameServer.
SyncPodToGs(context.Context, *gameKruiseV1alpha1.GameServerSet) error
// WaitOrNot compare the current game server network status to decide whether to re-queue.
Expand Down Expand Up @@ -92,7 +92,7 @@ func syncMetadataFromGss(gss *gameKruiseV1alpha1.GameServerSet) metav1.ObjectMet
}
}

func (manager GameServerManager) SyncGsToPod(ctx context.Context) error {
func (manager GameServerManager) SyncGsToPod(ctx context.Context, gss *gameKruiseV1alpha1.GameServerSet) error {
pod := manager.pod
gs := manager.gameServer
podLabels := pod.GetLabels()
Expand All @@ -102,8 +102,8 @@ func (manager GameServerManager) SyncGsToPod(ctx context.Context) error {
podGsState := podLabels[gameKruiseV1alpha1.GameServerStateKey]
podNetworkDisabled := podLabels[gameKruiseV1alpha1.GameServerNetworkDisabled]

newLabels := make(map[string]string)
newAnnotations := make(map[string]string)
newLabels := make(map[string]interface{})
newAnnotations := make(map[string]interface{})
// tolerate nil pointers in spec priorities
var gsDpStr, gsUpStr string
if gs.Spec.DeletionPriority != nil {
Expand Down Expand Up @@ -215,6 +215,27 @@ func (manager GameServerManager) SyncGsToPod(ctx context.Context) error {
}
}

// sync GameServerUpdatingContainersKey annotation: when Pod enters the PreUpdate state,
// compute the diff container names and write them to the annotation; during the Updating
// state, keep the annotation as-is so that hooks can consume it; in any other state,
// remove the annotation to clean up after the update is complete.
switch gsState {
case gameKruiseV1alpha1.PreUpdate:
if gss != nil {
diffNames := util.GetDiffContainerNames(pod, gss)
updatingValue := strings.Join(diffNames, ",")
if pod.GetAnnotations()[gameKruiseV1alpha1.GameServerUpdatingContainersKey] != updatingValue {
newAnnotations[gameKruiseV1alpha1.GameServerUpdatingContainersKey] = updatingValue
}
}
case gameKruiseV1alpha1.Updating:
// keep the existing annotation unchanged so that hooks can read it
default:
if _, exists := pod.GetAnnotations()[gameKruiseV1alpha1.GameServerUpdatingContainersKey]; exists {
newAnnotations[gameKruiseV1alpha1.GameServerUpdatingContainersKey] = nil
}
}

// sync annotations from gs to pod
for gsKey, gsValue := range gs.GetAnnotations() {
if util.IsHasPrefixGsSyncToPod(gsKey) {
Expand Down Expand Up @@ -255,15 +276,15 @@ func (manager GameServerManager) SyncGsToPod(ctx context.Context) error {
traceparent := tracing.GenerateTraceparent(spanContext)
if traceparent != "" {
if len(newAnnotations) == 0 {
newAnnotations = make(map[string]string)
newAnnotations = make(map[string]interface{})
}
newAnnotations[telemetryfields.AnnotationTraceparent] = traceparent
}
}

patchPod := make(map[string]interface{})
if len(newLabels) != 0 || len(newAnnotations) != 0 {
patchPod["metadata"] = map[string]map[string]string{"labels": newLabels, "annotations": newAnnotations}
patchPod["metadata"] = map[string]map[string]interface{}{"labels": newLabels, "annotations": newAnnotations}
}
if containers != nil {
patchPod["spec"] = map[string]interface{}{"containers": containers}
Expand Down
Loading
Loading