feat: add scheduler-k3s annotations:report and labels:report

The scheduler-k3s plugin exposes `annotations:set` and `labels:set` but no matching report subcommands, so scripts could not inspect the configured state for idempotent management without reading the property files directly. The new `scheduler-k3s:annotations:report` and `scheduler-k3s:labels:report` surface the configured entries with stdout, JSON, single-flag query, and `--process-type` / `--resource-type` filtering, mirroring the recently added `scheduler-k3s:charts:report`. The literal `GlobalProcessType` value `--global` is rendered as `global` in report keys to avoid leading dashes. The `scheduler-k3s:autoscaling-auth:report` command is updated alongside to loop over every app when no app and no `--global` flag is provided, matching the convention used by `scheduler-k3s:report`.
This commit is contained in:
Jose Diaz-Gonzalez
2026-05-30 20:12:00 -04:00
parent 4346a18194
commit 5dbb2951bb
10 changed files with 712 additions and 19 deletions

View File

@@ -0,0 +1,88 @@
#!/usr/bin/env bats
load test_helper
setup() {
global_setup
dokku apps:create $TEST_APP >/dev/null 2>/dev/null || true
}
teardown() {
dokku --force apps:destroy $TEST_APP >/dev/null 2>/dev/null || true
dokku --force apps:destroy ${TEST_APP}-2 >/dev/null 2>/dev/null || true
for resource in deployment service pod cronjob job secret ingress serviceaccount; do
dokku scheduler-k3s:annotations:set --global --resource-type "$resource" foo "" >/dev/null 2>/dev/null || true
dokku scheduler-k3s:annotations:set --global --resource-type "$resource" bar "" >/dev/null 2>/dev/null || true
done
global_teardown
}
@test "(scheduler-k3s:annotations:report) lists annotations after set, clears them after unset" {
run /bin/bash -c "dokku scheduler-k3s:annotations:set $TEST_APP --resource-type deployment foo bar"
assert_success
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --format json | jq -r '.\"global.deployment.foo\"'"
assert_success
assert_output "bar"
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP"
assert_success
assert_output_contains "$TEST_APP annotations information"
assert_output_contains "Annotation (global/deployment) foo:"
assert_output_contains "bar"
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --scheduler-k3s-annotations.global.deployment.foo"
assert_success
assert_output "bar"
run /bin/bash -c "dokku scheduler-k3s:annotations:set $TEST_APP --resource-type deployment foo"
assert_success
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --format json"
assert_success
assert_output "{}"
}
@test "(scheduler-k3s:annotations:report) honours --process-type and --resource-type filters" {
run /bin/bash -c "dokku scheduler-k3s:annotations:set $TEST_APP --resource-type deployment foo bar"
assert_success
run /bin/bash -c "dokku scheduler-k3s:annotations:set $TEST_APP --process-type web --resource-type deployment baz qux"
assert_success
run /bin/bash -c "dokku scheduler-k3s:annotations:set $TEST_APP --resource-type service alpha beta"
assert_success
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --resource-type deployment --format json | jq -r 'keys | sort | join(\",\")'"
assert_success
assert_output "global.deployment.foo,web.deployment.baz"
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --process-type web --format json | jq -r 'keys | sort | join(\",\")'"
assert_success
assert_output "web.deployment.baz"
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --process-type web --resource-type deployment --format json | jq -r '.\"web.deployment.baz\"'"
assert_success
assert_output "qux"
}
@test "(scheduler-k3s:annotations:report) supports --global scope and no-arg multi-app loop" {
run /bin/bash -c "dokku apps:create ${TEST_APP}-2"
assert_success
run /bin/bash -c "dokku scheduler-k3s:annotations:set --global --resource-type deployment foo global-val"
assert_success
run /bin/bash -c "dokku scheduler-k3s:annotations:set $TEST_APP --resource-type deployment foo app1-val"
assert_success
run /bin/bash -c "dokku scheduler-k3s:annotations:set ${TEST_APP}-2 --resource-type deployment bar app2-val"
assert_success
run /bin/bash -c "dokku scheduler-k3s:annotations:report --global --format json | jq -r '.\"global.deployment.foo\"'"
assert_success
assert_output "global-val"
run /bin/bash -c "dokku scheduler-k3s:annotations:report"
assert_success
assert_output_contains "$TEST_APP annotations information"
assert_output_contains "${TEST_APP}-2 annotations information"
assert_output_contains "app1-val"
assert_output_contains "app2-val"
}

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env bats
load test_helper
setup() {
global_setup
dokku apps:create $TEST_APP >/dev/null 2>/dev/null || true
dokku apps:create ${TEST_APP}-2 >/dev/null 2>/dev/null || true
}
teardown() {
dokku scheduler-k3s:autoscaling-auth:set $TEST_APP datadog >/dev/null 2>/dev/null || true
dokku scheduler-k3s:autoscaling-auth:set ${TEST_APP}-2 datadog >/dev/null 2>/dev/null || true
dokku --force apps:destroy $TEST_APP >/dev/null 2>/dev/null || true
dokku --force apps:destroy ${TEST_APP}-2 >/dev/null 2>/dev/null || true
global_teardown
}
@test "(scheduler-k3s:autoscaling-auth:report) no-arg loops all apps" {
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:set $TEST_APP datadog --metadata apiKey=secret-1"
assert_success
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:set ${TEST_APP}-2 datadog --metadata apiKey=secret-2"
assert_success
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:report"
assert_success
assert_output_contains "$TEST_APP scheduler-k3s information"
assert_output_contains "${TEST_APP}-2 scheduler-k3s information"
assert_output_contains "Datadog:" 2
}

