Skip to content

Commit

Permalink
feat: Implement cluster-api MachinePool CRD health checks (#19595)
Browse files Browse the repository at this point in the history
Signed-off-by: afarbos <farbos.arnaud@gmail.com>

---------

Signed-off-by: Arnaud Farbos <farbos.arnaud@gmail.com>
Signed-off-by: afarbos <farbos.arnaud@gmail.com>
  • Loading branch information
afarbos committed Aug 22, 2024
1 parent 86322b5 commit 59e0091
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 0 deletions.
48 changes: 48 additions & 0 deletions resource_customizations/cluster.x-k8s.io/MachinePool/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- Reference CRD can be found here:
-- https://doc.crds.dev/github.com/kubernetes-sigs/cluster-api/cluster.x-k8s.io/MachinePool/v1beta1@v1.8.1

function getStatusBasedOnPhase(obj, hs)
-- Phases can be found here:
-- https://github.com/kubernetes-sigs/cluster-api/blob/release-1.8/exp/api/v1beta1/machinepool_types.go#L139-L182
if obj.status ~= nil and obj.status.phase ~= nil then
hs.message = "MachinePool is " .. obj.status.phase
if obj.status.phase == "Running" then
hs.status = "Healthy"
end
if obj.status.phase == "Failed" or obj.status.phase == "Unknown" then
hs.status = "Degraded"
end
end
return hs
end

function getConditionStatuses(obj, hs)
local extraInfo = ""
if obj.status ~= nil and obj.status.conditions ~= nil then
for i, condition in ipairs(obj.status.conditions) do
if condition.type ~= nil and condition.status == "False" then
if extraInfo ~= "" then
extraInfo = extraInfo .. ", "
end
extraInfo = extraInfo .. "Not " .. condition.type
if condition.reason ~= nil then
extraInfo = extraInfo .. " (" .. condition.reason .. ")"
end
end
end
end
if extraInfo ~= "" then
hs.message = hs.message .. ": " .. extraInfo
end

return hs
end

local hs = {}
hs.status = "Progressing"
hs.message = ""

getStatusBasedOnPhase(obj, hs)
getConditionStatuses(obj, hs)

return hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests:
- healthStatus:
status: Healthy
message: 'MachinePool is Running'
inputPath: testdata/healthy_provisioned.yaml
- healthStatus:
status: Progressing
message: 'MachinePool is Provisioning: Not Ready (WaitingForInfrastructure), Not InfrastructureReady (WaitingForInfrastructure)'
inputPath: testdata/progressing_provisioning.yaml
- healthStatus:
status: Degraded
message: 'MachinePool is Failed'
inputPath: testdata/degraded_failed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachinePool
metadata:
labels:
argocd.argoproj.io/instance: foo
cluster.x-k8s.io/cluster-name: foo
name: foo-pool
namespace: default
spec:
clusterName: foo
replicas: 3
template:
metadata: {}
spec:
bootstrap:
dataSecretName: ""
clusterName: foo
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
kind: AWSManagedMachinePool
name: foo-pool
namespace: default
version: v1.30.0
status:
phase: Failed
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachinePool
metadata:
labels:
argocd.argoproj.io/instance: foo
cluster.x-k8s.io/cluster-name: foo
name: foo-pool
namespace: default
spec:
clusterName: foo
replicas: 3
template:
metadata: {}
spec:
bootstrap:
dataSecretName: ""
clusterName: foo
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
kind: AWSManagedMachinePool
name: foo-pool
namespace: default
version: v1.30.0
status:
availableReplicas: 3
bootstrapReady: true
conditions:
- lastTransitionTime: '2024-08-19T20:33:02Z'
status: 'True'
type: Ready
- lastTransitionTime: '2024-08-19T20:18:31Z'
status: 'True'
type: BootstrapReady
- lastTransitionTime: '2024-08-19T20:33:02Z'
status: 'True'
type: InfrastructureReady
- lastTransitionTime: '2024-08-19T20:18:31Z'
status: 'True'
type: ReplicasReady
infrastructureReady: true
nodeRefs:
- apiVersion: v1
kind: Node
name: ip-18-232-50-123-ec2.internal
uid: e4b3a44f-1c2d-4fd3-bb9e-3b0e08787a5a
- apiVersion: v1
kind: Node
name: ip-52-23-45-67-ec2.internal
uid: 2b9dabe5-3a1d-429a-985b-5e7ffb9649c6
- apiVersion: v1
kind: Node
name: ip-34-207-89-12-ec2.internal
uid: 6f94031a-d3e4-48f7-bc94-22bb9b687f5e
observedGeneration: 2
phase: Running
readyReplicas: 3
replicas: 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachinePool
metadata:
labels:
argocd.argoproj.io/instance: foo
cluster.x-k8s.io/cluster-name: foo
name: foo-pool
namespace: default
spec:
clusterName: foo
replicas: 3
template:
metadata: {}
spec:
bootstrap:
dataSecretName: ""
clusterName: foo
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
kind: AWSManagedMachinePool
name: foo-pool
namespace: default
version: v1.30.0
status:
bootstrapReady: true
conditions:
- lastTransitionTime: '2024-08-19T20:26:30Z'
reason: WaitingForInfrastructure
severity: Info
status: 'False'
type: Ready
- lastTransitionTime: '2024-08-19T20:26:30Z'
status: 'True'
type: BootstrapReady
- lastTransitionTime: '2024-08-19T20:26:30Z'
reason: WaitingForInfrastructure
severity: Info
status: 'False'
type: InfrastructureReady
- lastTransitionTime: '2024-08-19T20:26:30Z'
status: 'True'
type: ReplicasReady
observedGeneration: 1
phase: Provisioning

0 comments on commit 59e0091

Please # to comment.