If you want to test the changes made to this repo, you can do it by simply running apb test
The test does the following:
- Builds the APB
- Creates the project in currently targeted OpenShift instance
- Runs the
provision
role - Runs the
test-provision
role which checks that- Grafana and Prometheus routes are accessible
- we're getting successful response from OpenShift auth proxy server
- Runs
deprovision
role - Runs
deprovision-test
role which checks that all objects (routes, pods, services) were deprovisioned successfully
If the test ends successfully, you should see the message Pod phase Succeeded without returning test results
in your console output.
For more information about testing of APBs, check ansible-playbook-bundle documentation
See the inline comments here and the example config from Prometheus here.
Grafana picks up any dashboard JSON files that are placed inside the grafana-dashboards-configmap
. This section describes how to add a new dashboard into the grafana-dashboards-configmap
from inside an APB. The APB that provisions the service should also be responsible for adding the dashboard.
A reusable Ansible role for adding JSON files to a Config Map has been created: https://github.com/aerogear/oc-patch-file-to-configmap-role. The sections below demostrate how to use the role.
Under the playbooks
directory create a file requirements.yml
:
- src: https://github.com/aerogear/oc-patch-file-to-configmap-role
version: master
name: oc-patch-file-to-configmap
This file defines the oc-patch-file-to-configmap
role as a dependency.
The next step is to modify the default Dockerfile
. The default APB Dockerfile usually has a list of commands like this:
COPY playbooks /opt/apb/actions
COPY roles /opt/ansible/roles
COPY vars /opt/ansible/vars
RUN chmod -R g=u /opt/{ansible,apb}
USER apb
Add the following line before the RUN chmod -R g=u /opt/{ansible,apb}
command:
RUN ansible-galaxy install -r /opt/apb/actions/requirements.yml -p /opt/ansible/roles
This command uses the ansible-galaxy
CLI tool to install dependencies in requirements.yml
into the appropriate roles directory. This means when apb build
is run, the oc-patch-file-to-configmap
role is installed into the APB image.
It is recommended to use the oc-patch-file-to-configmap
role directly within the role being used to provision the service (e.g. provision-keycloak-apb
). The role directory structure should be similar to this:
├── defaults
│ └── main.yml
├── files
│ ├── ... # role specific files
├── tasks
│ └── main.yml
└── templates
├── ... # role specific templates
First, place the dashboard json file underneath the files
directory. e.g. files/keycloak-dashboard.json
Next, add the following variables to defaults/main.yml
# Dashboard config
dashboards_configmap: grafana-dashboards-configmap # this should not change
dashboard_filename: keycloak-dashboard.json # name the file will have inside the config map
dashboard_file_contents: "{{ lookup('file','../files/keycloak-dashboard.json') }}" # Contents of the dashboard file
Note the dashboard_filename
is the name the file will have inside the Config Map. This name should not clash with another service. If a file with the same name already exists in the Config Map, it will be overwritten.
Lastly, add the following into tasks/main.yml
- include_role:
name: oc-patch-file-to-configmap
vars:
file_contents: "{{ dashboard_file_contents }}"
filename: "{{ dashboard_filename }}"
configmap: "{{ dashboards_configmap }}"
namespace: "{{ namespace }}"
This instructs Ansible to execute the role, passing in the appropriate variables.
Note If the usage of this role is still not clear, take a look at the usage in the Keycloak APB.