Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow {web_,task_,}replicas to be 0 and split out molecule tests #1468

Merged
merged 5 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ name: CI

on:
pull_request:
branches: [devel]

push:
branches: [devel]

jobs:
molecule:
runs-on: ubuntu-latest
name: molecule
strategy:
matrix:
ansible_args:
- --skip-tags=replicas
- -t replicas
env:
DOCKER_API_VERSION: "1.41"
steps:
Expand All @@ -38,7 +40,7 @@ jobs:
run: |
sudo rm -f $(which kustomize)
make kustomize
KUSTOMIZE_PATH=$(readlink -f bin/kustomize) molecule test -s kind
KUSTOMIZE_PATH=$(readlink -f bin/kustomize) molecule test -s kind -- ${{ matrix.ansible_args }}
helm:
runs-on: ubuntu-latest
name: helm
Expand Down
4 changes: 4 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
api_version: v1
kind: Namespace
name: '{{ namespace }}'
tags:
- always

- import_tasks: kustomize.yml
vars:
state: present
tags:
- always
6 changes: 6 additions & 0 deletions molecule/default/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@
- import_tasks: kustomize.yml
vars:
state: absent
tags:
- always

- name: Destroy Namespace
k8s:
api_version: v1
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
4 changes: 4 additions & 0 deletions molecule/default/kustomize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
chdir: '{{ config_dir }}/testing'
register: resources
changed_when: false
tags:
- always

- name: Set resources to {{ state }}
k8s:
definition: '{{ item }}'
state: '{{ state }}'
wait: yes
loop: '{{ resources.stdout | from_yaml_all | list }}'
tags:
- always
8 changes: 8 additions & 0 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 35 additions & 0 deletions molecule/default/tasks/_test_case_replicas.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions molecule/default/tasks/apply_awx_spec.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 64 additions & 0 deletions molecule/default/tasks/awx_replicas_test.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 1 addition & 11 deletions molecule/default/tasks/awx_test.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
9 changes: 6 additions & 3 deletions molecule/default/templates/awx_cr_molecule.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand All @@ -37,3 +37,6 @@ spec:
additional_labels:
- my/team
- my/service
{% if additional_fields is defined %}
{{ additional_fields | to_nice_yaml | indent(2) }}
{% endif %}
12 changes: 12 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
include_tasks: '{{ item }}'
with_fileglob:
- tasks/*_test.yml
tags:
- always
rescue:
- name: Retrieve relevant resources
k8s_info:
Expand All @@ -31,6 +33,8 @@
- api_version: v1
kind: ConfigMap
register: debug_resources
tags:
- always

- name: Retrieve Pod logs
k8s_log:
Expand All @@ -39,19 +43,27 @@
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:
failed_task:
result: '{{ ansible_failed_result }}'
fail:
msg: '{{ failed_task }}'
tags:
- always
7 changes: 7 additions & 0 deletions molecule/kind/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,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 }}'
Expand All @@ -42,5 +47,7 @@
when:
- awx_image is defined
- awx_image != ''
tags:
- always

- import_playbook: ../default/converge.yml
4 changes: 4 additions & 0 deletions molecule/kind/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions molecule/kind/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
3 changes: 3 additions & 0 deletions roles/installer/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
command: >-
bash -c "awx-manage showmigrations | grep -v '[X]' | grep '[ ]' | wc -l"
changed_when: false
when: awx_task_pod_name != ''
register: database_check

- name: Migrate the database if the K8s resources were updated. # noqa 305
Expand All @@ -99,11 +100,13 @@
bash -c "awx-manage migrate --noinput"
register: migrate_result
when:
- awx_task_pod_name != ''
- database_check is defined
- (database_check.stdout|trim) != '0'

- name: Initialize Django
include_tasks: initialize_django.yml
when: awx_task_pod_name != ''

- name: Update status variables
include_tasks: update_status.yml
Expand Down
4 changes: 3 additions & 1 deletion roles/installer/tasks/resources_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,7 @@

- name: Verify the resource pod name is populated.
assert:
that: awx_task_pod_name != ''
that:
- awx_task_pod_name != ''
fail_msg: "Could not find the tower pod's name."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to think about moving away from the tower naming scheme in errors since we changed the pod_names? I will leave this as a single comment since it isn't directly applied to the PR, more just for others to see and think about potentially changing it if there are others.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but it doesn't have to prevent this from merging.

when: task_replicas | int > 0 or (task_replicas == '' and replicas > 0)
Loading