feat(health): Implement spinkube SpinApp CRD health checks (#21896)

Signed-off-by: lukepatrick <lukephilips@gmail.com>
This commit is contained in:
Luke
2025-05-29 11:27:19 -06:00
committed by GitHub
parent 1be1d1c0ae
commit 7d6604404f
6 changed files with 205 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
hs = {}
-- Check if status exists
if not obj.status then
hs.status = "Progressing"
hs.message = "Waiting for status to be available"
return hs
end
-- Initialize variables for conditions
local available = false
local progressing = false
local availableMessage = ""
local progressingMessage = ""
-- Check conditions - prioritize failure conditions first
if obj.status.conditions then
for _, condition in ipairs(obj.status.conditions) do
if condition.type == "Progressing" then
-- Check for timeout or failure in progressing condition first
if condition.status == "False" and (condition.reason == "ProgressDeadlineExceeded" or string.find(string.lower(condition.message or ""), "timeout") or string.find(string.lower(condition.message or ""), "failed")) then
hs.status = "Degraded"
hs.message = condition.message or "Application deployment has failed"
return hs
end
-- If progressing is true, mark it (any progressing=true condition wins)
if condition.status == "True" then
progressing = true
progressingMessage = condition.message or "Application progress status"
end
elseif condition.type == "Available" then
-- For available, we want all to be true, so any false condition wins
if condition.status == "True" then
available = true
availableMessage = condition.message or "Application availability status"
else
available = false
availableMessage = condition.message or "Application is not available"
end
end
end
end
-- Check ready replicas if specified
local readyReplicas = obj.status.readyReplicas or 0
local desiredReplicas = obj.spec.replicas or 1
-- Determine status based on conditions
if not available then
hs.status = "Degraded"
hs.message = availableMessage or "Application is not available"
return hs
end
if readyReplicas < desiredReplicas then
hs.status = "Progressing"
hs.message = string.format("Waiting for replicas to be ready (%d/%d)", readyReplicas, desiredReplicas)
return hs
end
if progressing then
hs.status = "Progressing"
hs.message = progressingMessage or "Application is still progressing"
return hs
end
-- All checks passed
hs.status = "Healthy"
hs.message = string.format("Application is healthy with %d/%d replicas ready", readyReplicas, desiredReplicas)
return hs

View File

@@ -0,0 +1,17 @@
tests:
- healthStatus:
status: Healthy
message: "Application is healthy with 2/2 replicas ready"
inputPath: testdata/healthy.yaml
- healthStatus:
status: Degraded
message: "ReplicaSet \"simple-spinapp-5b8d8bc656\" has timed out progressing."
inputPath: testdata/degraded.yaml
- healthStatus:
status: Progressing
message: "ReplicaSet \"simple-spinapp-c54f5bdb4\" has successfully progressed."
inputPath: testdata/progressing.yaml
- healthStatus:
status: Progressing
message: "Waiting for status to be available"
inputPath: testdata/no-status.yaml

View File

@@ -0,0 +1,36 @@
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVersion":"core.spinkube.dev/v1alpha1","kind":"SpinApp","metadata":{"annotations":{},"labels":{"argocd.argoproj.io/instance":"spin-apps"},"name":"simple-spinapp","namespace":"spin-apps"},"spec":{"executor":"containerd-shim-spin","image":"ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.19","replicas":2}}
creationTimestamp: '2025-02-17T20:30:09Z'
generation: 8
labels:
argocd.argoproj.io/instance: spin-apps
name: simple-spinapp
namespace: spin-apps
resourceVersion: '34094'
uid: ef4b3af3-ae67-4c49-8cbb-0cc4fb7b83ba
spec:
checks: {}
enableAutoscaling: false
executor: containerd-shim-spin
image: ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.19
replicas: 2
resources: {}
runtimeConfig: {}
status:
activeScheduler: containerd-shim-spin
conditions:
- lastTransitionTime: '2025-02-17T20:55:37Z'
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: 'True'
type: Available
- lastTransitionTime: '2025-02-17T21:05:38Z'
message: ReplicaSet "simple-spinapp-5b8d8bc656" has timed out progressing.
reason: ProgressDeadlineExceeded
status: 'False'
type: Progressing
readyReplicas: 2

View File

@@ -0,0 +1,36 @@
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVersion":"core.spinkube.dev/v1alpha1","kind":"SpinApp","metadata":{"annotations":{},"labels":{"argocd.argoproj.io/instance":"spin-apps"},"name":"simple-spinapp","namespace":"spin-apps"},"spec":{"executor":"containerd-shim-spin","image":"ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.0","replicas":2}}
creationTimestamp: '2025-02-17T20:30:09Z'
generation: 9
labels:
argocd.argoproj.io/instance: spin-apps
name: simple-spinapp
namespace: spin-apps
resourceVersion: '38985'
uid: ef4b3af3-ae67-4c49-8cbb-0cc4fb7b83ba
spec:
checks: {}
enableAutoscaling: false
executor: containerd-shim-spin
image: ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.0
replicas: 2
resources: {}
runtimeConfig: {}
status:
activeScheduler: containerd-shim-spin
conditions:
- lastTransitionTime: '2025-02-17T20:55:37Z'
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: 'True'
type: Available
- lastTransitionTime: '2025-02-17T21:37:41Z'
message: ReplicaSet "simple-spinapp-c54f5bdb4" has successfully progressed.
reason: NewReplicaSetAvailable
status: 'False'
type: Progressing
readyReplicas: 2

View File

@@ -0,0 +1,9 @@
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: simple-spinapp
namespace: spin-apps
spec:
executor: containerd-shim-spin
image: ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.0
replicas: 2

View File

@@ -0,0 +1,36 @@
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVersion":"core.spinkube.dev/v1alpha1","kind":"SpinApp","metadata":{"annotations":{},"labels":{"argocd.argoproj.io/instance":"spin-apps"},"name":"simple-spinapp","namespace":"spin-apps"},"spec":{"executor":"containerd-shim-spin","image":"ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.0","replicas":2}}
creationTimestamp: '2025-02-17T20:30:09Z'
generation: 9
labels:
argocd.argoproj.io/instance: spin-apps
name: simple-spinapp
namespace: spin-apps
resourceVersion: '38985'
uid: ef4b3af3-ae67-4c49-8cbb-0cc4fb7b83ba
spec:
checks: {}
enableAutoscaling: false
executor: containerd-shim-spin
image: ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.0
replicas: 2
resources: {}
runtimeConfig: {}
status:
activeScheduler: containerd-shim-spin
conditions:
- lastTransitionTime: '2025-02-17T20:55:37Z'
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: 'True'
type: Available
- lastTransitionTime: '2025-02-17T21:37:41Z'
message: ReplicaSet "simple-spinapp-c54f5bdb4" has successfully progressed.
reason: NewReplicaSetAvailable
status: 'True'
type: Progressing
readyReplicas: 2