mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-06 13:02:37 +00:00
Fix scale wait and add tests
Move wait logic out of raw and into common and use that logic in scale Fix a few broken wait condition cases highlighted by scaling up and down Move scale-related tests into dedicated test task file Additional service related tests
This commit is contained in:
@@ -559,6 +559,162 @@
|
||||
that:
|
||||
- deploy_after_serviceaccount_removal is failed
|
||||
|
||||
- name: Insert new service port
|
||||
k8s:
|
||||
definition:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: apply-svc
|
||||
namespace: "{{ apply_namespace }}"
|
||||
spec:
|
||||
selector:
|
||||
app: whatever
|
||||
ports:
|
||||
- name: mesh
|
||||
port: 8080
|
||||
targetPort: 8080
|
||||
- name: http
|
||||
port: 8081
|
||||
targetPort: 8081
|
||||
apply: yes
|
||||
register: k8s_service_4
|
||||
|
||||
- name: Check ports are correct
|
||||
assert:
|
||||
that:
|
||||
- k8s_service_4 is changed
|
||||
- k8s_service_4.result.spec.ports | length == 2
|
||||
- k8s_service_4.result.spec.ports[0].port == 8080
|
||||
- k8s_service_4.result.spec.ports[1].port == 8081
|
||||
|
||||
- name: Remove new service port (check mode)
|
||||
k8s:
|
||||
definition:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: apply-svc
|
||||
namespace: "{{ apply_namespace }}"
|
||||
spec:
|
||||
selector:
|
||||
app: whatever
|
||||
ports:
|
||||
- name: http
|
||||
port: 8081
|
||||
targetPort: 8081
|
||||
apply: yes
|
||||
check_mode: yes
|
||||
register: k8s_service_check
|
||||
|
||||
- name: Check ports are correct
|
||||
assert:
|
||||
that:
|
||||
- k8s_service_check is changed
|
||||
- k8s_service_check.result.spec.ports | length == 1
|
||||
- k8s_service_check.result.spec.ports[0].port == 8081
|
||||
|
||||
- name: Remove new service port
|
||||
k8s:
|
||||
definition:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: apply-svc
|
||||
namespace: "{{ apply_namespace }}"
|
||||
spec:
|
||||
selector:
|
||||
app: whatever
|
||||
ports:
|
||||
- name: http
|
||||
port: 8081
|
||||
targetPort: 8081
|
||||
apply: yes
|
||||
register: k8s_service_5
|
||||
|
||||
- name: Check ports are correct
|
||||
assert:
|
||||
that:
|
||||
- k8s_service_5 is changed
|
||||
- k8s_service_5.result.spec.ports | length == 1
|
||||
- k8s_service_5.result.spec.ports[0].port == 8081
|
||||
|
||||
- name: Add a serviceaccount
|
||||
k8s:
|
||||
definition:
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: apply-deploy
|
||||
namespace: "{{ apply_namespace }}"
|
||||
|
||||
- name: Add a deployment
|
||||
k8s:
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: apply-deploy
|
||||
namespace: "{{ apply_namespace }}"
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: "{{ k8s_pod_name }}"
|
||||
template: "{{ k8s_pod_template }}"
|
||||
wait: yes
|
||||
apply: yes
|
||||
vars:
|
||||
k8s_pod_name: apply-deploy
|
||||
k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:v0.10.0-green
|
||||
k8s_pod_service_account: apply-deploy
|
||||
k8s_pod_ports:
|
||||
- containerPort: 8080
|
||||
name: http
|
||||
protocol: TCP
|
||||
|
||||
- name: Remove the serviceaccount
|
||||
k8s:
|
||||
state: absent
|
||||
definition:
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: apply-deploy
|
||||
namespace: "{{ apply_namespace }}"
|
||||
|
||||
- name: Update the earlier deployment
|
||||
k8s:
|
||||
definition:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: apply-deploy
|
||||
namespace: "{{ apply_namespace }}"
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: "{{ k8s_pod_name }}"
|
||||
template: "{{ k8s_pod_template }}"
|
||||
wait: yes
|
||||
apply: yes
|
||||
vars:
|
||||
k8s_pod_name: apply-deploy
|
||||
k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:v0.10.0-purple
|
||||
k8s_pod_service_account: apply-deploy
|
||||
k8s_pod_ports:
|
||||
- containerPort: 8080
|
||||
name: http
|
||||
protocol: TCP
|
||||
register: deploy_after_serviceaccount_removal
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Ensure that updating deployment after service account removal failed
|
||||
assert:
|
||||
that:
|
||||
- deploy_after_serviceaccount_removal is failed
|
||||
|
||||
always:
|
||||
- name: Remove namespace
|
||||
k8s:
|
||||
|
||||
@@ -55,12 +55,6 @@
|
||||
wait: yes
|
||||
register: scale_down
|
||||
|
||||
# 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 pods to at least get to Terminating state
|
||||
- name: Avoid race condition
|
||||
pause:
|
||||
seconds: 2
|
||||
|
||||
- name: Get pods in scale-deploy
|
||||
k8s_info:
|
||||
kind: Pod
|
||||
@@ -70,6 +64,9 @@
|
||||
field_selectors:
|
||||
- status.phase=Running
|
||||
register: scale_down_deploy_pods
|
||||
until: "{{ scale_down_deploy_pods.resources | length == 0 }}"
|
||||
retries: 6
|
||||
delay: 5
|
||||
|
||||
- name: Ensure that scale down took effect
|
||||
assert:
|
||||
@@ -77,7 +74,6 @@
|
||||
- scale_down is changed
|
||||
- '"duration" in scale_down'
|
||||
- scale_down.diff
|
||||
- scale_down_deploy_pods.resources | length == 0
|
||||
|
||||
- name: Reapply the earlier deployment
|
||||
k8s:
|
||||
|
||||
@@ -119,6 +119,8 @@
|
||||
namespace: "{{ wait_namespace }}"
|
||||
label_selectors:
|
||||
- app=wait-ds
|
||||
field_selectors:
|
||||
- status.phase=Running
|
||||
register: updated_ds_pods
|
||||
|
||||
- name: Check that daemonset wait worked
|
||||
@@ -242,13 +244,17 @@
|
||||
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
|
||||
- updated_deploy_pods.resources[0].spec.containers[0].image.endswith(":2")
|
||||
|
||||
- name: Pause a deployment
|
||||
k8s:
|
||||
|
||||
Reference in New Issue
Block a user