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

feat: add backend option to action #23

Merged
merged 2 commits into from
Feb 22, 2024
Merged
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM grafana/cortex-tools:v0.10.6
FROM grafana/cortex-tools:v0.11.0

COPY entrypoint.sh /entrypoint.sh

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ This action is used to lint, prepare, verify, diff, and sync rules to a [Cortex]
This action is configured using environment variables defined in the workflow. The following variables can be configured.

| Name | Description | Required | Default |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------- |
| `CORTEX_ADDRESS` | URL address for the target Cortex cluster | `false` | N/A |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------- |
| `CORTEX_ADDRESS` | URL address for the target Cortex cluster | `false` | N/A |
| `CORTEX_TENANT_ID` | ID for the desired tenant in the target Cortex cluster. Used as the username under HTTP Basic authentication. | `false` | N/A |
| `CORTEX_API_KEY` | Optional password that is required for password-protected Cortex clusters. An encrypted [github secret](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets ) is recommended. Used as the password under HTTP Basic authentication. | `false` | N/A |
| `ACTION` | Which action to take. One of `lint`, `prepare`, `check`, `diff` or `sync` | `true` | N/A |
| `RULES_DIR` | Comma-separated list of directories to walk in order to source rules files | `false` | `./` |
| `LABEL_EXCLUDED_RULE_GROUPS` | Comma separated list of rule group names to exclude when including the configured label to aggregations. This option is supported only by the `prepare` action. | `false` | N/A |
| `NAMESPACES` | Comma-separated list of namespaces to use | `false` | N/A |
| `ACTION` | Which action to take. One of `lint`, `prepare`, `check`, `diff` or `sync` | `true` | N/A |
| `RULES_DIR` | Comma-separated list of directories to walk in order to source rules files | `false` | `./` |
| `LABEL_EXCLUDED_RULE_GROUPS` | Comma separated list of rule group names to exclude when including the configured label to aggregations. This option is supported only by the `prepare` action. | `false` | N/A |
| `NAMESPACES` | Comma-separated list of namespaces to use | `false` | N/A |
| `BACKEND` | Backend type to interact with: cortex, loki | `false` | `cortex` |

## Authentication

Expand Down
17 changes: 11 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ SYNC_CMD=sync
DIFF_CMD="diff"
PRINT_CMD=print

if [ -z "${BACKEND}" ]; then
echo "BACKEND not set, using 'cortex' as a default."
BACKEND="cortex"
fi

if [ -z "${RULES_DIR}" ]; then
echo "RULES_DIR not set, using './' as a default."
RULES_DIR="./"
Expand All @@ -41,28 +46,28 @@ fi
case "${ACTION}" in
"$SYNC_CMD")
verifyTenantAndAddress
OUTPUT=$(/usr/bin/cortextool rules sync --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} "$@")
OUTPUT=$(/usr/bin/cortextool rules sync --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} "$@")
STATUS=$?
;;
"$DIFF_CMD")
verifyTenantAndAddress
OUTPUT=$(/usr/bin/cortextool rules diff --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} --disable-color "$@")
OUTPUT=$(/usr/bin/cortextool rules diff --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} --disable-color "$@")
STATUS=$?
;;
"$LINT_CMD")
OUTPUT=$(/usr/bin/cortextool rules lint --rule-dirs="${RULES_DIR}" "$@")
OUTPUT=$(/usr/bin/cortextool rules lint --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" "$@")
STATUS=$?
;;
"$PREPARE_CMD")
OUTPUT=$(/usr/bin/cortextool rules prepare -i --rule-dirs="${RULES_DIR}" --label-excluded-rule-groups="${LABEL_EXCLUDED_RULE_GROUPS}" "$@")
OUTPUT=$(/usr/bin/cortextool rules prepare --backend="${BACKEND}" -i --rule-dirs="${RULES_DIR}" --label-excluded-rule-groups="${LABEL_EXCLUDED_RULE_GROUPS}" "$@")
STATUS=$?
;;
"$CHECK_CMD")
OUTPUT=$(/usr/bin/cortextool rules check --rule-dirs="${RULES_DIR}" "$@")
OUTPUT=$(/usr/bin/cortextool rules check --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" "$@")
STATUS=$?
;;
"$PRINT_CMD")
OUTPUT=$(/usr/bin/cortextool rules print --disable-color "$@")
OUTPUT=$(/usr/bin/cortextool rules print --backend="${BACKEND}" --disable-color "$@")
STATUS=$?
;;
*)
Expand Down
Loading