mirror of
https://github.com/ansible/awx-operator.git
synced 2026-05-07 13:52:58 +00:00
Initial commit.
This commit is contained in:
27
molecule/default/asserts.yml
Normal file
27
molecule/default/asserts.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
- name: Verify cluster resources
|
||||
hosts: localhost
|
||||
connection: local
|
||||
|
||||
vars:
|
||||
ansible_python_interpreter: '{{ ansible_playbook_python }}'
|
||||
|
||||
tasks:
|
||||
- name: Get tower Pod data
|
||||
k8s_facts:
|
||||
kind: Pod
|
||||
namespace: example-tower
|
||||
label_selectors:
|
||||
- app=tower
|
||||
register: tower_pods
|
||||
|
||||
- name: Verify there are two tower pods
|
||||
assert:
|
||||
that: '{{ (tower_pods.resources | length) == 2 }}'
|
||||
|
||||
- name: Verify tower functionality
|
||||
hosts: k8s
|
||||
|
||||
vars: []
|
||||
|
||||
tasks: []
|
||||
42
molecule/default/molecule.yml
Normal file
42
molecule/default/molecule.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
driver:
|
||||
name: docker
|
||||
lint:
|
||||
name: yamllint
|
||||
enabled: False
|
||||
platforms:
|
||||
- name: kind-default
|
||||
groups:
|
||||
- k8s
|
||||
image: bsycorp/kind:latest-1.14
|
||||
privileged: True
|
||||
override_command: no
|
||||
exposed_ports:
|
||||
- 8443/tcp
|
||||
- 10080/tcp
|
||||
published_ports:
|
||||
- 0.0.0.0:${TEST_CLUSTER_PORT:-9443}:8443/tcp
|
||||
pre_build_image: yes
|
||||
provisioner:
|
||||
name: ansible
|
||||
log: True
|
||||
lint:
|
||||
name: ansible-lint
|
||||
enabled: False
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
operator_namespace: ${TEST_NAMESPACE:-default}
|
||||
env:
|
||||
K8S_AUTH_KUBECONFIG: /tmp/molecule/kind-default/kubeconfig
|
||||
KUBECONFIG: /tmp/molecule/kind-default/kubeconfig
|
||||
ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles
|
||||
KIND_PORT: '${TEST_CLUSTER_PORT:-9443}'
|
||||
scenario:
|
||||
name: default
|
||||
verifier:
|
||||
name: testinfra
|
||||
lint:
|
||||
name: flake8
|
||||
10
molecule/default/playbook.yml
Normal file
10
molecule/default/playbook.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: localhost
|
||||
connection: local
|
||||
vars:
|
||||
ansible_python_interpreter: '{{ ansible_playbook_python }}'
|
||||
roles:
|
||||
- tower
|
||||
|
||||
- import_playbook: '{{ playbook_dir }}/asserts.yml'
|
||||
35
molecule/default/prepare.yml
Normal file
35
molecule/default/prepare.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
- name: Prepare
|
||||
hosts: k8s
|
||||
gather_facts: no
|
||||
vars:
|
||||
kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}"
|
||||
tasks:
|
||||
- name: delete the kubeconfig if present
|
||||
file:
|
||||
path: '{{ kubeconfig }}'
|
||||
state: absent
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Fetch the kubeconfig
|
||||
fetch:
|
||||
dest: '{{ kubeconfig }}'
|
||||
flat: yes
|
||||
src: /root/.kube/config
|
||||
|
||||
- name: Change the kubeconfig port to the proper value
|
||||
replace:
|
||||
regexp: 8443
|
||||
replace: "{{ lookup('env', 'KIND_PORT') }}"
|
||||
path: '{{ kubeconfig }}'
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Wait for the Kubernetes API to become available (this could take a minute)
|
||||
uri:
|
||||
url: "http://localhost:10080/kubernetes-ready"
|
||||
status_code: 200
|
||||
validate_certs: no
|
||||
register: result
|
||||
until: (result.status|default(-1)) == 200
|
||||
retries: 60
|
||||
delay: 5
|
||||
43
molecule/test-cluster/molecule.yml
Normal file
43
molecule/test-cluster/molecule.yml
Normal file
@@ -0,0 +1,43 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
driver:
|
||||
name: delegated
|
||||
options:
|
||||
managed: False
|
||||
ansible_connection_options: {}
|
||||
lint:
|
||||
name: yamllint
|
||||
enabled: False
|
||||
platforms:
|
||||
- name: test-cluster
|
||||
groups:
|
||||
- k8s
|
||||
provisioner:
|
||||
name: ansible
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
namespace: ${TEST_NAMESPACE:-default}
|
||||
lint:
|
||||
name: ansible-lint
|
||||
enabled: False
|
||||
env:
|
||||
ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles
|
||||
scenario:
|
||||
name: test-cluster
|
||||
test_sequence:
|
||||
- lint
|
||||
- destroy
|
||||
- dependency
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- side_effect
|
||||
- verify
|
||||
- destroy
|
||||
verifier:
|
||||
name: testinfra
|
||||
lint:
|
||||
name: flake8
|
||||
33
molecule/test-cluster/playbook.yml
Normal file
33
molecule/test-cluster/playbook.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
|
||||
- name: Converge
|
||||
hosts: localhost
|
||||
connection: local
|
||||
vars:
|
||||
ansible_python_interpreter: '{{ ansible_playbook_python }}'
|
||||
deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy"
|
||||
image_name: tower.ansible.com/tower-operator:testing
|
||||
custom_resource: "{{ lookup('file', '/'.join([deploy_dir, 'crds/tower_v1alpha1_tower_cr.yaml'])) | from_yaml }}"
|
||||
tasks:
|
||||
- name: Create the tower.ansible.com/v1alpha1.Tower
|
||||
k8s:
|
||||
namespace: '{{ namespace }}'
|
||||
definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/tower_v1alpha1_tower_cr.yaml'])) }}"
|
||||
|
||||
- name: Get the newly created Custom Resource
|
||||
debug:
|
||||
msg: "{{ lookup('k8s', group='tower.ansible.com', api_version='v1alpha1', kind='Tower', namespace=namespace, resource_name=custom_resource.metadata.name) }}"
|
||||
|
||||
- name: Wait 60s for reconciliation to run
|
||||
k8s_facts:
|
||||
api_version: 'v1alpha1'
|
||||
kind: 'Tower'
|
||||
namespace: '{{ namespace }}'
|
||||
name: '{{ custom_resource.metadata.name }}'
|
||||
register: reconcile_cr
|
||||
until:
|
||||
- "'Successful' in (reconcile_cr | json_query('resources[].status.conditions[].reason'))"
|
||||
delay: 6
|
||||
retries: 10
|
||||
|
||||
- import_playbook: '{{ playbook_dir }}/../default/asserts.yml'
|
||||
55
molecule/test-local/molecule.yml
Normal file
55
molecule/test-local/molecule.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
driver:
|
||||
name: docker
|
||||
lint:
|
||||
name: yamllint
|
||||
enabled: False
|
||||
platforms:
|
||||
- name: kind-test-local
|
||||
groups:
|
||||
- k8s
|
||||
image: bsycorp/kind:latest-1.15
|
||||
privileged: True
|
||||
override_command: no
|
||||
exposed_ports:
|
||||
- 8443/tcp
|
||||
- 10080/tcp
|
||||
published_ports:
|
||||
- 0.0.0.0:${TEST_CLUSTER_PORT:-10443}:8443/tcp
|
||||
pre_build_image: yes
|
||||
volumes:
|
||||
- ${MOLECULE_PROJECT_DIRECTORY}:/build:Z
|
||||
provisioner:
|
||||
name: ansible
|
||||
log: True
|
||||
lint:
|
||||
name: ansible-lint
|
||||
enabled: False
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
operator_namespace: ${TEST_NAMESPACE:-default}
|
||||
env:
|
||||
K8S_AUTH_KUBECONFIG: /tmp/molecule/kind-test-local/kubeconfig
|
||||
KUBECONFIG: /tmp/molecule/kind-test-local/kubeconfig
|
||||
ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles
|
||||
KIND_PORT: '${TEST_CLUSTER_PORT:-10443}'
|
||||
scenario:
|
||||
name: test-local
|
||||
test_sequence:
|
||||
- lint
|
||||
- destroy
|
||||
- dependency
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- side_effect
|
||||
- verify
|
||||
- destroy
|
||||
verifier:
|
||||
name: testinfra
|
||||
lint:
|
||||
name: flake8
|
||||
126
molecule/test-local/playbook.yml
Normal file
126
molecule/test-local/playbook.yml
Normal file
@@ -0,0 +1,126 @@
|
||||
---
|
||||
- name: Build Operator in Kubernetes docker container
|
||||
hosts: k8s
|
||||
|
||||
vars:
|
||||
image_name: tower.ansible.com/tower-operator:testing
|
||||
|
||||
tasks:
|
||||
# using command so we don't need to install any dependencies
|
||||
- name: Get existing image hash
|
||||
command: docker images -q {{ image_name }}
|
||||
register: prev_hash
|
||||
changed_when: false
|
||||
|
||||
- name: Build Operator Image
|
||||
command: docker build -f /build/build/Dockerfile -t {{ image_name }} /build
|
||||
register: build_cmd
|
||||
changed_when: not prev_hash.stdout or (prev_hash.stdout and prev_hash.stdout not in ''.join(build_cmd.stdout_lines[-2:]))
|
||||
|
||||
- name: Converge
|
||||
hosts: localhost
|
||||
connection: local
|
||||
|
||||
vars:
|
||||
ansible_python_interpreter: '{{ ansible_playbook_python }}'
|
||||
deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy"
|
||||
pull_policy: Never
|
||||
operator_image: tower.ansible.com/tower-operator:testing
|
||||
custom_resource: "{{ lookup('file', '/'.join([deploy_dir, 'crds/tower_v1alpha1_tower_cr.yaml'])) | from_yaml }}"
|
||||
|
||||
tasks:
|
||||
- block:
|
||||
- name: Delete the Operator Deployment
|
||||
k8s:
|
||||
state: absent
|
||||
namespace: '{{ operator_namespace }}'
|
||||
definition: "{{ lookup('template', '/'.join([deploy_dir, 'operator.yaml'])) }}"
|
||||
register: delete_deployment
|
||||
when: hostvars[groups.k8s.0].build_cmd.changed
|
||||
|
||||
- name: Wait 30s for Operator Deployment to terminate
|
||||
k8s_facts:
|
||||
api_version: '{{ definition.apiVersion }}'
|
||||
kind: '{{ definition.kind }}'
|
||||
namespace: '{{ operator_namespace }}'
|
||||
name: '{{ definition.metadata.name }}'
|
||||
vars:
|
||||
definition: "{{ lookup('template', '/'.join([deploy_dir, 'operator.yaml'])) | from_yaml }}"
|
||||
register: deployment
|
||||
until: not deployment.resources
|
||||
delay: 3
|
||||
retries: 10
|
||||
when: delete_deployment.changed
|
||||
|
||||
- name: Create the Operator Deployment
|
||||
k8s:
|
||||
namespace: '{{ operator_namespace }}'
|
||||
definition: "{{ lookup('template', '/'.join([deploy_dir, 'operator.yaml'])) }}"
|
||||
|
||||
- name: Ensure the Tower custom_resource namespace exists
|
||||
k8s:
|
||||
state: present
|
||||
name: '{{ custom_resource.metadata.namespace }}'
|
||||
kind: Namespace
|
||||
api_version: v1
|
||||
|
||||
- name: Create the tower.ansible.com/v1alpha1.Tower
|
||||
k8s:
|
||||
state: present
|
||||
namespace: '{{ custom_resource.metadata.namespace }}'
|
||||
definition: '{{ custom_resource }}'
|
||||
|
||||
- name: Wait 5m for reconciliation to run
|
||||
k8s_facts:
|
||||
api_version: '{{ custom_resource.apiVersion }}'
|
||||
kind: '{{ custom_resource.kind }}'
|
||||
namespace: '{{ custom_resource.metadata.namespace }}'
|
||||
name: '{{ custom_resource.metadata.name }}'
|
||||
register: cr
|
||||
until:
|
||||
- "'Successful' in (cr | json_query('resources[].status.conditions[].reason'))"
|
||||
delay: 6
|
||||
retries: 50
|
||||
rescue:
|
||||
- name: debug cr
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
debug:
|
||||
var: debug_cr
|
||||
vars:
|
||||
debug_cr: '{{ lookup("k8s",
|
||||
kind=custom_resource.kind,
|
||||
api_version=custom_resource.apiVersion,
|
||||
namespace=custom_resource.metadata.namespace,
|
||||
resource_name=custom_resource.metadata.name
|
||||
)}}'
|
||||
|
||||
- name: debug tower deployment
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
debug:
|
||||
var: deploy
|
||||
vars:
|
||||
deploy: '{{ lookup("k8s",
|
||||
kind="Deployment",
|
||||
api_version="apps/v1",
|
||||
namespace=custom_resource.metadata.namespace,
|
||||
label_selector="app=tower"
|
||||
)}}'
|
||||
|
||||
- name: get operator logs
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
command: kubectl logs deployment/{{ definition.metadata.name }} -n {{ operator_namespace }} -c operator
|
||||
environment:
|
||||
KUBECONFIG: '{{ lookup("env", "KUBECONFIG") }}'
|
||||
vars:
|
||||
definition: "{{ lookup('template', '/'.join([deploy_dir, 'operator.yaml'])) | from_yaml }}"
|
||||
register: log
|
||||
|
||||
- debug: var=log.stdout_lines
|
||||
|
||||
- fail:
|
||||
msg: "Failed on action: converge"
|
||||
|
||||
- import_playbook: '{{ playbook_dir }}/../default/asserts.yml'
|
||||
28
molecule/test-local/prepare.yml
Normal file
28
molecule/test-local/prepare.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
- import_playbook: ../default/prepare.yml
|
||||
|
||||
- name: Prepare operator resources
|
||||
hosts: localhost
|
||||
connection: local
|
||||
vars:
|
||||
ansible_python_interpreter: '{{ ansible_playbook_python }}'
|
||||
deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy"
|
||||
tasks:
|
||||
- name: Create Custom Resource Definition
|
||||
k8s:
|
||||
definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/tower_v1alpha1_tower_crd.yaml'])) }}"
|
||||
|
||||
- name: Ensure specified namespace is present
|
||||
k8s:
|
||||
api_version: v1
|
||||
kind: Namespace
|
||||
name: '{{ operator_namespace }}'
|
||||
|
||||
- name: Create RBAC resources
|
||||
k8s:
|
||||
definition: "{{ lookup('template', '/'.join([deploy_dir, item])) }}"
|
||||
namespace: '{{ operator_namespace }}'
|
||||
with_items:
|
||||
- role.yaml
|
||||
- role_binding.yaml
|
||||
- service_account.yaml
|
||||
Reference in New Issue
Block a user