Skip to content

Commit

Permalink
add health check for ClusterResourceSet
Browse files Browse the repository at this point in the history
Signed-off-by: nueavv <[email protected]>
  • Loading branch information
nueavv committed Nov 12, 2024
1 parent 40c6077 commit 3fec174
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
return hs
end
end

local hs = getStatus(obj)
return hs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3fec174

Please sign in to comment.