mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
feat(health): Implement spinkube SpinApp CRD health checks (#21896)
Signed-off-by: lukepatrick <lukephilips@gmail.com>
This commit is contained in:
71
resource_customizations/core.spinkube.dev/SpinApp/health.lua
Normal file
71
resource_customizations/core.spinkube.dev/SpinApp/health.lua
Normal 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
|
||||
@@ -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
|
||||
36
resource_customizations/core.spinkube.dev/SpinApp/testdata/degraded.yaml
vendored
Normal file
36
resource_customizations/core.spinkube.dev/SpinApp/testdata/degraded.yaml
vendored
Normal 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
|
||||
36
resource_customizations/core.spinkube.dev/SpinApp/testdata/healthy.yaml
vendored
Normal file
36
resource_customizations/core.spinkube.dev/SpinApp/testdata/healthy.yaml
vendored
Normal 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
|
||||
9
resource_customizations/core.spinkube.dev/SpinApp/testdata/no-status.yaml
vendored
Normal file
9
resource_customizations/core.spinkube.dev/SpinApp/testdata/no-status.yaml
vendored
Normal 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
|
||||
36
resource_customizations/core.spinkube.dev/SpinApp/testdata/progressing.yaml
vendored
Normal file
36
resource_customizations/core.spinkube.dev/SpinApp/testdata/progressing.yaml
vendored
Normal 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
|
||||
Reference in New Issue
Block a user