From c05d6fd4a0afcbea08bb5fa66b2f1c7964977617 Mon Sep 17 00:00:00 2001 From: Will Thames Date: Fri, 21 Feb 2020 12:44:20 +1000 Subject: [PATCH] Wait should work for deployments when replicas is 0 --- molecule/default/tasks/waiter.yml | 24 ++++++++++++++++++++++++ plugins/module_utils/raw.py | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/molecule/default/tasks/waiter.yml b/molecule/default/tasks/waiter.yml index 1269c2e9..73d65d5a 100644 --- a/molecule/default/tasks/waiter.yml +++ b/molecule/default/tasks/waiter.yml @@ -244,6 +244,30 @@ - deploy.result.status.availableReplicas == deploy.result.status.replicas - updated_deploy_pods.resources[0].spec.containers[0].image.endswith(":2") + - name: scale a deployment to 0 replicas + k8s: + definition: + apiVersion: apps/v1 + kind: Deployment + metadata: + name: wait-deploy + namespace: "{{ wait_namespace }}" + spec: + replicas: 0 + selector: + matchLabels: + app: "{{ k8s_pod_name }}" + template: "{{ k8s_pod_template }}" + wait: yes + vars: + k8s_pod_name: wait-deploy + k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:2 + k8s_pod_ports: + - containerPort: 8080 + name: http + protocol: TCP + register: scale_down_deploy + - name: Pause a deployment k8s: definition: diff --git a/plugins/module_utils/raw.py b/plugins/module_utils/raw.py index 861bcbfb..43674ff4 100644 --- a/plugins/module_utils/raw.py +++ b/plugins/module_utils/raw.py @@ -462,7 +462,8 @@ def wait(self, resource, definition, sleep, timeout, state='present', condition= def _deployment_ready(deployment): # FIXME: frustratingly bool(deployment.status) is True even if status is empty # Furthermore deployment.status.availableReplicas == deployment.status.replicas == None if status is empty - return (deployment.status and deployment.status.replicas is not None and + # deployment.status.replicas is None is perfectly ok if desired replicas == 0 + return (deployment.status and deployment.status.availableReplicas == deployment.status.replicas and deployment.status.observedGeneration == deployment.metadata.generation and not deployment.status.unAvailableReplicas)