-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement cluster-api MachinePool CRD health checks (#19595)
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
Showing
5 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
resource_customizations/cluster.x-k8s.io/MachinePool/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,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 |
13 changes: 13 additions & 0 deletions
13
resource_customizations/cluster.x-k8s.io/MachinePool/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: 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 |
25 changes: 25 additions & 0 deletions
25
resource_customizations/cluster.x-k8s.io/MachinePool/testdata/degraded_failed.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,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 |
57 changes: 57 additions & 0 deletions
57
resource_customizations/cluster.x-k8s.io/MachinePool/testdata/healthy_provisioned.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,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 |
44 changes: 44 additions & 0 deletions
44
resource_customizations/cluster.x-k8s.io/MachinePool/testdata/progressing_provisioning.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,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 |