View File

@@ -0,0 +1,88 @@
#!/usr/bin/env bats
load test_helper
setup() {
global_setup
dokku apps:create $TEST_APP >/dev/null 2>/dev/null || true
}
teardown() {
dokku --force apps:destroy $TEST_APP >/dev/null 2>/dev/null || true
dokku --force apps:destroy ${TEST_APP}-2 >/dev/null 2>/dev/null || true
for resource in deployment service pod cronjob job secret ingress serviceaccount; do
dokku scheduler-k3s:labels:set --global --resource-type "$resource" foo "" >/dev/null 2>/dev/null || true
dokku scheduler-k3s:labels:set --global --resource-type "$resource" bar "" >/dev/null 2>/dev/null || true
done
global_teardown
}
@test "(scheduler-k3s:labels:report) lists labels after set, clears them after unset" {
run /bin/bash -c "dokku scheduler-k3s:labels:set $TEST_APP --resource-type deployment foo bar"
assert_success
run /bin/bash -c "dokku scheduler-k3s:labels:report $TEST_APP --format json | jq -r '.\"global.deployment.foo\"'"
assert_success
assert_output "bar"
run /bin/bash -c "dokku scheduler-k3s:labels:report $TEST_APP"
assert_success
assert_output_contains "$TEST_APP labels information"
assert_output_contains "Label (global/deployment) foo:"
assert_output_contains "bar"
run /bin/bash -c "dokku scheduler-k3s:labels:report $TEST_APP --scheduler-k3s-labels.global.deployment.foo"
assert_success
assert_output "bar"
run /bin/bash -c "dokku scheduler-k3s:labels:set $TEST_APP --resource-type deployment foo"
assert_success
run /bin/bash -c "dokku scheduler-k3s:labels:report $TEST_APP --format json"
assert_success
assert_output "{}"
}
@test "(scheduler-k3s:labels:report) honours --process-type and --resource-type filters" {
run /bin/bash -c "dokku scheduler-k3s:labels:set $TEST_APP --resource-type deployment foo bar"
assert_success
run /bin/bash -c "dokku scheduler-k3s:labels:set $TEST_APP --process-type web --resource-type deployment baz qux"
assert_success
run /bin/bash -c "dokku scheduler-k3s:labels:set $TEST_APP --resource-type service alpha beta"
assert_success
run /bin/bash -c "dokku scheduler-k3s:labels:report $TEST_APP --resource-type deployment --format json | jq -r 'keys | sort | join(\",\")'"
assert_success
assert_output "global.deployment.foo,web.deployment.baz"
run /bin/bash -c "dokku scheduler-k3s:labels:report $TEST_APP --process-type web --format json | jq -r 'keys | sort | join(\",\")'"
assert_success
assert_output "web.deployment.baz"
run /bin/bash -c "dokku scheduler-k3s:labels:report $TEST_APP --process-type web --resource-type deployment --format json | jq -r '.\"web.deployment.baz\"'"
assert_success
assert_output "qux"
}
@test "(scheduler-k3s:labels:report) supports --global scope and no-arg multi-app loop" {
run /bin/bash -c "dokku apps:create ${TEST_APP}-2"
assert_success
run /bin/bash -c "dokku scheduler-k3s:labels:set --global --resource-type deployment foo global-val"
assert_success
run /bin/bash -c "dokku scheduler-k3s:labels:set $TEST_APP --resource-type deployment foo app1-val"
assert_success
run /bin/bash -c "dokku scheduler-k3s:labels:set ${TEST_APP}-2 --resource-type deployment bar app2-val"
assert_success
run /bin/bash -c "dokku scheduler-k3s:labels:report --global --format json | jq -r '.\"global.deployment.foo\"'"
assert_success
assert_output "global-val"
run /bin/bash -c "dokku scheduler-k3s:labels:report"
assert_success
assert_output_contains "$TEST_APP labels information"
assert_output_contains "${TEST_APP}-2 labels information"
assert_output_contains "app1-val"
assert_output_contains "app2-val"
}