mirror of
https://github.com/ansible/awx-operator.git
synced 2026-03-26 21:33:14 +00:00
Allow {web_,task_,}replicas to be 0 and split out molecule tests (#1468)
Signed-off-by: Rick Elrod <rick@elrod.me>
This commit is contained in:
@@ -12,7 +12,11 @@
|
||||
api_version: v1
|
||||
kind: Namespace
|
||||
name: '{{ namespace }}'
|
||||
tags:
|
||||
- always
|
||||
|
||||
- import_tasks: kustomize.yml
|
||||
vars:
|
||||
state: present
|
||||
tags:
|
||||
- always
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
- import_tasks: kustomize.yml
|
||||
vars:
|
||||
state: absent
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Destroy Namespace
|
||||
k8s:
|
||||
@@ -17,8 +19,12 @@
|
||||
kind: Namespace
|
||||
name: '{{ namespace }}'
|
||||
state: absent
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Unset pull policy
|
||||
command: '{{ kustomize }} edit remove patch --path pull_policy/{{ operator_pull_policy }}.yaml'
|
||||
args:
|
||||
chdir: '{{ config_dir }}/testing'
|
||||
tags:
|
||||
- always
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
chdir: '{{ config_dir }}/testing'
|
||||
register: resources
|
||||
changed_when: false
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Set resources to {{ state }}
|
||||
k8s:
|
||||
@@ -13,3 +15,5 @@
|
||||
state: '{{ state }}'
|
||||
wait: yes
|
||||
loop: '{{ resources.stdout | from_yaml_all | list }}'
|
||||
tags:
|
||||
- always
|
||||
|
||||
@@ -11,18 +11,26 @@
|
||||
You must specify the OPERATOR_IMAGE environment variable in order to run the
|
||||
'default' scenario
|
||||
when: not operator_image
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Set testing image
|
||||
command: '{{ kustomize }} edit set image testing={{ operator_image }}'
|
||||
args:
|
||||
chdir: '{{ config_dir }}/testing'
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Set pull policy
|
||||
command: '{{ kustomize }} edit add patch --path pull_policy/{{ operator_pull_policy }}.yaml'
|
||||
args:
|
||||
chdir: '{{ config_dir }}/testing'
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Set testing namespace
|
||||
command: '{{ kustomize }} edit set namespace {{ namespace }}'
|
||||
args:
|
||||
chdir: '{{ config_dir }}/testing'
|
||||
tags:
|
||||
- always
|
||||
|
||||
35
molecule/default/tasks/_test_case_replicas.yml
Normal file
35
molecule/default/tasks/_test_case_replicas.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
- name: Get web pod details
|
||||
k8s_info:
|
||||
namespace: '{{ namespace }}'
|
||||
kind: Pod
|
||||
label_selectors:
|
||||
- app.kubernetes.io/name = example-awx-web
|
||||
register: awx_web_pod
|
||||
# This can take a while to actually make it to the cluster
|
||||
retries: 30
|
||||
delay: 5
|
||||
until: awx_web_pod.resources | length == expected_web_replicas
|
||||
ignore_errors: true
|
||||
|
||||
- name: Get task pod details
|
||||
k8s_info:
|
||||
namespace: '{{ namespace }}'
|
||||
kind: Pod
|
||||
label_selectors:
|
||||
- app.kubernetes.io/name = example-awx-task
|
||||
register: awx_task_pod
|
||||
# This can take a while to actually make it to the cluster
|
||||
retries: 30
|
||||
delay: 5
|
||||
until: awx_task_pod.resources | length == expected_task_replicas
|
||||
ignore_errors: true
|
||||
|
||||
- name: Ensure that the correct number of web and task pods exist
|
||||
assert:
|
||||
that:
|
||||
- awx_web_pod.resources | length == expected_web_replicas
|
||||
- awx_task_pod.resources | length == expected_task_replicas
|
||||
fail_msg: >-
|
||||
Web pods: Expected {{ expected_web_replicas }}, got {{ awx_web_pod.resources | length }}.
|
||||
Task pods: Expected {{ expected_task_replicas }}, got {{ awx_task_pod.resources | length }}.
|
||||
13
molecule/default/tasks/apply_awx_spec.yml
Normal file
13
molecule/default/tasks/apply_awx_spec.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
- name: Create or update the awx.ansible.com/v1alpha1.AWX
|
||||
k8s:
|
||||
state: present
|
||||
namespace: '{{ namespace }}'
|
||||
definition: "{{ lookup('template', 'awx_cr_molecule.yml.j2') | from_yaml }}"
|
||||
apply: true
|
||||
wait: yes
|
||||
wait_timeout: 900
|
||||
wait_condition:
|
||||
type: Running
|
||||
reason: Successful
|
||||
status: "True"
|
||||
64
molecule/default/tasks/awx_replicas_test.yml
Normal file
64
molecule/default/tasks/awx_replicas_test.yml
Normal file
@@ -0,0 +1,64 @@
|
||||
---
|
||||
- block:
|
||||
- debug:
|
||||
msg: test - web_replicas and task_replicas should override replicas
|
||||
|
||||
- include_tasks: apply_awx_spec.yml
|
||||
vars:
|
||||
additional_fields:
|
||||
replicas: 2
|
||||
web_replicas: 0
|
||||
task_replicas: 0
|
||||
|
||||
- include_tasks: _test_case_replicas.yml
|
||||
vars:
|
||||
expected_web_replicas: 0
|
||||
expected_task_replicas: 0
|
||||
|
||||
####
|
||||
|
||||
- debug:
|
||||
msg: test - replicas should act as a default
|
||||
|
||||
- include_tasks: apply_awx_spec.yml
|
||||
vars:
|
||||
additional_fields:
|
||||
replicas: 2
|
||||
web_replicas: 1
|
||||
|
||||
- include_tasks: _test_case_replicas.yml
|
||||
vars:
|
||||
expected_web_replicas: 1
|
||||
expected_task_replicas: 2
|
||||
|
||||
####
|
||||
|
||||
- debug:
|
||||
msg: test - replicas=0 should kill all pods
|
||||
|
||||
- include_tasks: apply_awx_spec.yml
|
||||
vars:
|
||||
additional_fields:
|
||||
replicas: 0
|
||||
|
||||
- include_tasks: _test_case_replicas.yml
|
||||
vars:
|
||||
expected_web_replicas: 0
|
||||
expected_task_replicas: 0
|
||||
|
||||
####
|
||||
|
||||
- debug:
|
||||
msg: test - replicas=3 should give 3 of each
|
||||
|
||||
- include_tasks: apply_awx_spec.yml
|
||||
vars:
|
||||
additional_fields:
|
||||
replicas: 3
|
||||
|
||||
- include_tasks: _test_case_replicas.yml
|
||||
vars:
|
||||
expected_web_replicas: 3
|
||||
expected_task_replicas: 3
|
||||
tags:
|
||||
- replicas
|
||||
@@ -1,15 +1,5 @@
|
||||
---
|
||||
- name: Create the awx.ansible.com/v1alpha1.AWX
|
||||
k8s:
|
||||
state: present
|
||||
namespace: '{{ namespace }}'
|
||||
definition: "{{ lookup('template', 'awx_cr_molecule.yml.j2') | from_yaml }}"
|
||||
wait: yes
|
||||
wait_timeout: 900
|
||||
wait_condition:
|
||||
type: Running
|
||||
reason: Successful
|
||||
status: "True"
|
||||
- include_tasks: apply_awx_spec.yml
|
||||
|
||||
- name: Obtain generated admin password
|
||||
k8s_info:
|
||||
|
||||
@@ -20,15 +20,15 @@ spec:
|
||||
kubernetes.io/ingress.class: nginx
|
||||
web_resource_requirements:
|
||||
requests:
|
||||
cpu: 50m
|
||||
cpu: 20m
|
||||
memory: 32M
|
||||
task_resource_requirements:
|
||||
requests:
|
||||
cpu: 50m
|
||||
cpu: 20m
|
||||
memory: 32M
|
||||
ee_resource_requirements:
|
||||
requests:
|
||||
cpu: 50m
|
||||
cpu: 20m
|
||||
memory: 16M
|
||||
no_log: false
|
||||
postgres_resource_requirements: {}
|
||||
@@ -37,3 +37,6 @@ spec:
|
||||
additional_labels:
|
||||
- my/team
|
||||
- my/service
|
||||
{% if additional_fields is defined %}
|
||||
{{ additional_fields | to_nice_yaml | indent(2) }}
|
||||
{% endif %}
|
||||
@@ -15,6 +15,8 @@
|
||||
include_tasks: '{{ item }}'
|
||||
with_fileglob:
|
||||
- tasks/*_test.yml
|
||||
tags:
|
||||
- always
|
||||
rescue:
|
||||
- name: Retrieve relevant resources
|
||||
k8s_info:
|
||||
@@ -31,6 +33,8 @@
|
||||
- api_version: v1
|
||||
kind: ConfigMap
|
||||
register: debug_resources
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Retrieve Pod logs
|
||||
k8s_log:
|
||||
@@ -39,15 +43,21 @@
|
||||
container: awx-manager
|
||||
loop: "{{ q('k8s', api_version='v1', kind='Pod', namespace=namespace, label_selector=ctrl_label) }}"
|
||||
register: debug_logs
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Output gathered resources
|
||||
debug:
|
||||
var: debug_resources
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Output gathered logs
|
||||
debug:
|
||||
var: item.log_lines
|
||||
loop: '{{ debug_logs.results }}'
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Re-emit failure
|
||||
vars:
|
||||
@@ -55,3 +65,5 @@
|
||||
result: '{{ ansible_failed_result }}'
|
||||
fail:
|
||||
msg: '{{ failed_task }}'
|
||||
tags:
|
||||
- always
|
||||
|
||||
@@ -17,11 +17,16 @@
|
||||
push: no
|
||||
source: build
|
||||
force_source: yes
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Load operator image into kind cluster
|
||||
command: kind load docker-image --name osdk-test '{{ operator_image }}'
|
||||
register: result
|
||||
changed_when: '"not yet present" in result.stdout'
|
||||
tags:
|
||||
- always
|
||||
|
||||
|
||||
- name: Load awx image into kind cluster
|
||||
command: kind load docker-image --name osdk-test '{{ awx_image }}:{{ awx_version }}'
|
||||
@@ -30,5 +35,7 @@
|
||||
when:
|
||||
- awx_image is defined
|
||||
- awx_image != ''
|
||||
tags:
|
||||
- always
|
||||
|
||||
- import_playbook: ../default/converge.yml
|
||||
|
||||
@@ -9,8 +9,12 @@
|
||||
tasks:
|
||||
- name: Destroy test kind cluster
|
||||
command: kind delete cluster --name osdk-test --kubeconfig {{ kubeconfig }}
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Unset pull policy
|
||||
command: '{{ kustomize }} edit remove patch --path pull_policy/{{ operator_pull_policy }}.yaml'
|
||||
args:
|
||||
chdir: '{{ config_dir }}/testing'
|
||||
tags:
|
||||
- always
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
k8s:
|
||||
definition: |
|
||||
{{ lookup('url', nginx_ingress_definition, split_lines=False) | from_yaml_all }}
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Wait for NGINX ingress to become available
|
||||
k8s_info:
|
||||
@@ -25,5 +27,7 @@
|
||||
type: Ready
|
||||
register: result # For some reason, this task always fails on the first try...
|
||||
until: result is not failed
|
||||
tags:
|
||||
- always
|
||||
|
||||
- import_playbook: ../default/prepare.yml
|
||||
|
||||
Reference in New Issue
Block a user