-
Notifications
You must be signed in to change notification settings - Fork 9
Introduce the ability to provision SSCSI roles on hubs and spokes when needed #119
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
base: main
Are you sure you want to change the base?
Changes from all commits
905212c
6f41140
c71b4c4
d2715e8
a742014
1b027fc
23a4754
187c184
b7265d0
ef76979
db2bafa
cb1a535
582cc3d
cd37e5e
996bd20
8acafe7
1257c2b
cd6ff40
7dcf1e7
aa8221a
8af5caf
62c1756
dab5ce6
4e4e035
099f5e1
0b2dac3
c75a8f4
0449675
74657c3
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 |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| { | ||
| "default": true, | ||
| "MD003": false, | ||
| "MD013": false, | ||
| "MD033": false | ||
| } | ||
| "default": true, | ||
| "MD003": false, | ||
| "MD013": { | ||
| "line_length": 400, | ||
| "code_blocks": false, | ||
| "tables": false | ||
| }, | ||
| "MD033": false, | ||
| "MD060": { | ||
| "style": "compact" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- | ||
| # Discover values-<clustergroup>.yaml|yml under pattern_dir. | ||
| # Resolves pattern_dir like pattern_settings (extra var pattern_dir, env PATTERN_DIR, cwd). | ||
| - name: List pattern clustergroup value stems | ||
| hosts: localhost | ||
| connection: local | ||
| gather_facts: false | ||
| become: false | ||
| roles: | ||
| - pattern_settings | ||
| - role: clustergroup_discovery | ||
| tasks: | ||
| - name: Report clustergroup discovery | ||
| ansible.builtin.debug: | ||
| msg: | ||
| pattern_dir: "{{ pattern_dir }}" | ||
| main_clustergroup: "{{ main_clustergroup }}" | ||
| managed_clustergroup_names: "{{ managed_clustergroup_names }}" | ||
| clustergroup_names: "{{ clustergroup_names }}" | ||
| clustergroup_load_order: "{{ clustergroup_load_order }}" | ||
| clustergroup_file_entries: "{{ clustergroup_file_entries }}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| # Parse every top-level values-<clustergroup>.yaml|yml into clustergroup_documents (stem -> root). | ||
| # Use for migration tooling or inspection; SS CSI merge uses the same discovery role internally. | ||
| - name: Parse pattern clustergroup values files | ||
| hosts: localhost | ||
| connection: local | ||
| gather_facts: false | ||
| become: false | ||
| roles: | ||
| - pattern_settings | ||
| - role: clustergroup_discovery | ||
| vars: | ||
| clustergroup_discovery_parse_documents: true | ||
| tasks: | ||
| - name: Summarize parsed clustergroup documents | ||
| ansible.builtin.debug: | ||
| msg: | ||
| pattern_dir: "{{ pattern_dir }}" | ||
| main_clustergroup: "{{ main_clustergroup }}" | ||
| managed_clustergroup_names: "{{ managed_clustergroup_names }}" | ||
| stems_parsed: "{{ clustergroup_documents | default({}) | dict2items | map(attribute='key') | sort | list }}" | ||
| document_count: "{{ clustergroup_documents | default({}) | length }}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # clustergroup_discovery | ||
|
|
||
| Ansible role that lists **which clustergroup value stems are in use** for a Validated Patterns checkout, without scanning every `values-*.yaml` on disk. | ||
|
|
||
| ## Behavior | ||
|
|
||
| 1. Resolve **`pattern_dir`** the same way as `pattern_settings` (extra var, `PATTERN_DIR`, then `PWD` / `pwd`). | ||
| 2. Read **`main.clusterGroupName`** from `values-global.yaml` under `pattern_dir` (or use `main_clustergroup` / `main_clustergroupname` if the play already set them). | ||
| 3. Load **`values-<main>.yaml`** or **`values-<main>.yml`** and read **`clusterGroup.managedClusterGroups`**. For each entry, the managed name is **`value.name`** if set, otherwise the **YAML key** (same rule as SS CSI managed-cluster-group defaults). | ||
| 4. Expose facts: | ||
| - **`managed_clustergroup_names`** — sorted unique managed names | ||
| - **`clustergroup_load_order`** — `[main, …managed]` (main first; used when merging so later stems override duplicate `applications` keys) | ||
| - **`clustergroup_names`** — sorted list of all stems (main + managed) | ||
| - **`clustergroup_file_entries`** — `{name, path}` only for stems where a local `values-<stem>.yaml|yml` exists | ||
|
|
||
| Optional: set **`clustergroup_discovery_parse_documents: true`** to fill **`clustergroup_documents`** (`<stem>` → parsed YAML root) for each file in `clustergroup_file_entries`. | ||
|
|
||
| ## Playbooks | ||
|
|
||
| - `playbooks/list_clustergroups.yml` — runs `pattern_settings` + this role and prints the facts above. | ||
| - `playbooks/parse_clustergroup_values.yml` — same with parsing enabled. | ||
|
|
||
| Requires `ANSIBLE_ROLES_PATH` (or collection layout) so `pattern_settings` and this role resolve. | ||
|
|
||
| ## Relation to SS CSI | ||
|
|
||
| `vault_utils` includes this role when **`vault_ss_csi_aggregate_clustergroup_sources`** is true (default): SS CSI then loads and merges **one document per stem** in `clustergroup_load_order`. See `roles/vault_utils/README.md` (SS CSI section) for parsing, extraction, and projection. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| --- | ||
| # When true, slurp and parse each resolved clustergroup file into clustergroup_documents (stem -> root mapping) | ||
| clustergroup_discovery_parse_documents: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| galaxy_info: | ||
| author: rhvp | ||
| description: >- | ||
| Resolve main clustergroup from values-global, read managedClusterGroups from the main | ||
| values file, then optionally parse existing values-<stem> files for those stems. | ||
| license: Apache-2.0 | ||
| min_ansible_version: "2.14" | ||
| galaxy_tags: | ||
| - openshift | ||
| - gitops | ||
| dependencies: [] |
|
Contributor
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 suspect you need to do this because you need to set up the vault for stuff that will be consumed by spokes as well (apps/etc), correct? If that is the case we will need to look at the jwt stuff as well because they do need something similar as well iirc
Collaborator
Author
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. Yes, I believe that's right. I was also thinking of adding a separate AAP token injection as well. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| --- | ||
| # Discover clustergroups in use: main from values-global, managed from main file's clusterGroup.managedClusterGroups. | ||
| # Sets: clustergroup_names (sorted stems), managed_clustergroup_names (sorted, excludes main), | ||
| # clustergroup_load_order (main first, then managed sorted — SS CSI merge precedence), | ||
| # clustergroup_file_entries ({name, path} only when values-<stem>.yaml|yml exists), | ||
| # clustergroup_documents (optional, stem -> parsed YAML root). | ||
|
|
||
| - name: Resolve pattern_dir for clustergroup discovery | ||
| ansible.builtin.include_tasks: ../pattern_settings/tasks/resolve_overrides.yml | ||
| when: (pattern_dir | default('', true) | string | trim | length) == 0 | ||
|
|
||
| - name: Fail when pattern_dir is empty after resolve | ||
| ansible.builtin.fail: | ||
| msg: >- | ||
| pattern_dir is required (extra var pattern_dir, env PATTERN_DIR, or cwd with values-global.yaml). | ||
| when: (pattern_dir | default('', true) | string | trim | length) == 0 | ||
|
|
||
| - name: Resolve main clustergroup stem from facts or values-global.yaml | ||
| ansible.builtin.set_fact: | ||
| _clustergroup_discovery_main_stem: >- | ||
| {{ | ||
| ( | ||
| (main_clustergroupname | default(main_clustergroup | default('', true), true) | string | trim | length) > 0 | ||
| ) | ||
| | ternary( | ||
| main_clustergroupname | default(main_clustergroup, true) | string | trim, | ||
| ( | ||
| lookup('file', (pattern_dir | string | trim) ~ '/values-global.yaml') | ||
| | from_yaml | ||
| ).main.clusterGroupName | string | trim | ||
| ) | ||
| }} | ||
|
|
||
| - name: Fail when main clusterGroupName cannot be resolved | ||
| ansible.builtin.fail: | ||
| msg: >- | ||
| Could not resolve main clustergroup (values-global.yaml missing .main.clusterGroupName or empty). | ||
| when: (_clustergroup_discovery_main_stem | string | trim | length) == 0 | ||
|
|
||
| - name: Stat main clustergroup values file (yaml) | ||
| ansible.builtin.stat: | ||
| path: "{{ pattern_dir | string | trim }}/values-{{ _clustergroup_discovery_main_stem }}.yaml" | ||
| register: _clustergroup_discovery_main_stat_yaml | ||
|
|
||
| - name: Stat main clustergroup values file (yml) | ||
| ansible.builtin.stat: | ||
| path: "{{ pattern_dir | string | trim }}/values-{{ _clustergroup_discovery_main_stem }}.yml" | ||
| register: _clustergroup_discovery_main_stat_yml | ||
| when: not (_clustergroup_discovery_main_stat_yaml.stat.exists | default(false)) | ||
|
|
||
| - name: Set path to main clustergroup values file when present | ||
| ansible.builtin.set_fact: | ||
| _clustergroup_main_values_path: "{{ pattern_dir | string | trim }}/values-{{ _clustergroup_discovery_main_stem }}.yaml" | ||
| when: _clustergroup_discovery_main_stat_yaml.stat.exists | default(false) | ||
|
|
||
| - name: Set path to main clustergroup values file when only yml exists | ||
| ansible.builtin.set_fact: | ||
| _clustergroup_main_values_path: "{{ pattern_dir | string | trim }}/values-{{ _clustergroup_discovery_main_stem }}.yml" | ||
| when: | ||
| - _clustergroup_main_values_path is not defined | ||
| - _clustergroup_discovery_main_stat_yml is defined | ||
| - _clustergroup_discovery_main_stat_yml.stat.exists | default(false) | ||
|
|
||
| - name: Load parsed root from main clustergroup values file | ||
| ansible.builtin.set_fact: | ||
| _clustergroup_main_root: "{{ lookup('file', _clustergroup_main_values_path) | from_yaml }}" | ||
| when: _clustergroup_main_values_path is defined | ||
|
|
||
| - name: Default empty main clustergroup root when file is absent | ||
| ansible.builtin.set_fact: | ||
| _clustergroup_main_root: {} | ||
| when: _clustergroup_main_values_path is not defined | ||
|
|
||
| - name: Collect managed clustergroup names from main file managedClusterGroups | ||
| ansible.builtin.set_fact: | ||
| managed_clustergroup_names: "{{ managed_clustergroup_names | default([]) + [_cgd_mcg_name] }}" | ||
| vars: | ||
| _cgd_mcg_name: "{{ (item.value.name | default(item.key, true)) | string | trim }}" | ||
| loop: "{{ (_clustergroup_main_root.clusterGroup | default({})).managedClusterGroups | default({}) | dict2items }}" | ||
| loop_control: | ||
| label: "{{ _cgd_mcg_name }}" | ||
| when: | ||
| - _clustergroup_main_root is mapping | ||
| - (_clustergroup_main_root.clusterGroup | default({})).managedClusterGroups is defined | ||
| - ((_clustergroup_main_root.clusterGroup | default({})).managedClusterGroups | default({})) is mapping | ||
|
|
||
| - name: Finalize managed clustergroup names list | ||
| ansible.builtin.set_fact: | ||
| managed_clustergroup_names: "{{ managed_clustergroup_names | default([]) | unique | sort }}" | ||
|
|
||
| - name: Set clustergroup load order (main first so managed values files override for SS CSI merge) | ||
| ansible.builtin.set_fact: | ||
| clustergroup_load_order: >- | ||
| {{ | ||
| ( | ||
| [_clustergroup_discovery_main_stem] | ||
| + (managed_clustergroup_names | reject('equalto', _clustergroup_discovery_main_stem) | list) | ||
| ) | unique | list | ||
| }} | ||
|
|
||
| - name: Set sorted clustergroup names (all stems in use) | ||
| ansible.builtin.set_fact: | ||
| clustergroup_names: "{{ clustergroup_load_order | sort }}" | ||
|
|
||
| - name: Build clustergroup_file_entries for stems that have a local values file | ||
| ansible.builtin.include_tasks: resolve_clustergroup_file_path.yml | ||
| loop: "{{ clustergroup_load_order }}" | ||
| loop_control: | ||
| loop_var: clustergroup_discovery_stem | ||
|
|
||
| - name: Default empty clustergroup file entries | ||
| ansible.builtin.set_fact: | ||
| clustergroup_file_entries: [] | ||
| when: clustergroup_file_entries is not defined | ||
|
|
||
| - name: Parse each resolved clustergroup values file when requested | ||
| ansible.builtin.include_tasks: parse_documents.yml | ||
| when: clustergroup_discovery_parse_documents | default(false) | bool |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| - name: Parse clustergroup values YAML into clustergroup_documents | ||
| ansible.builtin.set_fact: | ||
| clustergroup_documents: "{{ clustergroup_documents | default({}) | combine({item.name: (lookup('file', item.path) | from_yaml)}) }}" | ||
| loop: "{{ clustergroup_file_entries }}" | ||
| loop_control: | ||
| label: "{{ item.name }}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| --- | ||
| # loop_var: clustergroup_discovery_stem — append {name, path} to clustergroup_file_entries when file exists. | ||
|
|
||
| - name: Stat values file for stem {{ clustergroup_discovery_stem }} (yaml) | ||
| ansible.builtin.stat: | ||
| path: "{{ pattern_dir | string | trim }}/values-{{ clustergroup_discovery_stem | string | trim }}.yaml" | ||
| register: _clustergroup_discovery_stem_stat_yaml | ||
|
|
||
| - name: Stat values file for stem {{ clustergroup_discovery_stem }} (yml) | ||
| ansible.builtin.stat: | ||
| path: "{{ pattern_dir | string | trim }}/values-{{ clustergroup_discovery_stem | string | trim }}.yml" | ||
| register: _clustergroup_discovery_stem_stat_yml | ||
|
|
||
| - name: Record clustergroup file entry for {{ clustergroup_discovery_stem }} (prefer yaml) | ||
| ansible.builtin.set_fact: | ||
| clustergroup_file_entries: "{{ clustergroup_file_entries | default([]) + [_entry] }}" | ||
| vars: | ||
| _entry: | ||
| name: "{{ clustergroup_discovery_stem | string | trim }}" | ||
| path: "{{ pattern_dir | string | trim }}/values-{{ clustergroup_discovery_stem | string | trim }}.yaml" | ||
| when: _clustergroup_discovery_stem_stat_yaml.stat.exists | default(false) | ||
|
|
||
| - name: Record clustergroup file entry for {{ clustergroup_discovery_stem }} (yml fallback) | ||
| ansible.builtin.set_fact: | ||
| clustergroup_file_entries: "{{ clustergroup_file_entries | default([]) + [_entry] }}" | ||
| vars: | ||
| _entry: | ||
| name: "{{ clustergroup_discovery_stem | string | trim }}" | ||
| path: "{{ pattern_dir | string | trim }}/values-{{ clustergroup_discovery_stem | string | trim }}.yml" | ||
| when: | ||
| - not (_clustergroup_discovery_stem_stat_yaml.stat.exists | default(false)) | ||
| - _clustergroup_discovery_stem_stat_yml.stat.exists | default(false) |
Uh oh!
There was an error while loading. Please reload this page.