Skip to content
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

Generate replacement requirements documentation for components #209

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/component-replaces-generator/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Documentation generator
hosts: localhost
gather_facts: no

Check warning on line 4 in docs/component-replaces-generator/main.yml

View workflow job for this annotation

GitHub Actions / yaml-lint

4:17 [truthy] truthy value should be one of [false, true]
tasks:
- name: Generate some documentation
ansible.builtin.import_role:
name: docs_generator
38 changes: 38 additions & 0 deletions docs/component-replaces-generator/roles/docs_generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for docs_generator
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

ANSIBLE_METADATA = {
'metadata_version': '0.1',
'status': ['preview'],
'supported_by': 'community'
}

class FilterModule(object):
def filters(self):
return {
'tree': self.tree_builder
}

def tree_builder(self, value):
tree = {}

t = tree
for part in value.split('.'):
t = t.setdefault(part, {})
return tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for docs_generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
galaxy_info:

Check warning on line 1 in docs/component-replaces-generator/roles/docs_generator/meta/main.yml

View workflow job for this annotation

GitHub Actions / yaml-lint

1:1 [document-start] missing document start "---"
author: Leif Madsen
description: Generates common component replaces requirements documentation
company: Red Hat

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: Apache-2.0

min_ansible_version: 2.16

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes

Check warning on line 43 in docs/component-replaces-generator/roles/docs_generator/meta/main.yml

View workflow job for this annotation

GitHub Actions / yaml-lint

43:5 [comments-indentation] comment not indented like content
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,

Check warning on line 51 in docs/component-replaces-generator/roles/docs_generator/meta/main.yml

View workflow job for this annotation

GitHub Actions / yaml-lint

51:3 [comments-indentation] comment not indented like content
# if you add dependencies to this list.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
- name: Show component contents
ansible.builtin.debug:
var: component_path

- name: Set component name
ansible.builtin.set_fact:
component_name: "{{ component_path.split('/')[-2] | trim }}"

- name: Set component directory
ansible.builtin.set_fact:
component_dir: "{{ component_path.split('/')[:-1] | join('/') }}"

- name: Read contents of module
ansible.builtin.slurp:
src: "{{ component_path }}"
register: kustomization_contents

- name: Interpret as yaml
ansible.builtin.set_fact:
kustomize_yaml: '{{ kustomization_contents.content | b64decode | from_yaml }}'

- name: Show yaml
ansible.builtin.debug:
var: kustomize_yaml

- name: Get all the fieldpaths
ansible.builtin.set_fact:
fieldpaths: "{{ fieldpaths|default([]) + [item.source.fieldPath] }}"
loop: "{{ kustomize_yaml.replacements }}"
when: "'replacements' in kustomize_yaml"

- name: Show replacements
ansible.builtin.debug:
var: fieldpaths

- name: Build new structure
loop: "{{ fieldpaths }}"
ansible.builtin.set_fact:
source_dict: "{{ source_dict|default({}) | combine(item | tree, recursive=True) }}"

- name: Show source_dict
ansible.builtin.debug:
var: source_dict

- name: Describe which component we're working on
ansible.builtin.debug:
msg: |
Working on documentation for {{ component_name }} at {{ component_dir }}

- name: Generate the documentation {{ component_name }}
ansible.builtin.template:
src: component_docs.j2
dest: "{{ component_dir }}/component_replacements.md"
when: "'replacements' in kustomize_yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
# tasks file for docs_generator
- name: Find common component directories
ansible.builtin.find:
paths: "{{ playbook_dir }}/../../lib/"
recurse: yes

Check warning on line 6 in docs/component-replaces-generator/roles/docs_generator/tasks/main.yml

View workflow job for this annotation

GitHub Actions / yaml-lint

6:14 [truthy] truthy value should be one of [false, true]
patterns: 'kustomization.yaml'
register: common_components_index

