From fd4355baae217439b686543f6f7d0ef904ca3169 Mon Sep 17 00:00:00 2001 From: sqs <105286805+qisongshi@users.noreply.github.com> Date: Sun, 7 Sep 2025 02:35:27 +0800 Subject: [PATCH] feat(health-check): Add resource_customizations for game.kruise.io (new) (#23558) Signed-off-by: shiqisong <1355703321@qq.com> --- .../game.kruise.io/GameServer/health.lua | 32 ++++++++++++++++ .../GameServer/health_test.yaml | 20 ++++++++++ .../GameServer/testdata/degraded.yaml | 13 +++++++ .../GameServer/testdata/healthy.yaml | 12 ++++++ .../GameServer/testdata/progressing.yaml | 7 ++++ .../GameServer/testdata/unknown.yaml | 5 +++ .../game.kruise.io/GameServerSet/health.lua | 38 +++++++++++++++++++ .../GameServerSet/health_test.yaml | 25 ++++++++++++ .../GameServerSet/testdata/healthy.yaml | 11 ++++++ .../testdata/progressing-init.yaml | 9 +++++ .../GameServerSet/testdata/progressing.yaml | 11 ++++++ .../testdata/suspended-partition.yaml | 13 +++++++ .../testdata/suspended-paused.yaml | 12 ++++++ 13 files changed, 208 insertions(+) create mode 100644 resource_customizations/game.kruise.io/GameServer/health.lua create mode 100644 resource_customizations/game.kruise.io/GameServer/health_test.yaml create mode 100644 resource_customizations/game.kruise.io/GameServer/testdata/degraded.yaml create mode 100644 resource_customizations/game.kruise.io/GameServer/testdata/healthy.yaml create mode 100644 resource_customizations/game.kruise.io/GameServer/testdata/progressing.yaml create mode 100644 resource_customizations/game.kruise.io/GameServer/testdata/unknown.yaml create mode 100644 resource_customizations/game.kruise.io/GameServerSet/health.lua create mode 100644 resource_customizations/game.kruise.io/GameServerSet/health_test.yaml create mode 100644 resource_customizations/game.kruise.io/GameServerSet/testdata/healthy.yaml create mode 100644 resource_customizations/game.kruise.io/GameServerSet/testdata/progressing-init.yaml create mode 100644 resource_customizations/game.kruise.io/GameServerSet/testdata/progressing.yaml create mode 100644 resource_customizations/game.kruise.io/GameServerSet/testdata/suspended-partition.yaml create mode 100644 resource_customizations/game.kruise.io/GameServerSet/testdata/suspended-paused.yaml diff --git a/resource_customizations/game.kruise.io/GameServer/health.lua b/resource_customizations/game.kruise.io/GameServer/health.lua new file mode 100644 index 0000000000..2323394231 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServer/health.lua @@ -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 \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServer/health_test.yaml b/resource_customizations/game.kruise.io/GameServer/health_test.yaml new file mode 100644 index 0000000000..16dc7073d0 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServer/health_test.yaml @@ -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 \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServer/testdata/degraded.yaml b/resource_customizations/game.kruise.io/GameServer/testdata/degraded.yaml new file mode 100644 index 0000000000..6472e2b9d5 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServer/testdata/degraded.yaml @@ -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" \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServer/testdata/healthy.yaml b/resource_customizations/game.kruise.io/GameServer/testdata/healthy.yaml new file mode 100644 index 0000000000..facc0d78a0 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServer/testdata/healthy.yaml @@ -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" \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServer/testdata/progressing.yaml b/resource_customizations/game.kruise.io/GameServer/testdata/progressing.yaml new file mode 100644 index 0000000000..a25e1f4273 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServer/testdata/progressing.yaml @@ -0,0 +1,7 @@ +apiVersion: game.kruise.io/v1alpha1 +kind: GameServer +metadata: + name: gs-progressing +status: + currentState: "Creating" + desiredState: "Ready" \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServer/testdata/unknown.yaml b/resource_customizations/game.kruise.io/GameServer/testdata/unknown.yaml new file mode 100644 index 0000000000..a14f1ff427 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServer/testdata/unknown.yaml @@ -0,0 +1,5 @@ +apiVersion: game.kruise.io/v1alpha1 +kind: GameServer +metadata: + name: gs-unknown +spec: {} \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServerSet/health.lua b/resource_customizations/game.kruise.io/GameServerSet/health.lua new file mode 100644 index 0000000000..19f26f4ef7 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServerSet/health.lua @@ -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 \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServerSet/health_test.yaml b/resource_customizations/game.kruise.io/GameServerSet/health_test.yaml new file mode 100644 index 0000000000..b1a551fb46 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServerSet/health_test.yaml @@ -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 \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServerSet/testdata/healthy.yaml b/resource_customizations/game.kruise.io/GameServerSet/testdata/healthy.yaml new file mode 100644 index 0000000000..7c8d054c86 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServerSet/testdata/healthy.yaml @@ -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 \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServerSet/testdata/progressing-init.yaml b/resource_customizations/game.kruise.io/GameServerSet/testdata/progressing-init.yaml new file mode 100644 index 0000000000..591e8b1654 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServerSet/testdata/progressing-init.yaml @@ -0,0 +1,9 @@ +apiVersion: game.kruise.io/v1alpha1 +kind: GameServerSet +metadata: + generation: 2 +spec: + replicas: 3 +status: + observedGeneration: 1 + replicas: 3 \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServerSet/testdata/progressing.yaml b/resource_customizations/game.kruise.io/GameServerSet/testdata/progressing.yaml new file mode 100644 index 0000000000..98095025fb --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServerSet/testdata/progressing.yaml @@ -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 \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServerSet/testdata/suspended-partition.yaml b/resource_customizations/game.kruise.io/GameServerSet/testdata/suspended-partition.yaml new file mode 100644 index 0000000000..4761212b47 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServerSet/testdata/suspended-partition.yaml @@ -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 \ No newline at end of file diff --git a/resource_customizations/game.kruise.io/GameServerSet/testdata/suspended-paused.yaml b/resource_customizations/game.kruise.io/GameServerSet/testdata/suspended-paused.yaml new file mode 100644 index 0000000000..b04affc4c1 --- /dev/null +++ b/resource_customizations/game.kruise.io/GameServerSet/testdata/suspended-paused.yaml @@ -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 \ No newline at end of file