Skip to content

Commit

Permalink
feat: Extend Cluster.cluster.x-k8s.io health check (#11705)
Browse files Browse the repository at this point in the history
Signed-off-by: Jellyfrog <Jellyfrog@users.noreply.github.com>

Signed-off-by: Jellyfrog <Jellyfrog@users.noreply.github.com>
  • Loading branch information
Jellyfrog committed Dec 16, 2022
1 parent 2f16fca commit c4f6ed8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 12 deletions.
21 changes: 10 additions & 11 deletions resource_customizations/cluster.x-k8s.io/Cluster/health.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function getStatusBasedOnPhase(obj)
hs = {}
function getStatusBasedOnPhase(obj, hs)
hs.status = "Progressing"
hs.message = "Waiting for clusters"
if obj.status ~= nil and obj.status.phase ~= nil then
Expand All @@ -15,27 +14,27 @@ function getStatusBasedOnPhase(obj)
return hs
end

function getReadyContitionMessage(obj)
function getReadyContitionStatus(obj, hs)
if obj.status ~= nil and obj.status.conditions ~= nil then
for i, condition in ipairs(obj.status.conditions) do
if condition.type == "Ready" and condition.status == "False" then
return condition.message
hs.status = "Degraded"
hs.message = condition.message
return hs
end
end
end
return "Condition is unknown"
return hs
end

hs = {}
if obj.spec.paused ~= nil and obj.spec.paused then
hs = {}
hs.status = "Suspended"
hs.message = "Cluster is paused"
return hs
end

hs = getStatusBasedOnPhase(obj)
if hs.status ~= "Healthy" then
hs.message = getReadyContitionMessage(obj)
end
getStatusBasedOnPhase(obj, hs)
getReadyContitionStatus(obj, hs)

return hs
return hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests:
- healthStatus:
status: Progressing
message: 'Condition is unknown'
message: 'Waiting for clusters'
inputPath: testdata/progressing_provisioning.yaml
- healthStatus:
status: Degraded
Expand All @@ -15,3 +15,7 @@ tests:
status: Healthy
message: 'Cluster is running'
inputPath: testdata/healthy_provisioned.yaml
- healthStatus:
status: Degraded
message: 'Post "https://tvc01.foo.bar/sdk": host "tvc01.foo.bar:443" thumbprint does not match "0A:21:BD:FC:71:40:BD:96"'
inputPath: testdata/error_provisioned.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: cluster.x-k8s.io/v1alpha3
kind: Cluster
metadata:
labels:
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: 0.3.11
argocd.argoproj.io/instance: test
cluster.x-k8s.io/cluster-name: test
name: test
namespace: test
spec:
clusterNetwork:
pods:
cidrBlocks:
- 10.20.10.0/19
services:
cidrBlocks:
- 10.10.10.0/19
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1alpha3
kind: KubeadmControlPlane
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: VSphereCluster
status:
conditions:
- lastTransitionTime: '2022-12-14T07:45:14Z'
message: >-
Post "https://tvc01.foo.bar/sdk": host "tvc01.foo.bar:443"
thumbprint does not match
"0A:21:BD:FC:71:40:BD:96"
reason: VCenterUnreachable
severity: Error
status: 'False'
type: Ready
- lastTransitionTime: '2022-11-30T12:04:22Z'
status: 'True'
type: ControlPlaneInitialized
- lastTransitionTime: '2022-11-30T12:10:30Z'
status: 'True'
type: ControlPlaneReady
- lastTransitionTime: '2022-12-14T07:45:14Z'
message: >-
Post "https://tvc01.foo.bar/sdk": host "tvc01.foo.bar:443"
thumbprint does not match
"0A:21:BD:FC:71:40:BD:96"
reason: VCenterUnreachable
severity: Error
status: 'False'
type: InfrastructureReady
controlPlaneReady: true
infrastructureReady: true
observedGeneration: 2
phase: Provisioned

0 comments on commit c4f6ed8

Please sign in to comment.