diff --git a/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/health.lua b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/health.lua new file mode 100644 index 0000000000..b59fccc941 --- /dev/null +++ b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/health.lua @@ -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 diff --git a/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/health_test.yaml b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/health_test.yaml new file mode 100644 index 0000000000..c067297903 --- /dev/null +++ b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/health_test.yaml @@ -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 diff --git a/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/degraded_failedToConfigure.yaml b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/degraded_failedToConfigure.yaml new file mode 100644 index 0000000000..c76f0b93f9 --- /dev/null +++ b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/degraded_failedToConfigure.yaml @@ -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 diff --git a/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/healthy_configured.yaml b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/healthy_configured.yaml new file mode 100644 index 0000000000..5af640ef88 --- /dev/null +++ b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/healthy_configured.yaml @@ -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 diff --git a/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/progressing_configuring.yaml b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/progressing_configuring.yaml new file mode 100644 index 0000000000..986c1f82a5 --- /dev/null +++ b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/progressing_configuring.yaml @@ -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 diff --git a/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/progressing_noStatus.yaml b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/progressing_noStatus.yaml new file mode 100644 index 0000000000..3bb421de45 --- /dev/null +++ b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/progressing_noStatus.yaml @@ -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 diff --git a/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/suspended_noMatchingNode.yaml b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/suspended_noMatchingNode.yaml new file mode 100644 index 0000000000..e900c2dfdb --- /dev/null +++ b/resource_customizations/nmstate.io/NodeNetworkConfigurationPolicy/testdata/suspended_noMatchingNode.yaml @@ -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