From 6d8894cfc1a57ccbd013ccbe5df504043cb3548f Mon Sep 17 00:00:00 2001 From: Mike Graves Date: Tue, 11 May 2021 14:55:17 -0400 Subject: [PATCH 1/2] Account for updated pods when waiting on DaemonSet The exising logic that's used to determine when a DaemonSet is ready fails to account for the fact that a RollingUpdate first kills the pod and then creates a new one. Simply checking if the desiredNumberScheduled equals the numberReady will succeed in cases when the old pod takes time to shut down, and would report that the new Deployment is ready despite the fact that the old pod has not been replaced, yet. --- molecule/default/tasks/waiter.yml | 9 +++++++++ plugins/module_utils/common.py | 1 + 2 files changed, 10 insertions(+) diff --git a/molecule/default/tasks/waiter.yml b/molecule/default/tasks/waiter.yml index 303cb2d1bb..44fc42b3ff 100644 --- a/molecule/default/tasks/waiter.yml +++ b/molecule/default/tasks/waiter.yml @@ -54,6 +54,9 @@ vars: k8s_pod_name: wait-ds k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:1 + k8s_pod_command: + - sleep + - "600" register: ds - name: Check that daemonset wait worked @@ -82,6 +85,9 @@ vars: k8s_pod_name: wait-ds k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:2 + k8s_pod_command: + - sleep + - "600" register: update_ds_check_mode check_mode: yes @@ -112,6 +118,9 @@ vars: k8s_pod_name: wait-ds k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:3 + k8s_pod_command: + - sleep + - "600" register: ds - name: Get updated pods diff --git a/plugins/module_utils/common.py b/plugins/module_utils/common.py index 86b7ae9ac5..02d22c095d 100644 --- a/plugins/module_utils/common.py +++ b/plugins/module_utils/common.py @@ -403,6 +403,7 @@ def _pod_ready(pod): def _daemonset_ready(daemonset): return (daemonset.status and daemonset.status.desiredNumberScheduled is not None + and daemonset.status.updatedNumberScheduled == daemonset.status.desiredNumberScheduled and daemonset.status.numberReady == daemonset.status.desiredNumberScheduled and daemonset.status.observedGeneration == daemonset.metadata.generation and not daemonset.status.unavailableReplicas) From b98fbe893b03bb98d3a37f08bb61f6ad121a8305 Mon Sep 17 00:00:00 2001 From: Mike Graves Date: Mon, 17 May 2021 15:04:05 -0400 Subject: [PATCH 2/2] Add changelog fragment --- changelogs/fragments/102-wait-updated-daemonset-pods.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/102-wait-updated-daemonset-pods.yaml diff --git a/changelogs/fragments/102-wait-updated-daemonset-pods.yaml b/changelogs/fragments/102-wait-updated-daemonset-pods.yaml new file mode 100644 index 0000000000..2fc981de2f --- /dev/null +++ b/changelogs/fragments/102-wait-updated-daemonset-pods.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - k8s - wait for all pods to update when rolling out daemonset changes (https://github.com/ansible-collections/kubernetes.core/pull/102).