Skip to content

Commit

Permalink
fix: Add test for argument_specs matching (#177)
Browse files Browse the repository at this point in the history
* fix: Add test for argument_specs matching

Compare contents of `meta/arguments_spec.yml` against `defaults/main.yml` on
each role to make sure keys match.

Signed-off-by: SuperQ <[email protected]>

* Fixup arguments_spec linting issues.

Signed-off-by: SuperQ <[email protected]>

---------

Signed-off-by: SuperQ <[email protected]>
  • Loading branch information
SuperQ authored Aug 16, 2023
1 parent 766f0d7 commit 100b6e2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
22 changes: 22 additions & 0 deletions .github/scripts/lint_arguments_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
#
# Description: Lint the defaults/main.yml against the meta/arguments_spec.yml

lint_diff() {
diff -u \
<(yq 'keys | .[]' "${role}/defaults/main.yml" | sort -u) \
<(yq '.argument_specs.main.options | keys | .[] ' "${role}/meta/argument_specs.yml" | sort -u)
return $?
}

error=0

for role in roles/* ; do
echo "Checking ${role}"
if ! lint_diff ; then
echo "ERROR: ${role}: meta/argument_specs.yml doesn't match defaults/main.yml"
error=1
fi
done

exit "${error}"
9 changes: 9 additions & 0 deletions .github/workflows/ansible-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ jobs:
- name: Lint collection
uses: ansible/ansible-lint@main

arguments-spec-lint:
runs-on: ubuntu-latest
container:
image: quay.io/prometheus/golang-builder:base
steps:
- uses: actions/checkout@v3
- name: Lint arguments spec
run: ./.github/scripts/lint_arguments_spec.sh

discover-ansible-versions:
runs-on: ubuntu-latest
outputs:
Expand Down
6 changes: 6 additions & 0 deletions roles/blackbox_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ argument_specs:
blackbox_exporter_config_dir:
description: "Directory where the blackbox exporter configuration file is placed"
default: "/etc"
blackbox_exporter_user:
description: "The user the exporter runs as"
default: "blackbox-exp"
blackbox_exporter_group:
description: "The group the exporter runs as"
default: "blackbox-exp"
4 changes: 2 additions & 2 deletions roles/mysqld_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ mysqld_exporter_username: exporter
mysqld_exporter_password: secret

mysqld_exporter_config_file: "mysqld_exporter.cnf"
# mysqld_exporter_host: localhost
# mysqld_exporter_port: 3306
mysqld_exporter_host: null
mysqld_exporter_port: null
mysqld_exporter_socket: "/run/mysqld/mysqld.sock"

mysqld_exporter_tls_server_config: {}
Expand Down
9 changes: 9 additions & 0 deletions roles/mysqld_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ argument_specs:
mysqld_exporter_web_telemetry_path:
description: "Path under which to expose metrics"
default: "/metrics"
mysqld_exporter_config_dir:
description: "The path where exporter configuration is stored"
default: "/etc/mysqld_exporter"
mysqld_exporter_config_file:
description: "The filename of the exporter mysql config file"
default: "mysqld_exporter.cnf"
Expand All @@ -42,6 +45,12 @@ argument_specs:
mysqld_exporter_socket:
description: "The target MySQL unix socket"
default: "/run/mysqld/mysqld.sock"
mysqld_exporter_username:
description: "The username for MySQL login"
default: "exporter"
mysqld_exporter_password:
description: "The password for MySQL login"
default: "secret"
mysqld_exporter_enabled_collectors:
description:
- "List of dicts defining additionally enabled collectors and their configuration."
Expand Down

0 comments on commit 100b6e2

Please sign in to comment.