select wait

This commit is contained in:
abikouo
2021-05-20 14:30:19 +02:00
parent 483c91ca22
commit a20a1f6f01
2 changed files with 437 additions and 434 deletions

View File

@@ -20,111 +20,111 @@
assert:
that: (pod_list.resources | count) > 5
- name: Include access_review.yml
include_tasks:
file: tasks/access_review.yml
apply:
tags: [ access_review, k8s ]
tags:
- always
- name: Include append_hash.yml
include_tasks:
file: tasks/append_hash.yml
apply:
tags: [ append_hash, k8s ]
tags:
- always
- name: Include apply.yml
include_tasks:
file: tasks/apply.yml
apply:
tags: [ apply, k8s ]
tags:
- always
- name: Include cluster_info.yml
include_tasks:
file: tasks/cluster_info.yml
apply:
tags: [ cluster_info, k8s ]
tags:
- always
- name: Include crd.yml
include_tasks:
file: tasks/crd.yml
apply:
tags: [ crd, k8s ]
tags:
- always
- name: Include delete.yml
include_tasks:
file: tasks/delete.yml
apply:
tags: [ delete, k8s ]
tags:
- always
- name: Include exec.yml
include_tasks:
file: tasks/exec.yml
apply:
tags: [ exec, k8s ]
tags:
- always
- name: Include full.yml
include_tasks:
file: tasks/full.yml
apply:
tags: [ full, k8s ]
tags:
- always
- name: Include gc.yml
include_tasks:
file: tasks/gc.yml
apply:
tags: [ gc, k8s ]
tags:
- always
- name: Include info.yml
include_tasks:
file: tasks/info.yml
apply:
tags: [ info, k8s ]
tags:
- always
- name: Include lists.yml
include_tasks:
file: tasks/lists.yml
apply:
tags: [ lists, k8s ]
tags:
- always
- name: Include log.yml
include_tasks:
file: tasks/log.yml
apply:
tags: [ log, k8s ]
tags:
- always
- name: Include rollback.yml
include_tasks:
file: tasks/rollback.yml
apply:
tags: [ rollback, k8s ]
tags:
- always
- name: Include scale.yml
include_tasks:
file: tasks/scale.yml
apply:
tags: [ scale, k8s ]
tags:
- always
- name: Include template.yml
include_tasks:
file: tasks/template.yml
apply:
tags: [ template, k8s ]
tags:
- always
# - name: Include access_review.yml
# include_tasks:
# file: tasks/access_review.yml
# apply:
# tags: [ access_review, k8s ]
# tags:
# - always
# - name: Include append_hash.yml
# include_tasks:
# file: tasks/append_hash.yml
# apply:
# tags: [ append_hash, k8s ]
# tags:
# - always
# - name: Include apply.yml
# include_tasks:
# file: tasks/apply.yml
# apply:
# tags: [ apply, k8s ]
# tags:
# - always
# - name: Include cluster_info.yml
# include_tasks:
# file: tasks/cluster_info.yml
# apply:
# tags: [ cluster_info, k8s ]
# tags:
# - always
# - name: Include crd.yml
# include_tasks:
# file: tasks/crd.yml
# apply:
# tags: [ crd, k8s ]
# tags:
# - always
# - name: Include delete.yml
# include_tasks:
# file: tasks/delete.yml
# apply:
# tags: [ delete, k8s ]
# tags:
# - always
# - name: Include exec.yml
# include_tasks:
# file: tasks/exec.yml
# apply:
# tags: [ exec, k8s ]
# tags:
# - always
# - name: Include full.yml
# include_tasks:
# file: tasks/full.yml
# apply:
# tags: [ full, k8s ]
# tags:
# - always
# - name: Include gc.yml
# include_tasks:
# file: tasks/gc.yml
# apply:
# tags: [ gc, k8s ]
# tags:
# - always
# - name: Include info.yml
# include_tasks:
# file: tasks/info.yml
# apply:
# tags: [ info, k8s ]
# tags:
# - always
# - name: Include lists.yml
# include_tasks:
# file: tasks/lists.yml
# apply:
# tags: [ lists, k8s ]
# tags:
# - always
# - name: Include log.yml
# include_tasks:
# file: tasks/log.yml
# apply:
# tags: [ log, k8s ]
# tags:
# - always
# - name: Include rollback.yml
# include_tasks:
# file: tasks/rollback.yml
# apply:
# tags: [ rollback, k8s ]
# tags:
# - always
# - name: Include scale.yml
# include_tasks:
# file: tasks/scale.yml
# apply:
# tags: [ scale, k8s ]
# tags:
# - always
# - name: Include template.yml
# include_tasks:
# file: tasks/template.yml
# apply:
# tags: [ template, k8s ]
# tags:
# - always
- name: Include waiter.yml
include_tasks:
file: tasks/waiter.yml
@@ -149,10 +149,10 @@
tags:
- always
roles:
- role: helm
tags:
- helm
# roles:
# - role: helm
# tags:
# - helm
post_tasks:
- name: Ensure namespace exists

