feat: Implement nmstate health checks (#26506) (#26507)

Signed-off-by: sandert-k8s <sandert98@gmail.com>
This commit is contained in:
Sander Tervoert 2026-02-22 19:44:36 +01:00 committed by GitHub
parent 5e7bb39b02
commit 7a3d6f1f6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 216 additions and 0 deletions

View file

@ -0,0 +1,59 @@
-- NodeNetworkConfigurationPolicy (NNCP) is a cluster-scoped resource that defines
-- the desired network configuration for nodes in a Kubernetes cluster.
--
-- Documentation:
-- User guide (configuration & conditions): https://github.com/nmstate/kubernetes-nmstate/blob/main/docs/user-guide/102-configuration.md
-- Troubleshooting (failure states): https://github.com/nmstate/kubernetes-nmstate/blob/main/docs/user-guide/103-troubleshooting.md
--
-- Condition types and reasons are defined in:
-- https://github.com/nmstate/kubernetes-nmstate/blob/main/api/shared/nodenetworkconfigurationpolicy_types.go
--
-- NNCP exposes three active condition types:
-- Available (True) - All matched nodes successfully configured (SuccessfullyConfigured)
-- Degraded (True) - One or more nodes failed to configure (FailedToConfigure)
-- Progressing (True) - Configuration is being applied across nodes (ConfigurationProgressing)
-- Ignored (True) - Policy matches no nodes (NoMatchingNode)
--
-- ArgoCD health mapping:
-- Available=True => Healthy
-- Degraded=True => Degraded
-- Progressing=True => Progressing
-- Ignored=True => Suspended (policy intentionally matches no nodes)
-- No status yet => Progressing
local hs = {}
if obj.status ~= nil then
if obj.status.conditions ~= nil then
for i, condition in ipairs(obj.status.conditions) do
if condition.status == "True" then
local msg = condition.reason
if condition.message ~= nil and condition.message ~= "" then
msg = condition.reason .. ": " .. condition.message
end
if condition.type == "Available" then
hs.status = "Healthy"
hs.message = msg
return hs
end
if condition.type == "Degraded" then
hs.status = "Degraded"
hs.message = msg
return hs
end
if condition.type == "Progressing" then
hs.status = "Progressing"
hs.message = msg
return hs
end
if condition.type == "Ignored" then
hs.status = "Suspended"
hs.message = msg
return hs
end
end
end
end
end
hs.status = "Progressing"
hs.message = "Waiting for policy to be applied"
return hs

View file

@ -0,0 +1,21 @@
tests:
- healthStatus:
status: Progressing
message: Waiting for policy to be applied
inputPath: testdata/progressing_noStatus.yaml
- healthStatus:
status: Progressing
message: "ConfigurationProgressing: Policy is progressing 0/1 nodes finished"
inputPath: testdata/progressing_configuring.yaml
- healthStatus:
status: Healthy
message: "SuccessfullyConfigured: 1/1 nodes successfully configured"
inputPath: testdata/healthy_configured.yaml
- healthStatus:
status: Degraded
message: "FailedToConfigure: 1/1 nodes failed to configure"
inputPath: testdata/degraded_failedToConfigure.yaml
- healthStatus:
status: Suspended
message: NoMatchingNode
inputPath: testdata/suspended_noMatchingNode.yaml

View file

@ -0,0 +1,30 @@
apiVersion: nmstate.io/v1
kind: NodeNetworkConfigurationPolicy
metadata:
name: test-node-network-configuration-policy
spec:
nodeSelector:
kubernetes.io/hostname: node1
desiredState:
interfaces:
- name: eth1
type: ethernet
state: up
status:
conditions:
- lastHeartbeatTime: '2026-02-11T12:28:37Z'
lastTransitionTime: '2026-02-11T12:28:37Z'
reason: FailedToConfigure
status: 'False'
type: Available
- lastHeartbeatTime: '2026-02-11T12:28:37Z'
lastTransitionTime: '2026-02-11T12:28:37Z'
message: 1/1 nodes failed to configure
reason: FailedToConfigure
status: 'True'
type: Degraded
- lastHeartbeatTime: '2026-02-11T12:28:37Z'
lastTransitionTime: '2026-02-11T12:28:37Z'
reason: ConfigurationProgressing
status: 'False'
type: Progressing

View file

@ -0,0 +1,30 @@
apiVersion: nmstate.io/v1
kind: NodeNetworkConfigurationPolicy
metadata:
name: test-node-network-configuration-policy
spec:
nodeSelector:
kubernetes.io/hostname: node1
desiredState:
interfaces:
- name: eth1
type: ethernet
state: up
status:
conditions:
- lastHeartbeatTime: '2026-02-18T13:41:43Z'
lastTransitionTime: '2026-02-18T13:41:43Z'
message: 1/1 nodes successfully configured
reason: SuccessfullyConfigured
status: 'True'
type: Available
- lastHeartbeatTime: '2026-02-18T13:41:43Z'
lastTransitionTime: '2026-02-18T13:41:43Z'
reason: SuccessfullyConfigured
status: 'False'
type: Degraded
- lastHeartbeatTime: '2026-02-18T13:41:43Z'
lastTransitionTime: '2026-02-18T13:41:43Z'
reason: ConfigurationProgressing
status: 'False'
type: Progressing

View file

@ -0,0 +1,30 @@
apiVersion: nmstate.io/v1
kind: NodeNetworkConfigurationPolicy
metadata:
name: test-node-network-configuration-policy
spec:
nodeSelector:
kubernetes.io/hostname: node1
desiredState:
interfaces:
- name: eth1
type: ethernet
state: up
status:
conditions:
- lastHeartbeatTime: '2026-02-18T14:16:33Z'
lastTransitionTime: '2026-02-18T14:16:33Z'
reason: ConfigurationProgressing
status: Unknown
type: Available
- lastHeartbeatTime: '2026-02-18T14:16:33Z'
lastTransitionTime: '2026-02-18T14:16:33Z'
reason: ConfigurationProgressing
status: Unknown
type: Degraded
- lastHeartbeatTime: '2026-02-18T14:16:33Z'
lastTransitionTime: '2026-02-18T14:16:33Z'
message: Policy is progressing 0/1 nodes finished
reason: ConfigurationProgressing
status: 'True'
type: Progressing

View file

@ -0,0 +1,12 @@
apiVersion: nmstate.io/v1
kind: NodeNetworkConfigurationPolicy
metadata:
name: test-node-network-configuration-policy
spec:
nodeSelector:
kubernetes.io/hostname: node1
desiredState:
interfaces:
- name: eth1
type: ethernet
state: up

View file

@ -0,0 +1,34 @@
apiVersion: nmstate.io/v1
kind: NodeNetworkConfigurationPolicy
metadata:
name: test-node-network-configuration-policy
spec:
nodeSelector:
kubernetes.io/hostname: node1
desiredState:
interfaces:
- name: eth1
type: ethernet
state: up
status:
conditions:
- lastHeartbeatTime: '2026-02-18T14:16:33Z'
lastTransitionTime: '2026-02-18T14:16:33Z'
reason: NoMatchingNode
status: 'False'
type: Available
- lastHeartbeatTime: '2026-02-18T14:16:33Z'
lastTransitionTime: '2026-02-18T14:16:33Z'
reason: NoMatchingNode
status: 'False'
type: Degraded
- lastHeartbeatTime: '2026-02-18T14:16:33Z'
lastTransitionTime: '2026-02-18T14:16:33Z'
reason: NoMatchingNode
status: 'False'
type: Progressing
- lastHeartbeatTime: '2026-02-18T14:16:33Z'
lastTransitionTime: '2026-02-18T14:16:33Z'
reason: NoMatchingNode
status: 'True'
type: Ignored