From 0bbc9ca9992c217f3cef523b99a11e3ee7c69d18 Mon Sep 17 00:00:00 2001 From: Mike Graves Date: Wed, 19 May 2021 09:29:22 -0400 Subject: [PATCH] Account for updated pods when waiting on DaemonSet (#102) * 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. * Add changelog fragment --- .../fragments/102-wait-updated-daemonset-pods.yaml | 3 +++ molecule/default/tasks/waiter.yml | 9 +++++++++ plugins/module_utils/common.py | 1 + 3 files changed, 13 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 00000000..2fc981de --- /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). diff --git a/molecule/default/tasks/waiter.yml b/molecule/default/tasks/waiter.yml index 303cb2d1..44fc42b3 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 06f31dae..de3c9282 100644 --- a/plugins/module_utils/common.py +++ b/plugins/module_utils/common.py @@ -403,6 +403,7 @@ class K8sAnsibleMixin(object): 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)