Skip to content

Commit

Permalink
feat: make key-value DB deployment generic
Browse files Browse the repository at this point in the history
1. Rely on a single tag ‹with_kv_database› for deciding whether it
   should be deployed or not.
2. Introduce a new variable ‹kv_database› that holds the name of the KV
   database that might be deployed.
   - Also allows for easier deduction of the hostname and makes sure
     that there's always at least one deployment of any kind, i.e., it
     is now not possible to require it present, but have incorrect
     combination of flags, e.g., neither ‹with_redis› nor ‹with_redict›
     set.
3. Add it to templates where it's been forgotten.

Signed-off-by: Matej Focko <[email protected]>
  • Loading branch information
mfocko committed Oct 3, 2024
1 parent 2892b42 commit 77eae5a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 50 deletions.
20 changes: 8 additions & 12 deletions playbooks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
tenant: packit # MP+ tenant
with_tokman: true
with_fedmsg: true
with_redis: false
with_redict: true
kv_database: "redict"
with_kv_database: true
with_redis_commander: false
with_flower: false
with_dashboard: true
Expand Down Expand Up @@ -183,20 +183,16 @@
tags:
- postgres

- name: Deploy redis
- name: Deploy key-value database ({{ kv_database }})
vars:
k8s_apply: true
ansible.builtin.include_tasks: tasks/k8s.yml
loop:
- "{{ lookup('template', '{{ project_dir }}/openshift/redis.yml.j2') }}"
when: with_redis
- "{{ lookup('template', '{{ project_dir }}/openshift/{{ kv_database }}.yml.j2') }}"
when: with_kv_database
tags:
- kv_database
- redis

- name: Deploy redict
ansible.builtin.include_tasks: tasks/k8s.yml
loop:
- "{{ lookup('template', '{{ project_dir }}/openshift/redict.yml.j2') }}"
when: with_redict
tags:
- redict

- name: Deploy fluentd image stream and config
Expand Down
4 changes: 2 additions & 2 deletions playbooks/roles/deploy/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ deployment: "{{ lookup('env', 'DEPLOYMENT') }}" # noqa: var-naming[no-role-prefi
tenant: packit # noqa: var-naming[no-role-prefix] # MP+ tenant
with_tokman: true # noqa: var-naming[no-role-prefix]
with_fedmsg: true # noqa: var-naming[no-role-prefix]
with_redis: false # noqa: var-naming[no-role-prefix]
with_redict: true # noqa: var-naming[no-role-prefix]
kv_database: "redict" # noqa: var-naming[no-role-prefix]
with_kv_database: true # noqa: var-naming[no-role-prefix]
with_redis_commander: false # noqa: var-naming[no-role-prefix]
with_flower: false # noqa: var-naming[no-role-prefix]
with_dashboard: true # noqa: var-naming[no-role-prefix]
Expand Down
16 changes: 6 additions & 10 deletions playbooks/roles/deploy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,16 @@
tags:
- postgres

- name: Deploy redis
- name: Deploy key-value database ({{ kv_database }})
vars:
k8s_apply: true
ansible.builtin.include_tasks: tasks/k8s.yml
loop:
- "{{ lookup('template', '{{ project_dir }}/openshift/redis.yml.j2') }}"
when: with_redis
- "{{ lookup('template', '{{ project_dir }}/openshift/{{ kv_database }}.yml.j2') }}"
when: with_kv_database
tags:
- kv_database
- redis

- name: Deploy redict
ansible.builtin.include_tasks: tasks/k8s.yml
loop:
- "{{ lookup('template', '{{ project_dir }}/openshift/redict.yml.j2') }}"
when: with_redict
tags:
- redict

- name: Deploy fluentd image stream and config
Expand Down
4 changes: 2 additions & 2 deletions playbooks/tasks/set-deployment-facts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
packit-dashboard: "{{ with_dashboard }}"
pushgateway: "{{ with_pushgateway }}"
nginx: "{{ with_pushgateway }}"
redis: "{{ with_redis }}"
redict: "{{ with_redict }}"
redis: "{{ with_kv_database and kv_database == 'redis' }}"
redict: "{{ with_kv_database and kv_database == 'redict' }}"
tags:
- always

Expand Down
26 changes: 2 additions & 24 deletions playbooks/tasks/set-facts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,5 @@
- name: Set Redis-like hostname
tags:
- always
block:
# Needed for nice message of the sanity check
- name: Set default for the hostname
ansible.builtin.set_fact:
redis_hostname: None

- name: Set Redict as the hostname
ansible.builtin.set_fact:
redis_hostname: redict
when: with_redict

- name: Set Redis as the hostname (backward compatibility)
ansible.builtin.set_fact:
redis_hostname: redis
when: with_redis

- name: Sanity check for deploying exactly one of Redis or Redict
ansible.builtin.assert:
that: with_redict != with_redis
success_msg: |
[INFO] Deploying {{ redis_hostname }}
fail_msg: |
[FAIL] Check vars (‹with_redict› and ‹with_redis›).
Cannot deploy none or both of Redis and Redict!
ansible.builtin.set_fact:
redis_hostname: "{{ kv_database }}"
3 changes: 3 additions & 0 deletions vars/packit/dev_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ check_up_to_date: false
# edit the queue name in secrets/*/fedora.toml
with_fedmsg: false

# kv_database: redict
# with_kv_database: true

with_redis_commander: false

with_flower: true
Expand Down
3 changes: 3 additions & 0 deletions vars/packit/prod_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ api_key: ""
# edit the queue name in secrets/*/fedora.toml
# with_fedmsg: true

# kv_database: redict
# with_kv_database: true

# with_redis_commander: false

with_flower: true
Expand Down
3 changes: 3 additions & 0 deletions vars/packit/stg_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ api_key: ""
# edit the queue name in secrets/*/fedora.toml
# with_fedmsg: true

# kv_database: redict
# with_kv_database: true

# with_redis_commander: false

with_flower: true
Expand Down

0 comments on commit 77eae5a

Please sign in to comment.