mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-07 13:32:37 +00:00
k8s_scale - add option label_selectors and continue_on_error (#114)
k8s_scale suppport for label selector
This commit is contained in:
50
molecule/default/files/deployment.yaml
Normal file
50
molecule/default/files/deployment.yaml
Normal file
@@ -0,0 +1,50 @@
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: test0
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.14.2
|
||||
ports:
|
||||
- containerPort: 80
|
||||
- name: hello
|
||||
image: busybox
|
||||
command: ['sh', '-c', 'echo "Hello, from test0" && sleep 3600']
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: test1
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.14.2
|
||||
ports:
|
||||
- containerPort: 80
|
||||
- name: hello
|
||||
image: busybox
|
||||
command: ['sh', '-c', 'echo "Hello, from test1" && sleep 3600']
|
||||
@@ -202,6 +202,68 @@
|
||||
- scale_down_no_wait.diff
|
||||
- scale_down_no_wait_pods.resources | length == 1
|
||||
|
||||
# scale multiple resource using label selectors
|
||||
- name: create deployment
|
||||
kubernetes.core.k8s:
|
||||
namespace: "{{ scale_namespace }}"
|
||||
src: files/deployment.yaml
|
||||
|
||||
- name: list deployment
|
||||
kubernetes.core.k8s_info:
|
||||
kind: Deployment
|
||||
namespace: "{{ scale_namespace }}"
|
||||
label_selectors:
|
||||
- app=nginx
|
||||
register: resource
|
||||
- assert:
|
||||
that:
|
||||
- resource.resources | list | length == 2
|
||||
|
||||
- name: scale deployment using resource version
|
||||
kubernetes.core.k8s_scale:
|
||||
replicas: 2
|
||||
kind: Deployment
|
||||
namespace: "{{ scale_namespace }}"
|
||||
resource_version: 0
|
||||
label_selectors:
|
||||
- app=nginx
|
||||
register: scale_out
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not scale_out.changed
|
||||
- scale_out.results | selectattr('warning', 'defined') | list | length == 2
|
||||
|
||||
- name: scale deployment using current replicas (wrong value)
|
||||
kubernetes.core.k8s_scale:
|
||||
replicas: 2
|
||||
current_replicas: 4
|
||||
kind: Deployment
|
||||
namespace: "{{ scale_namespace }}"
|
||||
label_selectors:
|
||||
- app=nginx
|
||||
register: scale_out
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not scale_out.changed
|
||||
- scale_out.results | selectattr('warning', 'defined') | list | length == 2
|
||||
|
||||
- name: scale deployment using current replicas (right value)
|
||||
kubernetes.core.k8s_scale:
|
||||
replicas: 2
|
||||
current_replicas: 3
|
||||
kind: Deployment
|
||||
namespace: "{{ scale_namespace }}"
|
||||
label_selectors:
|
||||
- app=nginx
|
||||
register: scale_out
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- scale_out.changed
|
||||
- scale_out.results | map(attribute='result.status.replicas') | list | unique == [2]
|
||||
|
||||
always:
|
||||
- name: Remove namespace
|
||||
k8s:
|
||||
|
||||
Reference in New Issue
Block a user