Fix waiting on StatefulSet scale down (#391)

Fix waiting on StatefulSet scale down

SUMMARY

When scaling a StatefulSet down to 0 replicas the wait will fail
because some properties of the status (readyReplicas, updatedReplicas)
will not exist. These are probably defined as omitempty in the API and
since the value is zero are not present in the response.

Fixes #203
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

k8s_scale
ADDITIONAL INFORMATION

Reviewed-by: Gonéri Le Bouder <goneri@lebouder.net>
This commit is contained in:
Mike Graves
2022-03-11 12:32:12 -05:00
committed by GitHub
parent 30e84faa24
commit d68dec3b90
3 changed files with 56 additions and 2 deletions

View File

@@ -341,6 +341,54 @@
- scale_out.changed
- scale_out.results | map(attribute='result.status.replicas') | list | unique == [2]
- name: Create a StatefulSet
kubernetes.core.k8s:
wait: yes
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
definition:
apiVersion: apps/v1
kind: StatefulSet
metadata:
namespace: "{{ scale_namespace }}"
name: scale-set
spec:
replicas: 2
selector:
matchLabels:
app: foo
template:
metadata:
labels:
app: foo
spec:
terminationGracePeriodSeconds: 10
containers:
- image: busybox
name: busybox
command:
- sleep
- "600"
register: output
- assert:
that:
- output.result.status.replicas == 2
- name: Wait for StatefulSet to scale down to 0
kubernetes.core.k8s_scale:
kind: StatefulSet
api_version: apps/v1
name: scale-set
namespace: "{{ scale_namespace }}"
replicas: 0
wait: yes
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
register: output
- assert:
that:
- output.result.status.replicas == 0
always:
- name: Remove namespace
k8s: