-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add health check for ClusterResourceSet
Signed-off-by: nueavv <nuguni@kakao.com>
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
resource_customizations/cluster.x-k8s.io/ClusterResourceSet/health.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 13 additions & 0 deletions
13
resource_customizations/cluster.x-k8s.io/ClusterResourceSet/health_test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
27 changes: 27 additions & 0 deletions
27
...customizations/cluster.x-k8s.io/ClusterResourceSet/testdata/degraded_resourceapplied.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 24 additions & 0 deletions
24
..._customizations/cluster.x-k8s.io/ClusterResourceSet/testdata/healthy_resourceapplied.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
18 changes: 18 additions & 0 deletions
18
...tomizations/cluster.x-k8s.io/ClusterResourceSet/testdata/progressing_resourceapplied.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |