feat(health-check): Add resource_customizations for game.kruise.io (new) (#23558)

Signed-off-by: shiqisong <1355703321@qq.com>
This commit is contained in:
sqs
2025-09-07 02:35:27 +08:00
committed by GitHub
parent d954789d47
commit fd4355baae
13 changed files with 208 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
hs = {status="Unknown", message="Waiting for GameServer to be ready"}
if obj.status then
local cur = obj.status.currentState
local dest = obj.status.desiredState
-- 1) Check cur and dest status: Progressing
if cur ~= dest then
hs.status = "Progressing"
hs.message = "State change: " .. (cur or "Unknown") .. "" .. (dest or "Unknown")
return hs
end
-- 2) Check pod: KruisePodReady
local podCond = obj.status.podStatus or {}
for _, c in ipairs(podCond.conditions or {}) do
if c.type == "KruisePodReady" and c.status ~= "True" then
hs.status = "Degraded"
hs.message = "Pod is not ready: " .. c.type
return hs
end
end
-- 3) Both ready: Healthy
if cur == "Ready" and dest == "Ready" then
hs.status = "Healthy"
hs.message = "GameServer is Ready"
return hs
end
end
return hs

View File

@@ -0,0 +1,20 @@
tests:
- healthStatus:
status: Healthy
message: GameServer is Ready
inputPath: testdata/healthy.yaml
- healthStatus:
status: Progressing
message: 'State change: Creating → Ready'
inputPath: testdata/progressing.yaml
- healthStatus:
status: Degraded
message: 'Pod is not ready: KruisePodReady'
inputPath: testdata/degraded.yaml
- healthStatus:
status: Unknown
message: Waiting for GameServer to be ready
inputPath: testdata/unknown.yaml

View File

@@ -0,0 +1,13 @@
apiVersion: game.kruise.io/v1alpha1
kind: GameServer
metadata:
name: gs-degraded
status:
currentState: "Ready"
desiredState: "Ready"
podStatus:
conditions:
- type: "Ready"
status: "True"
- type: "KruisePodReady"
status: "False"

View File

@@ -0,0 +1,12 @@
apiVersion: game.kruise.io/v1alpha1
kind: GameServer
metadata:
name: gs-healthy
status:
currentState: Ready
desiredState: Ready
conditions:
- type: PodNormal
status: "True"
- type: NodeNormal
status: "True"

View File

@@ -0,0 +1,7 @@
apiVersion: game.kruise.io/v1alpha1
kind: GameServer
metadata:
name: gs-progressing
status:
currentState: "Creating"
desiredState: "Ready"

View File

@@ -0,0 +1,5 @@
apiVersion: game.kruise.io/v1alpha1
kind: GameServer
metadata:
name: gs-unknown
spec: {}

View File

@@ -0,0 +1,38 @@
hs = {status="Progressing", message="Waiting for GameServerSet initialization"}
if obj.status and obj.metadata.generation == obj.status.observedGeneration then
local ru = obj.spec.updateStrategy and obj.spec.updateStrategy.rollingUpdate or {}
-- 1) Pause
if ru.paused == true then
hs.status = "Suspended"
hs.message = "GameServerSet is paused"
return hs
end
-- 2) Partition
local partition = ru.partition or 0
if partition ~= 0 and (obj.status.updatedReplicas or 0) >= (obj.status.replicas or 0) - partition then
hs.status = "Suspended"
hs.message = "Partition=" .. partition .. ", waiting for manual intervention"
return hs
end
-- 3) All updated and ready
if (obj.status.updatedReadyReplicas or 0) == (obj.status.replicas or 0) then
hs.status = "Healthy"
hs.message = "All GameServerSet replicas are updated and ready"
return hs
end
-- 4) ReadyRelicas not enough
if (obj.status.readyReplicas or 0) < (obj.status.replicas or 0) then
hs.status = "Progressing"
hs.message = "ReadyReplicas " ..
(obj.status.readyReplicas or 0) .. "/" ..
(obj.status.replicas or 0) .. ", still progressing"
return hs
end
end
return hs

View File

@@ -0,0 +1,25 @@
tests:
- healthStatus:
status: Healthy
message: All GameServerSet replicas are updated and ready
inputPath: testdata/healthy.yaml
- healthStatus:
status: Suspended
message: GameServerSet is paused
inputPath: testdata/suspended-paused.yaml
- healthStatus:
status: Suspended
message: Partition=2, waiting for manual intervention
inputPath: testdata/suspended-partition.yaml
- healthStatus:
status: Progressing
message: 'ReadyReplicas 2/3, still progressing'
inputPath: testdata/progressing.yaml
- healthStatus:
status: Progressing
message: Waiting for GameServerSet initialization
inputPath: testdata/progressing-init.yaml

View File

@@ -0,0 +1,11 @@
apiVersion: game.kruise.io/v1alpha1
kind: GameServerSet
metadata:
generation: 1
spec:
replicas: 3
status:
observedGeneration: 1
replicas: 3
readyReplicas: 3
updatedReadyReplicas: 3

View File

@@ -0,0 +1,9 @@
apiVersion: game.kruise.io/v1alpha1
kind: GameServerSet
metadata:
generation: 2
spec:
replicas: 3
status:
observedGeneration: 1
replicas: 3

View File

@@ -0,0 +1,11 @@
apiVersion: game.kruise.io/v1alpha1
kind: GameServerSet
metadata:
generation: 1
spec:
replicas: 3
status:
observedGeneration: 1
replicas: 3
readyReplicas: 2
updatedReadyReplicas: 2

View File

@@ -0,0 +1,13 @@
apiVersion: game.kruise.io/v1alpha1
kind: GameServerSet
metadata:
generation: 1
spec:
replicas: 5
updateStrategy:
rollingUpdate:
partition: 2
status:
observedGeneration: 1
replicas: 5
updatedReplicas: 3

View File

@@ -0,0 +1,12 @@
apiVersion: game.kruise.io/v1alpha1
kind: GameServerSet
metadata:
generation: 1
spec:
replicas: 3
updateStrategy:
rollingUpdate:
paused: true
status:
observedGeneration: 1
replicas: 3