feat: add health check for ClusterResourceSet (#20746)

Signed-off-by: nueavv <nuguni@kakao.com>
This commit is contained in:
1102
2024-12-16 05:56:34 +09:00
committed by GitHub
parent 22fe65b4eb
commit fdf539dc6a
5 changed files with 113 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
function getStatus(obj)
local hs = {}
hs.status = "Progressing"
hs.message = "Initializing cluster resource set"
if obj.status ~= nil then
if obj.status.conditions ~= nil then
for i, condition in ipairs(obj.status.conditions) do
-- Ready
if condition.type == "ResourcesApplied" and condition.status == "True" then
hs.status = "Healthy"
hs.message = "cluster resource set is applied"
return hs
end
-- Resources Applied
if condition.type == "ResourcesApplied" and condition.status == "False" then
hs.status = "Degraded"
hs.message = condition.message
return hs
end
end
end
end
return hs
end
local hs = getStatus(obj)
return hs

View File

@@ -0,0 +1,13 @@
tests:
- healthStatus:
status: Progressing
message: 'Initializing cluster resource set'
inputPath: testdata/progressing_resourceapplied.yaml
- healthStatus:
status: Degraded
message: 'Failed to apply resources'
inputPath: testdata/degraded_resourceapplied.yaml
- healthStatus:
status: Healthy
message: 'cluster resource set is applied'
inputPath: testdata/healthy_resourceapplied.yaml

View File

@@ -0,0 +1,27 @@
apiVersion: addons.cluster.x-k8s.io/v1beta1
kind: ClusterResourceSet
metadata:
finalizers:
- addons.cluster.x-k8s.io
generation: 1
labels:
app.argocd.io/instance: clustername
name: clustername-resource-set
namespace: capi-managed-cluster
spec:
clusterSelector:
matchLabels:
clusterName: clustername
resources:
- kind: ConfigMap
name: clustername-default-rbac
strategy: ApplyOnce
status:
conditions:
- lastTransitionTime: '2024-11-11T03:28:48Z'
message: "Failed to apply resources"
reason: RemoteClusterClientFailed
severity: Error
status: 'False'
type: ResourcesApplied
observedGeneration: 1

View File

@@ -0,0 +1,24 @@
apiVersion: addons.cluster.x-k8s.io/v1beta1
kind: ClusterResourceSet
metadata:
finalizers:
- addons.cluster.x-k8s.io
generation: 2
labels:
app.argocd.io/instance: clustername
name: clustername-resource-set
namespace: capi-managed-cluster
spec:
clusterSelector:
matchLabels:
clusterName: clustername
resources:
- kind: ConfigMap
name: clustername-default-rbac
strategy: ApplyOnce
status:
conditions:
- lastTransitionTime: '2024-11-08T08:49:13Z'
status: 'True'
type: ResourcesApplied
observedGeneration: 2

View File

@@ -0,0 +1,18 @@
apiVersion: addons.cluster.x-k8s.io/v1beta1
kind: ClusterResourceSet
metadata:
finalizers:
- addons.cluster.x-k8s.io
generation: 2
labels:
app.argocd.io/instance: clustername
name: clustername-resource-set
namespace: capi-managed-cluster
spec:
clusterSelector:
matchLabels:
clusterName: clustername
resources:
- kind: ConfigMap
name: clustername-default-rbac
strategy: ApplyOnce