- name: Set common component path list
ansible.builtin.set_fact:
common_components: "{{ common_components_index.files | map(attribute='path') | list }}"

- name: Show common components
ansible.builtin.debug:
msg: "{{ item }}"
loop: "{{ common_components }}"

- name: Generate component interface documentation
loop: "{{ common_components }}"
ansible.builtin.include_tasks: generate_component_interface.yaml
loop_control:
loop_var: component_path
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
## Component {{ component_name }} replacement requirements

Each component expects a set of ConfigMap parameters to be passed to it so that
manifests can be generated by kustomize.

The component expects the parameters to be set in a corresponding local
ConfigMap in the overlay. Defaults are generally not provided by the component,
and errors will be thrown if the expected parameter is missing when building
the manifests with kustomize.

| ConfigMap source name | Parameter field path |
| ----------- | ---------- |
{% for replacement in kustomize_yaml.replacements %}
| {{ replacement.source.name }} | {{ replacement.source.fieldPath }} |
{% endfor %}

### Creating the local ConfigMap file

In the overlay, create a file that will hold the parameters for the component which will be later included as a resource within the `kustomization.yaml` file. The resource name may match the ConfigMap source name with `.yaml` appended or another filename such as `values.yaml`.

```yaml
# local-config: referenced, but not emitted by kustomize
---
apiVersion: v1
kind: ConfigMap
metadata:
name: <source_name>
annotations:
config.kubernetes.io/local-config: "true"
{{ source_dict | to_nice_yaml }}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- docs_generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for docs_generator
88 changes: 88 additions & 0 deletions lib/control-plane/component_replacements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
## Component control-plane replacement requirements

Each component expects a set of ConfigMap parameters to be passed to it so that
manifests can be generated by kustomize.

The component expects the parameters to be set in a corresponding local
ConfigMap in the overlay. Defaults are generally not provided by the component,
and errors will be thrown if the expected parameter is missing when building
the manifests with kustomize.

| ConfigMap source name | Parameter field path |
| ----------- | ---------- |
| network-values | data.internalapi.endpoint_annotations |
| network-values | data.ctlplane.endpoint_annotations |
| network-values | data.rabbitmq.endpoint_annotations |
| network-values | data.rabbitmq-cell1.endpoint_annotations |
| network-values | data.lbServiceType |
| network-values | data.dns-resolver.options |
| network-values | data.storageClass |
| network-values | data.bridgeName |

### Creating the local ConfigMap file

In the overlay, create a file that will hold the parameters for the component which will be later included as a resource within the `kustomization.yaml` file. The resource name may match the ConfigMap source name with `.yaml` appended or another filename such as `values.yaml`.

```yaml
# local-config: referenced, but not emitted by kustomize
---
apiVersion: v1
kind: ConfigMap
metadata:
name: <source_name>
annotations:
config.kubernetes.io/local-config: "true"
data:
bridgeName: {}
ctlplane:
endpoint_annotations: {}
iface: {}
mtu: {}
prefix-length: {}
dns-resolver:
config: {}
options: {}
internalapi:
base_iface: {}
endpoint_annotations: {}
mtu: {}
prefix-length: {}
vlan: {}
lbServiceType: {}
node_0:
ctlplane_ip: {}
internalapi_ip: {}
name: {}
storage_ip: {}
tenant_ip: {}
node_1:
ctlplane_ip: {}
internalapi_ip: {}
name: {}
storage_ip: {}
tenant_ip: {}
node_2:
ctlplane_ip: {}
internalapi_ip: {}
name: {}
storage_ip: {}
tenant_ip: {}
rabbitmq:
endpoint_annotations: {}
rabbitmq-cell1:
endpoint_annotations: {}
routes: {}
storage:
base_iface: {}
mtu: {}
prefix-length: {}
vlan: {}
storageClass: {}
tenant:
base_iface: {}
mtu: {}
prefix-length: {}
vlan: {}

```
Loading
Loading