Skip to content

Commit

Permalink
feat: add lifecycle field for gameserverset (#162)
Browse files Browse the repository at this point in the history
Signed-off-by: ChrisLiu <[email protected]>
  • Loading branch information
chrisliu1995 authored Aug 16, 2024
1 parent 14e281d commit 26fcaf7
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 13 deletions.
16 changes: 9 additions & 7 deletions apis/v1alpha1/gameserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ type GameServerContainer struct {
type GameServerState string

const (
Unknown GameServerState = "Unknown"
Creating GameServerState = "Creating"
Ready GameServerState = "Ready"
NotReady GameServerState = "NotReady"
Crash GameServerState = "Crash"
Updating GameServerState = "Updating"
Deleting GameServerState = "Deleting"
Unknown GameServerState = "Unknown"
Creating GameServerState = "Creating"
Ready GameServerState = "Ready"
NotReady GameServerState = "NotReady"
Crash GameServerState = "Crash"
Updating GameServerState = "Updating"
Deleting GameServerState = "Deleting"
PreDelete GameServerState = "PreDelete"
PreUpdate GameServerState = "PreUpdate"
)

type OpsState string
Expand Down
1 change: 1 addition & 0 deletions apis/v1alpha1/gameserverset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type GameServerSetSpec struct {
UpdateStrategy UpdateStrategy `json:"updateStrategy,omitempty"`
ScaleStrategy ScaleStrategy `json:"scaleStrategy,omitempty"`
Network *Network `json:"network,omitempty"`
Lifecycle *appspub.Lifecycle `json:"lifecycle,omitempty"`
}

type GameServerTemplate struct {
Expand Down
5 changes: 5 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions config/crd/bases/game.kruise.io_gameserversets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,49 @@ spec:
type: array
type: object
x-kubernetes-preserve-unknown-fields: true
lifecycle:
description: Lifecycle contains the hooks for Pod lifecycle.
properties:
inPlaceUpdate:
description: InPlaceUpdate is the hook before Pod to update and
after Pod has been updated.
properties:
finalizersHandler:
items:
type: string
type: array
labelsHandler:
additionalProperties:
type: string
type: object
markPodNotReady:
description: 'MarkPodNotReady = true means: - Pod will be
set to ''NotReady'' at preparingDelete/preparingUpdate state.
- Pod will be restored to ''Ready'' at Updated state if
it was set to ''NotReady'' at preparingUpdate state. Default
to false.'
type: boolean
type: object
preDelete:
description: PreDelete is the hook before Pod to be deleted.
properties:
finalizersHandler:
items:
type: string
type: array
labelsHandler:
additionalProperties:
type: string
type: object
markPodNotReady:
description: 'MarkPodNotReady = true means: - Pod will be
set to ''NotReady'' at preparingDelete/preparingUpdate state.
- Pod will be restored to ''Ready'' at Updated state if
it was set to ''NotReady'' at preparingUpdate state. Default
to false.'
type: boolean
type: object
type: object
network:
properties:
networkConf:
Expand Down
13 changes: 12 additions & 1 deletion pkg/controllers/gameserver/gameserver_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,21 @@ func (manager GameServerManager) SyncGsToPod() error {
case corev1.PodRunning:
// GameServer Updating
lifecycleState, exist := pod.GetLabels()[kruisePub.LifecycleStateKey]
if exist && (lifecycleState == string(kruisePub.LifecycleStateUpdating) || lifecycleState == string(kruisePub.LifecycleStatePreparingUpdate)) {
if exist && lifecycleState == string(kruisePub.LifecycleStateUpdating) {
gsState = gameKruiseV1alpha1.Updating
break
}
// GameServer PreUpdate
if exist && lifecycleState == string(kruisePub.LifecycleStatePreparingUpdate) {
gsState = gameKruiseV1alpha1.PreUpdate
break
}
// GameServer PreDelete
if exist && lifecycleState == string(kruisePub.LifecycleStatePreparingDelete) {
gsState = gameKruiseV1alpha1.PreDelete
break
}

// GameServer Deleting
if !pod.DeletionTimestamp.IsZero() {
gsState = gameKruiseV1alpha1.Deleting
Expand Down
16 changes: 11 additions & 5 deletions pkg/util/gameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,20 @@ func GetNewAstsFromGss(gss *gameKruiseV1alpha1.GameServerSet, asts *kruiseV1beta
readinessGates = append(readinessGates, corev1.PodReadinessGate{ConditionType: appspub.InPlaceUpdateReady})
asts.Spec.Template.Spec.ReadinessGates = readinessGates

// set Lifecycle
asts.Spec.Lifecycle = gss.Spec.Lifecycle
// AllowNotReadyContainers
if gss.Spec.Network != nil && IsAllowNotReadyContainers(gss.Spec.Network.NetworkConf) {
// set lifecycle
asts.Spec.Lifecycle = &appspub.Lifecycle{
InPlaceUpdate: &appspub.LifecycleHook{
LabelsHandler: map[string]string{gameKruiseV1alpha1.InplaceUpdateNotReadyBlocker: "true"},
},
if asts.Spec.Lifecycle == nil {
asts.Spec.Lifecycle = &appspub.Lifecycle{}
}
if asts.Spec.Lifecycle.InPlaceUpdate == nil {
asts.Spec.Lifecycle.InPlaceUpdate = &appspub.LifecycleHook{}
}
if asts.Spec.Lifecycle.InPlaceUpdate.LabelsHandler == nil {
asts.Spec.Lifecycle.InPlaceUpdate.LabelsHandler = make(map[string]string)
}
asts.Spec.Lifecycle.InPlaceUpdate.LabelsHandler[gameKruiseV1alpha1.InplaceUpdateNotReadyBlocker] = "true"
}

// set VolumeClaimTemplates
Expand Down

0 comments on commit 26fcaf7

Please sign in to comment.