-
Notifications
You must be signed in to change notification settings - Fork 6
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
MariaDB HA via Galera and tests #23
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
- name: "[MARIADB_APB][TEST] Test MariaDB APB" | ||
hosts: localhost | ||
gather_facts: False | ||
connection: local | ||
roles: | ||
- role: ansible.kubernetes-modules | ||
install_python_requirements: no | ||
- role: ansibleplaybookbundle.asb-modules | ||
|
||
# Currently only includes ha. | ||
# TODO: The other plans are unable to contact the mariadb service. Needs to be investigated. | ||
|
||
tasks: | ||
- include_tasks: test_tasks.yml | ||
vars: | ||
plan: "{{ outer_item }}" | ||
with_items: | ||
- ha | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @djzager I kept having problems with the tests failing for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is fair to me. Adding a todo for the remainder would be a good idea then. |
||
loop_control: | ||
loop_var: outer_item |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
- name: "Include variables per apb plan" | ||
include_vars: | ||
file: "vars/{{ plan }}.yml" | ||
|
||
- name: "[TEST][{{ _apb_plan_id }}] Create new project" | ||
openshift_v1_project: | ||
name: "{{ namespace }}" | ||
state: 'present' | ||
|
||
- name: "[TEST][{{ _apb_plan_id }}]" | ||
include_role: | ||
name: rhscl-mariadb-apb-openshift | ||
vars: | ||
action: "provision" | ||
state: "present" | ||
|
||
- name: "[TEST][{{ _apb_plan_id }}]" | ||
include_role: | ||
name: rhscl-mariadb-apb-openshift | ||
vars: | ||
action: "test" | ||
|
||
- name: "[TEST][{{ _apb_plan_id }}]" | ||
include_role: | ||
name: rhscl-mariadb-apb-openshift | ||
vars: | ||
action: "deprovision" | ||
state: "absent" | ||
|
||
- name: "[TEST][{{ _apb_plan_id }}] Delete test project" | ||
openshift_v1_project: | ||
name: "{{ namespace }}" | ||
state: "absent" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
_apb_plan_id: "dev" | ||
service_name: "rhscl-mariadb" | ||
namespace: "test-{{ _apb_plan_id }}-{{ service_name }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we not able to push most of these variables down into the role vars/defaults? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe this is as practical as I originally thought when making the comment, however I do believe the simpler our Ansible code, the better. |
||
mariadb_database: "userdb" | ||
mariadb_user: "user" | ||
volume_size: "1Gi" | ||
mariadb_version: "10.2" | ||
mariadb_root_password: "password123" | ||
mariadb_password: "password123" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
_apb_plan_id: "ha" | ||
service_name: "rhscl-mariadb" | ||
namespace: "test-{{ _apb_plan_id }}-{{ service_name }}" | ||
mariadb_database: "userdb" | ||
mariadb_user: "user" | ||
volume_size: "1Gi" | ||
mariadb_version: "10.2" | ||
mariadb_root_password: "password123" | ||
mariadb_password: "password123" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
_apb_plan_id: "prod" | ||
service_name: "rhscl-mariadb" | ||
namespace: "test-{{ _apb_plan_id }}-{{ service_name }}" | ||
mariadb_database: "userdb" | ||
mariadb_user: "user" | ||
volume_size: "1Gi" | ||
mariadb_version: "10.2" | ||
mariadb_root_password: "password123" | ||
mariadb_password: "password123" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,35 @@ | ||
--- | ||
|
||
service_name: "{{ lookup('env','SERVICE_NAME') | default('rhscl-mariadb', true) }}" | ||
namespace: "{{ lookup('env','NAMESPACE') | default('rhscl-mariadb-apb', true) }}" | ||
mariadb_database: "{{ lookup('env','MARIADB_DATABASE') | default('', true) }}" | ||
mariadb_user: "{{ lookup('env','MARIADB_USER') | default('admin', true) }}" | ||
volume_size: "{{ lookup('env','VOLUME_SIZE') | default('10Gi', true) }}" | ||
mariadb_version: "{{ lookup('env','MARIADB_VERSION') | default('10.0', true) }}" | ||
image: "registry.access.redhat.com/rhscl/mariadb-{{ mariadb_version | replace('.', '') }}-rhel7" | ||
mariadb_version_nodots: "{{ mariadb_version | replace('.', '') }}" | ||
|
||
|
||
# http://jinja.pocoo.org/docs/2.10/templates/#whitespace-control | ||
# https://stackoverflow.com/a/21699210 | ||
image: >- | ||
{% if _apb_plan_id == "ha" -%} | ||
registry.centos.org/centos/mariadb-{{ mariadb_version_nodots }}-centos7 | ||
{%- else %} | ||
registry.access.redhat.com/rhscl/mariadb-{{ mariadb_version_nodots }}-rhel7 | ||
{%- endif %} | ||
state: present | ||
|
||
# Variables below are for the testing of the mariadb service. | ||
|
||
test_create_table: 'CREATE TABLE IF NOT EXISTS example_timestamp (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,data VARCHAR(100),cur_timestamp TIMESTAMP(6));' | ||
test_insert: 'INSERT INTO example_timestamp (data) VALUES ("The time of creation is:");' | ||
test_select: 'SELECT * FROM example_timestamp;' | ||
test_galera: | ||
- 'SHOW GLOBAL STATUS LIKE "wsrep_local_state_comment";' | ||
- 'SHOW GLOBAL STATUS LIKE "wsrep_connected";' | ||
- 'SHOW GLOBAL STATUS LIKE "wsrep_ready";' | ||
|
||
test_galera_expected_results: | ||
wsrep_connected: "ON" | ||
wsrep_ready: "ON" | ||
wsrep_local_state_comment: "Synced" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
# This module fails if the import ImageStream exists | ||
- name: Image Streams | ||
openshift_v1_image_stream: | ||
name: "{{ item.name }}" | ||
namespace: "{{ namespace }}" | ||
state: "{{ state }}" | ||
spec_tags: "{{ item.tags | default(omit) }}" | ||
ignore_errors: True | ||
with_items: | ||
- name: "{{ service_name }}-{{ mariadb_version_nodots }}-{{ _apb_plan_id }}" | ||
- name: "{{ service_name }}-{{ mariadb_version_nodots }}-galera" | ||
- name: "{{ image.split('/')[-1] }}" | ||
tags: | ||
- from: | ||
kind: DockerImage | ||
name: "{{ image }}" | ||
name: latest | ||
|
||
# This module does not correctly implement `spec_cluster_ip` when setting | ||
# to 'None' still creates a clusterIP. | ||
- name: Template Service | ||
template: | ||
src: service.yaml.j2 | ||
dest: /tmp/service.yaml | ||
register: svc | ||
|
||
- name: Apply Service | ||
command: "oc apply -n {{ namespace }} -f {{ svc.dest | default(svc.path) }}" | ||
|
||
- name: Template BuildConfigs | ||
template: | ||
src: "{{ item }}.j2" | ||
dest: "/tmp/{{ item }}" | ||
register: bc | ||
with_items: | ||
- "bc-ha.yaml" | ||
- "bc-galera.yaml" | ||
|
||
- name: Create BuildConfigs | ||
openshift_v1_build_config: | ||
name: "{{ (lookup('file', item.dest|default(item.path)) | from_yaml).metadata['name'] }}" | ||
namespace: "{{ namespace }}" | ||
state: "{{ state }}" | ||
src: "{{ item.dest | default(item.path) }}" | ||
with_items: "{{ bc.results }}" | ||
|
||
- name: Template StatefulSet | ||
template: | ||
src: statefulset.yaml.j2 | ||
dest: /tmp/statefulset.yaml | ||
register: sfs | ||
|
||
# This module fails if the statefulset exists and state is present | ||
- name: Create StatefulSet | ||
k8s_v1beta1_stateful_set: | ||
name: "{{ service_name }}-{{ mariadb_version_nodots }}-{{ _apb_plan_id }}" | ||
namespace: "{{ namespace }}" | ||
src: "{{ sfs.dest | default(sfs.path) }}" | ||
state: "{{ state }}" | ||
ignore_errors: True | ||
|
||
|
||
- name: Wait for rollout of StatefulSet | ||
k8s_v1beta1_stateful_set: | ||
name: "{{ service_name }}-{{ mariadb_version_nodots }}-{{ _apb_plan_id }}" | ||
namespace: "{{ namespace }}" | ||
register: rollout | ||
until: rollout['stateful_set']['status']['ready_replicas'] == rollout['stateful_set']['status']['replicas'] | ||
delay: 30 | ||
retries: 20 | ||
when: state == 'present' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would like for this to be a parameter instead of a plan.