Skip to content

Commit

Permalink
Refactor order for test converge tasks (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak authored Jul 5, 2023
1 parent 8adce47 commit 5cd1379
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,56 +124,6 @@
kind='Secret',
kubeconfig=k8s_kubeconfig) }}"

- name: query pagila publications
community.postgresql.postgresql_query:
db: "{{ dataplane_pagila_db }}"
query: "SELECT * FROM pg_publication where pubname = 'dbz_publication'"
login_user: "{{ pagila_owner_user }}"
login_password: "{{ pagila_owner_pass }}"
login_host: "{{ pagila_host }}"
register: pagila_publication_query

- name: create pagila publication
community.postgresql.postgresql_query:
db: "{{ dataplane_pagila_db }}"
query: "CREATE PUBLICATION dbz_publication FOR ALL TABLES"
login_user: "{{ pagila_owner_user }}"
login_password: "{{ pagila_owner_pass }}"
login_host: "{{ pagila_host }}"
when: pagila_publication_query.query_all_results | flatten | length == 0

- name: deploy dataplane helm chart
kubernetes.core.helm:
state: present
name: "{{ dataplane_chart }}"
chart_ref: "{{ dataplane_path }}/charts/dataplane"
release_namespace: "{{ dataplane_namespace }}"
create_namespace: true
force: true
wait: false
timeout: 30m
kubeconfig: "{{ k8s_kubeconfig }}"
binary_path: "{{ k8s_helm_bin }}"
values: "{{ dataplane_chart_values }}"

- name: wait for database cluster startup
ansible.builtin.fail:
msg: "zalando clusters failed to come up on time"
vars:
cluster_failed: "{{ cluster_status | rejectattr('status.PostgresClusterStatus', 'equalto', 'Running') | map(attribute='metadata.name') }}"
cluster_status: "{{ cluster_query | selectattr('status', 'defined') }}"
cluster_query: "{{ query(
'kubernetes.core.k8s',
api_version='acid.zalan.do/v1',
kind='postgresql',
kubeconfig=k8s_kubeconfig) }}"
retries: 15
delay: 30
until: cluster_failed | length == 0
failed_when:
- (cluster_status | length) != (cluster_query | length)
- cluster_failed | length > 0

- name: query pagila connection data
ansible.builtin.set_fact:
pagila_user: "{{ _db_secret_data.data.username | b64decode }}"
Expand All @@ -192,7 +142,7 @@
host: "{{ pagila_host }}"
port: 5432

- name: create database
- name: create pagila database
community.postgresql.postgresql_db:
name: "{{ dataplane_pagila_db }}"
state: present
Expand Down Expand Up @@ -241,3 +191,53 @@
state: absent
path: "{{ datadir.path }}"
changed_when: false

- name: query pagila publications
community.postgresql.postgresql_query:
db: "{{ dataplane_pagila_db }}"
query: "SELECT * FROM pg_publication where pubname = 'dbz_publication'"
login_user: "{{ pagila_owner_user }}"
login_password: "{{ pagila_owner_pass }}"
login_host: "{{ pagila_host }}"
register: pagila_publication_query

- name: create pagila publication
community.postgresql.postgresql_query:
db: "{{ dataplane_pagila_db }}"
query: "CREATE PUBLICATION dbz_publication FOR ALL TABLES"
login_user: "{{ pagila_owner_user }}"
login_password: "{{ pagila_owner_pass }}"
login_host: "{{ pagila_host }}"
when: pagila_publication_query.query_all_results | flatten | length == 0

- name: deploy dataplane helm chart
kubernetes.core.helm:
state: present
name: "{{ dataplane_chart }}"
chart_ref: "{{ dataplane_path }}/charts/dataplane"
release_namespace: "{{ dataplane_namespace }}"
create_namespace: true
force: true
wait: false
timeout: 30m
kubeconfig: "{{ k8s_kubeconfig }}"
binary_path: "{{ k8s_helm_bin }}"
values: "{{ dataplane_chart_values }}"

- name: wait for database cluster startup
ansible.builtin.fail:
msg: "zalando clusters failed to come up on time"
vars:
cluster_failed: "{{ cluster_status | rejectattr('status.PostgresClusterStatus', 'equalto', 'Running') }}"
cluster_status: "{{ cluster_query | selectattr('status', 'defined') }}"
cluster_query: "{{ query(
'kubernetes.core.k8s',
api_version='acid.zalan.do/v1',
kind='postgresql',
kubeconfig=k8s_kubeconfig) }}"
retries: 15
delay: 30
until: cluster_failed | length == 0
failed_when:
- (cluster_status | length) != (cluster_query | length)
- cluster_failed | length > 0

0 comments on commit 5cd1379

Please sign in to comment.