Skip to content

Commit

Permalink
[install_yamls] Allow install_yamls env vars patches
Browse files Browse the repository at this point in the history
  • Loading branch information
pablintino authored and openshift-merge-bot[bot] committed Oct 25, 2024
1 parent 6dfc7dd commit 8948c13
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
11 changes: 11 additions & 0 deletions roles/install_yamls/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# install_yamls

An ansible role wrapper around [install_yamls](https://github.com/openstack-k8s-operators/install_yamls) Makefile. It dynamically creates `install_yamls_makes` role, which can be reused within [the CI Framework and other projects](https://github.com/rdo-infra/rdo-jobs/blob/39d0647cbb20abe3aaf2baad134a0e09473e1c54/playbooks/data_plane_adoption/ci_framework_install_yamls.yaml#L5-L24).

It contains a set of playbooks to deploy podified control plane.

## Parameters

* `cifmw_install_yamls_envfile`: (String) Environment file containing all the Makefile overrides. Defaults to `install_yamls`.
* `cifmw_install_yamls_out_dir`: (String) `install_yamls` output directory to store generated output. Defaults to `{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}/artifacts"`.
* `cifmw_install_yamls_vars`: (Dict) A dict containing Makefile overrides.
Expand All @@ -13,9 +15,17 @@ It contains a set of playbooks to deploy podified control plane.
* `cifmw_install_yamls_checkout_openstack_ref`: (String) Enable the checkout from openstack-operator references
when cloning operator's repository using install_yamls make targets. Defaults to `"true"`

## cifmw_install_yamls_vars patching

This role makes possible to define a base `cifmw_install_yamls_vars` and
patch its values afterwards by defining variables named like `^cifmw_install_yamls_vars_patch.*`
that will be combined on top of the original `cifmw_install_yamls_var` after sorting them by name.

## Use case

This module uses [a custom plugin](https://github.com/openstack-k8s-operators/ci-framework/blob/main/plugins/modules/generate_make_tasks.py) created to generate the role with tasks from Makefile.
The created role directory contains multiple task files, similar to

```YAML
---
- name: Debug make_crc_storage_env
Expand All @@ -40,6 +50,7 @@ The created role directory contains multiple task files, similar to
```
The role can be imported and tasks can be executed like this
```YAML
- name: Prepare storage in CRC
vars:
Expand Down
22 changes: 19 additions & 3 deletions roles/install_yamls/molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
vars:
cifmw_install_yamls_vars:
namespace: foobar
openstack_ctlplane: controlplane-yaml-file.yaml
ansible_user_dir: "{{ lookup('env', 'HOME') }}"
cifmw_install_yamls_repo: "{{ ansible_user_dir }}/src/github.com/openstack-k8s-operators/install_yamls"
zuul:
Expand All @@ -41,14 +42,29 @@
short_name: service-telemetry-operator
name: infrawatch/service-telemetry-operator
src_dir: src/github.com/infrawatch/service-telemetry-operator
roles:
- role: "install_yamls"

tasks:
- name: Add install_yamls vars overrides
ansible.builtin.set_fact:
cifmw_install_yamls_vars_patch_01_patch:
namespace: patched
cifmw_install_yamls_vars_patch_02_patch:
namespace: patched2
infra_img: quay.io/openstack-k8s-operators/infra-operator-index:dummy

- name: Call role under test
ansible.builtin.include_role:
name: "install_yamls"

- name: Ensure we get cifmw_install_yamls_environment fact
ansible.builtin.assert:
that:
- cifmw_install_yamls_environment is defined
- cifmw_install_yamls_environment.OPENSTACK_CTLPLANE is defined
- cifmw_install_yamls_environment.OPENSTACK_CTLPLANE == cifmw_install_yamls_vars.openstack_ctlplane
- cifmw_install_yamls_environment.NAMESPACE is defined
- cifmw_install_yamls_environment.NAMESPACE == cifmw_install_yamls_vars_patch_02_patch.namespace
- cifmw_install_yamls_environment.INFRA_IMG is defined
- cifmw_install_yamls_environment.INFRA_IMG == cifmw_install_yamls_vars_patch_02_patch.infra_img

- name: Gather some file data
register: make_files
Expand Down
27 changes: 24 additions & 3 deletions roles/install_yamls/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,39 @@
name: install_yamls
tasks_from: zuul_set_operators_repo.yml

- name: Compute the cifmw_install_yamls_vars final value
tags:
- bootstrap
vars:
_cifmw_install_yamls_vars_patches: >-
{{
hostvars[inventory_hostname] |
dict2items |
selectattr("key", "match",
"^cifmw_install_yamls_vars_patch.*") |
sort(attribute='key') |
map(attribute='value') |
list
}}
ansible.builtin.set_fact:
_install_yamls_override_vars: >-
{{
_install_yamls_override_vars | default({}) |
combine(item, recursive=True)
}}
loop: "{{ [cifmw_install_yamls_vars| default({})] + _cifmw_install_yamls_vars_patches }}"

- name: Set environment override cifmw_install_yamls_environment fact
tags:
- bootstrap
vars:
install_yamls_override_vars: "{{ cifmw_install_yamls_vars| default({}) }}"
install_yamls_operators_repos: "{{ cifmw_install_yamls_operators_repo | default({}) }}"
ansible.builtin.set_fact:
cifmw_install_yamls_environment: >-
{{
install_yamls_override_vars.keys() |
_install_yamls_override_vars.keys() |
map('upper') |
zip(install_yamls_override_vars.values()) |
zip(_install_yamls_override_vars.values()) |
items2dict(key_name=0, value_name=1) |
combine({
'OUT': cifmw_install_yamls_manifests_dir,
Expand Down

0 comments on commit 8948c13

Please sign in to comment.