View File

@@ -11,358 +11,358 @@
metadata:
name: "{{ wait_namespace }}"
- name: Add a simple pod
k8s:
definition:
apiVersion: v1
kind: Pod
metadata:
name: "{{ k8s_pod_name }}"
namespace: "{{ wait_namespace }}"
spec: "{{ k8s_pod_spec }}"
wait: yes
vars:
k8s_pod_name: wait-pod
k8s_pod_image: alpine:3.8
k8s_pod_command:
- sleep
- "10000"
register: wait_pod
ignore_errors: yes
# - name: Add a simple pod
# k8s:
# definition:
# apiVersion: v1
# kind: Pod
# metadata:
# name: "{{ k8s_pod_name }}"
# namespace: "{{ wait_namespace }}"
# spec: "{{ k8s_pod_spec }}"
# wait: yes
# vars:
# k8s_pod_name: wait-pod
# k8s_pod_image: alpine:3.8
# k8s_pod_command:
# - sleep
# - "10000"
# register: wait_pod
# ignore_errors: yes
- name: Assert that pod creation succeeded
assert:
that:
- wait_pod is successful
# - name: Assert that pod creation succeeded
# assert:
# that:
# - wait_pod is successful
- name: Add a daemonset
k8s:
definition:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: wait-daemonset
namespace: "{{ wait_namespace }}"
spec:
selector:
matchLabels:
app: "{{ k8s_pod_name }}"
template: "{{ k8s_pod_template }}"
wait: yes
wait_sleep: 5
wait_timeout: 180
vars:
k8s_pod_name: wait-ds
k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:1
k8s_pod_command:
- sleep
- "600"
register: ds
# - name: Add a daemonset
# k8s:
# definition:
# apiVersion: apps/v1
# kind: DaemonSet
# metadata:
# name: wait-daemonset
# namespace: "{{ wait_namespace }}"
# spec:
# selector:
# matchLabels:
# app: "{{ k8s_pod_name }}"
# template: "{{ k8s_pod_template }}"
# wait: yes
# wait_sleep: 5
# wait_timeout: 180
# 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
assert:
that:
- ds.result.status.currentNumberScheduled == ds.result.status.desiredNumberScheduled
# - name: Check that daemonset wait worked
# assert:
# that:
# - ds.result.status.currentNumberScheduled == ds.result.status.desiredNumberScheduled
- name: Update a daemonset in check_mode
k8s:
definition:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: wait-daemonset
namespace: "{{ wait_namespace }}"
spec:
selector:
matchLabels:
app: "{{ k8s_pod_name }}"
updateStrategy:
type: RollingUpdate
template: "{{ k8s_pod_template }}"
wait: yes
wait_sleep: 3
wait_timeout: 180
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
# - name: Update a daemonset in check_mode
# k8s:
# definition:
# apiVersion: apps/v1
# kind: DaemonSet
# metadata:
# name: wait-daemonset
# namespace: "{{ wait_namespace }}"
# spec:
# selector:
# matchLabels:
# app: "{{ k8s_pod_name }}"
# updateStrategy:
# type: RollingUpdate
# template: "{{ k8s_pod_template }}"
# wait: yes
# wait_sleep: 3
# wait_timeout: 180
# 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
- name: Check that check_mode result contains the changes
assert:
that:
- update_ds_check_mode is changed
- "update_ds_check_mode.result.spec.template.spec.containers[0].image == 'gcr.io/kuar-demo/kuard-amd64:2'"
# - name: Check that check_mode result contains the changes
# assert:
# that:
# - update_ds_check_mode is changed
# - "update_ds_check_mode.result.spec.template.spec.containers[0].image == 'gcr.io/kuar-demo/kuard-amd64:2'"
- name: Update a daemonset
k8s:
definition:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: wait-daemonset
namespace: "{{ wait_namespace }}"
spec:
selector:
matchLabels:
app: "{{ k8s_pod_name }}"
updateStrategy:
type: RollingUpdate
template: "{{ k8s_pod_template }}"
wait: yes
wait_sleep: 3
wait_timeout: 180
vars:
k8s_pod_name: wait-ds
k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:3
k8s_pod_command:
- sleep
- "600"
register: ds
# - name: Update a daemonset
# k8s:
# definition:
# apiVersion: apps/v1
# kind: DaemonSet
# metadata:
# name: wait-daemonset
# namespace: "{{ wait_namespace }}"
# spec:
# selector:
# matchLabels:
# app: "{{ k8s_pod_name }}"
# updateStrategy:
# type: RollingUpdate
# template: "{{ k8s_pod_template }}"
# wait: yes
# wait_sleep: 3
# wait_timeout: 180
# 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
k8s_info:
api_version: v1
kind: Pod
namespace: "{{ wait_namespace }}"
label_selectors:
- app=wait-ds
field_selectors:
- status.phase=Running
register: updated_ds_pods
# - name: Get updated pods
# k8s_info:
# api_version: v1
# kind: Pod
# namespace: "{{ wait_namespace }}"
# label_selectors:
# - app=wait-ds
# field_selectors:
# - status.phase=Running
# register: updated_ds_pods
- name: Check that daemonset wait worked
assert:
that:
- ds.result.status.currentNumberScheduled == ds.result.status.desiredNumberScheduled
- updated_ds_pods.resources[0].spec.containers[0].image.endswith(":3")
# - name: Check that daemonset wait worked
# assert:
# that:
# - ds.result.status.currentNumberScheduled == ds.result.status.desiredNumberScheduled
# - updated_ds_pods.resources[0].spec.containers[0].image.endswith(":3")
- name: Add a crashing pod
k8s:
definition:
apiVersion: v1
kind: Pod
metadata:
name: "{{ k8s_pod_name }}"
namespace: "{{ wait_namespace }}"
spec: "{{ k8s_pod_spec }}"
wait: yes
wait_sleep: 1
wait_timeout: 30
vars:
k8s_pod_name: wait-crash-pod
k8s_pod_image: alpine:3.8
k8s_pod_command:
- /bin/false
register: crash_pod
ignore_errors: yes
# - name: Add a crashing pod
# k8s:
# definition:
# apiVersion: v1
# kind: Pod
# metadata:
# name: "{{ k8s_pod_name }}"
# namespace: "{{ wait_namespace }}"
# spec: "{{ k8s_pod_spec }}"
# wait: yes
# wait_sleep: 1
# wait_timeout: 30
# vars:
# k8s_pod_name: wait-crash-pod
# k8s_pod_image: alpine:3.8
# k8s_pod_command:
# - /bin/false
# register: crash_pod
# ignore_errors: yes
- name: Check that task failed
assert:
that:
- crash_pod is failed
# - name: Check that task failed
# assert:
# that:
# - crash_pod is failed
- name: Use a non-existent image
k8s:
definition:
apiVersion: v1
kind: Pod
metadata:
name: "{{ k8s_pod_name }}"
namespace: "{{ wait_namespace }}"
spec: "{{ k8s_pod_spec }}"
wait: yes
wait_sleep: 1
wait_timeout: 30
vars:
k8s_pod_name: wait-no-image-pod
k8s_pod_image: i_made_this_up:and_this_too
register: no_image_pod
ignore_errors: yes
# - name: Use a non-existent image
# k8s:
# definition:
# apiVersion: v1
# kind: Pod
# metadata:
# name: "{{ k8s_pod_name }}"
# namespace: "{{ wait_namespace }}"
# spec: "{{ k8s_pod_spec }}"
# wait: yes
# wait_sleep: 1
# wait_timeout: 30
# vars:
# k8s_pod_name: wait-no-image-pod
# k8s_pod_image: i_made_this_up:and_this_too
# register: no_image_pod
# ignore_errors: yes
- name: Check that task failed
assert:
that:
- no_image_pod is failed
# - name: Check that task failed
# assert:
# that:
# - no_image_pod is failed
- name: Add a deployment
k8s:
definition:
apiVersion: apps/v1
kind: Deployment
metadata:
name: wait-deploy
namespace: "{{ wait_namespace }}"
spec:
replicas: 3
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:1
k8s_pod_ports:
- containerPort: 8080
name: http
protocol: TCP
# - name: Add a deployment
# k8s:
# definition:
# apiVersion: apps/v1
# kind: Deployment
# metadata:
# name: wait-deploy
# namespace: "{{ wait_namespace }}"
# spec:
# replicas: 3
# 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:1
# k8s_pod_ports:
# - containerPort: 8080
# name: http
# protocol: TCP
register: deploy
# register: deploy
- name: Check that deployment wait worked
assert:
that:
- deploy.result.status.availableReplicas == deploy.result.status.replicas
# - name: Check that deployment wait worked
# assert:
# that:
# - deploy.result.status.availableReplicas == deploy.result.status.replicas
- name: Update a deployment
k8s:
definition:
apiVersion: apps/v1
kind: Deployment
metadata:
name: wait-deploy
namespace: "{{ wait_namespace }}"
spec:
replicas: 3
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: update_deploy
# - name: Update a deployment
# k8s:
# definition:
# apiVersion: apps/v1
# kind: Deployment
# metadata:
# name: wait-deploy
# namespace: "{{ wait_namespace }}"
# spec:
# replicas: 3
# 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: update_deploy
# It looks like the Deployment is updated to have the desired state *before* the pods are terminated
# Wait a couple of seconds to allow the old pods to at least get to Terminating state
- name: Avoid race condition
pause:
seconds: 2
# # It looks like the Deployment is updated to have the desired state *before* the pods are terminated
# # Wait a couple of seconds to allow the old pods to at least get to Terminating state
# - name: Avoid race condition
# pause:
# seconds: 2
- name: Get updated pods
k8s_info:
api_version: v1
kind: Pod
namespace: "{{ wait_namespace }}"
label_selectors:
- app=wait-deploy
field_selectors:
- status.phase=Running
register: updated_deploy_pods
until: updated_deploy_pods.resources[0].spec.containers[0].image.endswith(':2')
retries: 6
delay: 5
# - name: Get updated pods
# k8s_info:
# api_version: v1
# kind: Pod
# namespace: "{{ wait_namespace }}"
# label_selectors:
# - app=wait-deploy
# field_selectors:
# - status.phase=Running
# register: updated_deploy_pods
# until: updated_deploy_pods.resources[0].spec.containers[0].image.endswith(':2')
# retries: 6
# delay: 5
- name: Check that deployment wait worked
assert:
that:
- deploy.result.status.availableReplicas == deploy.result.status.replicas
# - name: Check that deployment wait worked
# assert:
# that:
# - deploy.result.status.availableReplicas == deploy.result.status.replicas
- name: Pause a deployment
k8s:
definition:
apiVersion: apps/v1
kind: Deployment
metadata:
name: wait-deploy
namespace: "{{ wait_namespace }}"
spec:
paused: True
apply: no
wait: yes
wait_condition:
type: Progressing
status: Unknown
reason: DeploymentPaused
register: pause_deploy
# - name: Pause a deployment
# k8s:
# definition:
# apiVersion: apps/v1
# kind: Deployment
# metadata:
# name: wait-deploy
# namespace: "{{ wait_namespace }}"
# spec:
# paused: True
# apply: no
# wait: yes
# wait_condition:
# type: Progressing
# status: Unknown
# reason: DeploymentPaused
# register: pause_deploy
- name: Check that paused deployment wait worked
assert:
that:
- condition.reason == "DeploymentPaused"
- condition.status == "Unknown"
vars:
condition: '{{ pause_deploy.result.status.conditions[1] }}'
# - name: Check that paused deployment wait worked
# assert:
# that:
# - condition.reason == "DeploymentPaused"
# - condition.status == "Unknown"
# vars:
# condition: '{{ pause_deploy.result.status.conditions[1] }}'
- name: Add a service based on the deployment
k8s:
definition:
apiVersion: v1
kind: Service
metadata:
name: wait-svc
namespace: "{{ wait_namespace }}"
spec:
selector:
app: "{{ k8s_pod_name }}"
ports:
- port: 8080
targetPort: 8080
protocol: TCP
wait: yes
vars:
k8s_pod_name: wait-deploy
register: service
# - name: Add a service based on the deployment
# k8s:
# definition:
# apiVersion: v1
# kind: Service
# metadata:
# name: wait-svc
# namespace: "{{ wait_namespace }}"
# spec:
# selector:
# app: "{{ k8s_pod_name }}"
# ports:
# - port: 8080
# targetPort: 8080
# protocol: TCP
# wait: yes
# vars:
# k8s_pod_name: wait-deploy
# register: service
- name: Assert that waiting for service works
assert:
that:
- service is successful
# - name: Assert that waiting for service works
# assert:
# that:
# - service is successful
- name: Add a crashing deployment
k8s:
definition:
apiVersion: apps/v1
kind: Deployment
metadata:
name: wait-crash-deploy
namespace: "{{ wait_namespace }}"
spec:
replicas: 3
selector:
matchLabels:
app: "{{ k8s_pod_name }}"
template: "{{ k8s_pod_template }}"
wait: yes
vars:
k8s_pod_name: wait-crash-deploy
k8s_pod_image: alpine:3.8
k8s_pod_command:
- /bin/false
register: wait_crash_deploy
ignore_errors: yes
# - name: Add a crashing deployment
# k8s:
# definition:
# apiVersion: apps/v1
# kind: Deployment
# metadata:
# name: wait-crash-deploy
# namespace: "{{ wait_namespace }}"
# spec:
# replicas: 3
# selector:
# matchLabels:
# app: "{{ k8s_pod_name }}"
# template: "{{ k8s_pod_template }}"
# wait: yes
# vars:
# k8s_pod_name: wait-crash-deploy
# k8s_pod_image: alpine:3.8
# k8s_pod_command:
# - /bin/false
# register: wait_crash_deploy
# ignore_errors: yes
- name: Check that task failed
assert:
that:
- wait_crash_deploy is failed
# - name: Check that task failed
# assert:
# that:
# - wait_crash_deploy is failed
- name: Remove Pod with very short timeout
k8s:
api_version: v1
kind: Pod
name: wait-pod
namespace: "{{ wait_namespace }}"
state: absent
wait: yes
wait_sleep: 2
wait_timeout: 5
ignore_errors: yes
register: short_wait_remove_pod
# - name: Remove Pod with very short timeout
# k8s:
# api_version: v1
# kind: Pod
# name: wait-pod
# namespace: "{{ wait_namespace }}"
# state: absent
# wait: yes
# wait_sleep: 2
# wait_timeout: 5
# ignore_errors: yes
# register: short_wait_remove_pod
- name: Check that task failed
assert:
that:
- short_wait_remove_pod is failed
# - name: Check that task failed
# assert:
# that:
# - short_wait_remove_pod is failed
- name: add a simple crashing pod and wait until container is running
k8s:
@@ -378,6 +378,7 @@
image: busybox
command: ['/dummy/dummy-shell', '-c', 'sleep 2000']
wait: yes
wait_sleep: 2
wait_timeout: 10
wait_property:
property: status.containerStatuses[*].state.running
@@ -405,6 +406,7 @@
image: busybox
command: ['/bin/sh', '-c', 'sleep 10000']
wait: yes
wait_sleep: 2
wait_timeout: 10
wait_property:
property: status.containerStatuses[*].state.running
@@ -439,6 +441,7 @@
configMap:
name: redis-config
wait: yes
wait_sleep: 2
wait_timeout: 10
wait_property:
property: status.containerStatuses[0].ready