2018-11-13 13:50:15 +01:00
|
|
|
- name: ensure that there are actually some nodes
|
2019-05-27 18:17:42 +02:00
|
|
|
k8s_info:
|
2018-11-13 13:50:15 +01:00
|
|
|
kind: Node
|
|
|
|
register: nodes
|
|
|
|
|
|
|
|
- block:
|
|
|
|
- set_fact:
|
|
|
|
wait_namespace: wait
|
2019-05-30 01:26:43 +02:00
|
|
|
|
2018-11-13 13:50:15 +01:00
|
|
|
- name: ensure namespace exists
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Namespace
|
|
|
|
metadata:
|
|
|
|
name: "{{ wait_namespace }}"
|
|
|
|
|
|
|
|
- name: add a simple pod
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Pod
|
|
|
|
metadata:
|
2019-05-30 01:26:43 +02:00
|
|
|
name: "{{ k8s_pod_name }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
namespace: "{{ wait_namespace }}"
|
2019-05-30 01:26:43 +02:00
|
|
|
spec: "{{ k8s_pod_spec }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
wait: yes
|
|
|
|
vars:
|
2019-05-30 01:26:43 +02:00
|
|
|
k8s_pod_name: wait-pod
|
|
|
|
k8s_pod_image: alpine:3.8
|
|
|
|
k8s_pod_command:
|
2018-11-13 13:50:15 +01:00
|
|
|
- sleep
|
|
|
|
- "10000"
|
|
|
|
register: wait_pod
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- name: assert that pod creation succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- wait_pod is successful
|
|
|
|
|
|
|
|
- name: add a daemonset
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: extensions/v1beta1
|
|
|
|
kind: DaemonSet
|
|
|
|
metadata:
|
|
|
|
name: wait-daemonset
|
|
|
|
namespace: "{{ wait_namespace }}"
|
|
|
|
spec:
|
|
|
|
selector:
|
|
|
|
matchLabels:
|
2019-05-30 01:26:43 +02:00
|
|
|
app: "{{ k8s_pod_name }}"
|
|
|
|
template: "{{ k8s_pod_template }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
wait: yes
|
2019-08-07 13:27:54 +02:00
|
|
|
wait_sleep: 3
|
2018-11-13 13:50:15 +01:00
|
|
|
wait_timeout: 180
|
|
|
|
vars:
|
2019-05-30 01:26:43 +02:00
|
|
|
k8s_pod_name: wait-ds
|
|
|
|
k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:1
|
2018-11-13 13:50:15 +01:00
|
|
|
register: ds
|
|
|
|
|
|
|
|
- name: check that daemonset wait worked
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- ds.result.status.currentNumberScheduled == ds.result.status.desiredNumberScheduled
|
|
|
|
|
2019-01-25 11:08:46 +01:00
|
|
|
- name: update a daemonset in check_mode
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: extensions/v1beta1
|
|
|
|
kind: DaemonSet
|
|
|
|
metadata:
|
|
|
|
name: wait-daemonset
|
|
|
|
namespace: "{{ wait_namespace }}"
|
|
|
|
spec:
|
|
|
|
selector:
|
|
|
|
matchLabels:
|
2019-05-30 01:26:43 +02:00
|
|
|
app: "{{ k8s_pod_name }}"
|
2019-01-25 11:08:46 +01:00
|
|
|
updateStrategy:
|
|
|
|
type: RollingUpdate
|
2019-05-30 01:26:43 +02:00
|
|
|
template: "{{ k8s_pod_template }}"
|
2019-01-25 11:08:46 +01:00
|
|
|
wait: yes
|
2019-08-07 13:27:54 +02:00
|
|
|
wait_sleep: 3
|
2019-01-25 11:08:46 +01:00
|
|
|
wait_timeout: 180
|
|
|
|
vars:
|
2019-05-30 01:26:43 +02:00
|
|
|
k8s_pod_name: wait-ds
|
|
|
|
k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:2
|
2019-01-25 11:08:46 +01:00
|
|
|
register: update_ds_check_mode
|
|
|
|
|
|
|
|
- name: check that check_mode returned changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- update_ds_check_mode is changed
|
|
|
|
|
2018-11-13 13:50:15 +01:00
|
|
|
- name: update a daemonset
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: extensions/v1beta1
|
|
|
|
kind: DaemonSet
|
|
|
|
metadata:
|
|
|
|
name: wait-daemonset
|
|
|
|
namespace: "{{ wait_namespace }}"
|
|
|
|
spec:
|
|
|
|
selector:
|
|
|
|
matchLabels:
|
2019-05-30 01:26:43 +02:00
|
|
|
app: "{{ k8s_pod_name }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
updateStrategy:
|
|
|
|
type: RollingUpdate
|
2019-05-30 01:26:43 +02:00
|
|
|
template: "{{ k8s_pod_template }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
wait: yes
|
2019-08-07 13:27:54 +02:00
|
|
|
wait_sleep: 3
|
2018-11-13 13:50:15 +01:00
|
|
|
wait_timeout: 180
|
|
|
|
vars:
|
2019-05-30 01:26:43 +02:00
|
|
|
k8s_pod_name: wait-ds
|
|
|
|
k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:3
|
2018-11-13 13:50:15 +01:00
|
|
|
register: ds
|
|
|
|
|
|
|
|
- name: get updated pods
|
2019-05-27 18:17:42 +02:00
|
|
|
k8s_info:
|
2018-11-13 13:50:15 +01:00
|
|
|
api_version: v1
|
|
|
|
kind: Pod
|
|
|
|
namespace: "{{ wait_namespace }}"
|
|
|
|
label_selectors:
|
|
|
|
- app=wait-ds
|
|
|
|
register: updated_ds_pods
|
|
|
|
|
|
|
|
- name: check that daemonset wait worked
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- ds.result.status.currentNumberScheduled == ds.result.status.desiredNumberScheduled
|
2019-05-30 01:26:43 +02:00
|
|
|
- updated_ds_pods.resources[0].spec.containers[0].image.endswith(":3")
|
2018-11-13 13:50:15 +01:00
|
|
|
|
|
|
|
- name: add a crashing pod
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Pod
|
|
|
|
metadata:
|
2019-05-30 01:26:43 +02:00
|
|
|
name: "{{ k8s_pod_name }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
namespace: "{{ wait_namespace }}"
|
2019-05-30 01:26:43 +02:00
|
|
|
spec: "{{ k8s_pod_spec }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
wait: yes
|
2019-08-07 13:27:54 +02:00
|
|
|
wait_sleep: 1
|
2018-11-13 13:50:15 +01:00
|
|
|
wait_timeout: 30
|
|
|
|
vars:
|
2019-05-30 01:26:43 +02:00
|
|
|
k8s_pod_name: wait-crash-pod
|
|
|
|
k8s_pod_image: alpine:3.8
|
|
|
|
k8s_pod_command:
|
2018-11-13 13:50:15 +01:00
|
|
|
- /bin/false
|
|
|
|
register: crash_pod
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- name: check that task failed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- crash_pod is failed
|
|
|
|
|
|
|
|
- name: use a non-existent image
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Pod
|
|
|
|
metadata:
|
2019-05-30 01:26:43 +02:00
|
|
|
name: "{{ k8s_pod_name }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
namespace: "{{ wait_namespace }}"
|
2019-05-30 01:26:43 +02:00
|
|
|
spec: "{{ k8s_pod_spec }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
wait: yes
|
2019-08-07 13:27:54 +02:00
|
|
|
wait_sleep: 1
|
2018-11-13 13:50:15 +01:00
|
|
|
wait_timeout: 30
|
|
|
|
vars:
|
2019-05-30 01:26:43 +02:00
|
|
|
k8s_pod_name: wait-no-image-pod
|
|
|
|
k8s_pod_image: i_made_this_up:and_this_too
|
2018-11-13 13:50:15 +01:00
|
|
|
register: no_image_pod
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- name: check that task failed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- no_image_pod is failed
|
|
|
|
|
|
|
|
- name: add a deployment
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: extensions/v1beta1
|
|
|
|
kind: Deployment
|
|
|
|
metadata:
|
|
|
|
name: wait-deploy
|
|
|
|
namespace: "{{ wait_namespace }}"
|
|
|
|
spec:
|
|
|
|
replicas: 3
|
|
|
|
selector:
|
|
|
|
matchLabels:
|
2019-05-30 01:26:43 +02:00
|
|
|
app: "{{ k8s_pod_name }}"
|
|
|
|
template: "{{ k8s_pod_template }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
wait: yes
|
|
|
|
vars:
|
2019-05-30 01:26:43 +02:00
|
|
|
k8s_pod_name: wait-deploy
|
|
|
|
k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:1
|
|
|
|
k8s_pod_ports:
|
2018-11-13 13:50:15 +01:00
|
|
|
- containerPort: 8080
|
|
|
|
name: http
|
|
|
|
protocol: TCP
|
|
|
|
|
|
|
|
register: deploy
|
|
|
|
|
|
|
|
- name: check that deployment wait worked
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- deploy.result.status.availableReplicas == deploy.result.status.replicas
|
|
|
|
|
|
|
|
- name: update a deployment
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: extensions/v1beta1
|
|
|
|
kind: Deployment
|
|
|
|
metadata:
|
|
|
|
name: wait-deploy
|
|
|
|
namespace: "{{ wait_namespace }}"
|
|
|
|
spec:
|
|
|
|
replicas: 3
|
|
|
|
selector:
|
|
|
|
matchLabels:
|
2019-05-30 01:26:43 +02:00
|
|
|
app: "{{ k8s_pod_name }}"
|
|
|
|
template: "{{ k8s_pod_template }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
wait: yes
|
|
|
|
vars:
|
2019-05-30 01:26:43 +02:00
|
|
|
k8s_pod_name: wait-deploy
|
|
|
|
k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:2
|
|
|
|
k8s_pod_ports:
|
2018-11-13 13:50:15 +01:00
|
|
|
- containerPort: 8080
|
|
|
|
name: http
|
|
|
|
protocol: TCP
|
|
|
|
register: update_deploy
|
|
|
|
|
|
|
|
- name: get updated pods
|
2019-05-27 18:17:42 +02:00
|
|
|
k8s_info:
|
2018-11-13 13:50:15 +01:00
|
|
|
api_version: v1
|
|
|
|
kind: Pod
|
|
|
|
namespace: "{{ wait_namespace }}"
|
|
|
|
label_selectors:
|
|
|
|
- app=wait-deploy
|
|
|
|
register: updated_deploy_pods
|
|
|
|
|
|
|
|
- name: check that deployment wait worked
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- deploy.result.status.availableReplicas == deploy.result.status.replicas
|
|
|
|
- updated_deploy_pods.resources[0].spec.containers[0].image.endswith(":2")
|
|
|
|
|
2019-03-06 13:41:17 +01:00
|
|
|
- name: pause a deployment
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: extensions/v1beta1
|
|
|
|
kind: Deployment
|
|
|
|
metadata:
|
|
|
|
name: wait-deploy
|
|
|
|
namespace: "{{ wait_namespace }}"
|
|
|
|
spec:
|
|
|
|
paused: True
|
2019-07-08 22:47:41 +02:00
|
|
|
apply: no
|
2019-03-06 13:41:17 +01:00
|
|
|
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:
|
2019-05-22 08:08:22 +02:00
|
|
|
condition: '{{ pause_deploy.result.status.conditions | json_query("[?type==`Progressing`]") | first }}'
|
2019-03-06 13:41:17 +01:00
|
|
|
|
2018-11-13 13:50:15 +01:00
|
|
|
- name: add a service based on the deployment
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Service
|
|
|
|
metadata:
|
|
|
|
name: wait-svc
|
|
|
|
namespace: "{{ wait_namespace }}"
|
|
|
|
spec:
|
|
|
|
selector:
|
2019-05-30 01:26:43 +02:00
|
|
|
app: "{{ k8s_pod_name }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
ports:
|
|
|
|
- port: 8080
|
|
|
|
targetPort: 8080
|
|
|
|
protocol: TCP
|
|
|
|
wait: yes
|
|
|
|
vars:
|
2019-05-30 01:26:43 +02:00
|
|
|
k8s_pod_name: wait-deploy
|
2018-11-13 13:50:15 +01:00
|
|
|
register: service
|
|
|
|
|
|
|
|
- name: assert that waiting for service works
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- service is successful
|
|
|
|
|
|
|
|
- name: add a crashing deployment
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
apiVersion: extensions/v1beta1
|
|
|
|
kind: Deployment
|
|
|
|
metadata:
|
|
|
|
name: wait-crash-deploy
|
|
|
|
namespace: "{{ wait_namespace }}"
|
|
|
|
spec:
|
|
|
|
replicas: 3
|
|
|
|
selector:
|
|
|
|
matchLabels:
|
2019-05-30 01:26:43 +02:00
|
|
|
app: "{{ k8s_pod_name }}"
|
|
|
|
template: "{{ k8s_pod_template }}"
|
2018-11-13 13:50:15 +01:00
|
|
|
wait: yes
|
|
|
|
vars:
|
2019-05-30 01:26:43 +02:00
|
|
|
k8s_pod_name: wait-crash-deploy
|
|
|
|
k8s_pod_image: alpine:3.8
|
|
|
|
k8s_pod_command:
|
2018-11-13 13:50:15 +01:00
|
|
|
- /bin/false
|
|
|
|
register: wait_crash_deploy
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- 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
|
2019-08-07 13:27:54 +02:00
|
|
|
wait_sleep: 2
|
2018-11-13 13:50:15 +01:00
|
|
|
wait_timeout: 5
|
|
|
|
ignore_errors: yes
|
|
|
|
register: short_wait_remove_pod
|
|
|
|
|
|
|
|
- name: check that task failed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- short_wait_remove_pod is failed
|
|
|
|
|
|
|
|
always:
|
|
|
|
- name: remove namespace
|
|
|
|
k8s:
|
|
|
|
kind: Namespace
|
|
|
|
name: "{{ wait_namespace }}"
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
when: (nodes.resources | length) > 0
|