From f980187f1711a79f2d7dc1ec87033ee9410104d9 Mon Sep 17 00:00:00 2001 From: Jingchao Date: Thu, 12 Sep 2024 06:32:37 +0800 Subject: [PATCH] fix: openkruise health check npe error #19545 (#19660) * test: add broken unit test data Signed-off-by: Jingchao * fix: npe error in kruise ds health-check Signed-off-by: Jingchao --------- Signed-off-by: Jingchao --- .../apps.kruise.io/DaemonSet/health.lua | 2 +- .../apps.kruise.io/DaemonSet/health_test.yaml | 4 +++ .../no-update-strategy-partition.yaml | 34 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 resource_customizations/apps.kruise.io/DaemonSet/testdata/no-update-strategy-partition.yaml diff --git a/resource_customizations/apps.kruise.io/DaemonSet/health.lua b/resource_customizations/apps.kruise.io/DaemonSet/health.lua index 7705bcc332..30ccdc85da 100644 --- a/resource_customizations/apps.kruise.io/DaemonSet/health.lua +++ b/resource_customizations/apps.kruise.io/DaemonSet/health.lua @@ -8,7 +8,7 @@ if obj.status ~= nil then hs.status = "Suspended" hs.message = "Daemonset is paused" return hs - elseif obj.spec.updateStrategy.rollingUpdate.partition ~= 0 and obj.metadata.generation > 1 then + elseif (obj.spec.updateStrategy.rollingUpdate.partition ~= nil) and (obj.spec.updateStrategy.rollingUpdate.partition ~= 0 and obj.metadata.generation > 1) then if obj.status.updatedNumberScheduled > (obj.status.desiredNumberScheduled - obj.spec.updateStrategy.rollingUpdate.partition) then hs.status = "Suspended" hs.message = "Daemonset needs manual intervention" diff --git a/resource_customizations/apps.kruise.io/DaemonSet/health_test.yaml b/resource_customizations/apps.kruise.io/DaemonSet/health_test.yaml index 0a8c829267..a1d2579d2e 100644 --- a/resource_customizations/apps.kruise.io/DaemonSet/health_test.yaml +++ b/resource_customizations/apps.kruise.io/DaemonSet/health_test.yaml @@ -11,6 +11,10 @@ tests: status: Progressing message: "Waiting for initialization" inputPath: testdata/unknown.yaml + - healthStatus: + status: Progressing + message: "Waiting for initialization" + inputPath: testdata/no-update-strategy-partition.yaml - healthStatus: status: Suspended message: "Daemonset is paused" diff --git a/resource_customizations/apps.kruise.io/DaemonSet/testdata/no-update-strategy-partition.yaml b/resource_customizations/apps.kruise.io/DaemonSet/testdata/no-update-strategy-partition.yaml new file mode 100644 index 0000000000..765378b0c6 --- /dev/null +++ b/resource_customizations/apps.kruise.io/DaemonSet/testdata/no-update-strategy-partition.yaml @@ -0,0 +1,34 @@ +apiVersion: apps.kruise.io/v1alpha1 +kind: DaemonSet +metadata: + name: rdma-device-plugin + namespace: nvidia-gpu + generation: 2 +spec: + selector: + matchLabels: + app-name: rdma-device-plugin-pod + template: + metadata: + labels: + app-name: rdma-device-plugin-pod + spec: + containers: + image: 'my-k8s-rdmaplugin' + imagePullPolicy: IfNotPresent + name: k8s-rdma-device-plugin + hostNetwork: true + updateStrategy: + rollingUpdate: + maxSurge: 0 + maxUnavailable: 50 + rollingUpdateType: Standard + type: RollingUpdate +status: + currentNumberScheduled: 0 + daemonSetHash: 5998d4d4d7 + desiredNumberScheduled: 0 + numberMisscheduled: 0 + numberReady: 0 + observedGeneration: 2 + updatedNumberScheduled: 0