feat: add a whole-set form for scheduler-k3s metadata
The `scheduler-k3s` metadata commands were all per-key, so matching an app's stored annotations, labels or node sysctls to a declared set meant reading the report, computing the difference in both directions and issuing one command per added, changed and removed key, with a failure partway through leaving a mixture of the two sets. A `--replace` flag on `annotations:set`, `labels:set`, `node-sysctls:set` and `autoscaling-auth:set` now writes the declared map in a single call, taking trailing `key=value` pairs everywhere except `autoscaling-auth:set`, which keeps its repeatable `--metadata` flag. Every pair is parsed before anything is written, so a rejected pair leaves the stored map untouched, and a pair ending in `=` stores an empty value, which the per-key form cannot express. An empty pair list is rejected rather than treated as a request to remove everything, so a generated list that expands to nothing cannot silently drop an app's metadata; `annotations:clear`, `labels:clear` and `node-sysctls:clear` handle that case, taking the same optional filters as their report commands. The `--resource-type` flag and the app name are now validated on the set commands as well, where a typo previously exited zero and wrote a property that no report and no deploy ever read.
This commit is contained in:
12 files changed
+1271
-195
No files matched your search
@@ -10,10 +10,8 @@ setup() {
|
||||
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
|
||||
dokku scheduler-k3s:annotations:clear --global >/dev/null 2>/dev/null || true
|
||||
dokku scheduler-k3s:node-sysctls:clear --global >/dev/null 2>/dev/null || true
|
||||
global_teardown
|
||||
}
|
||||
|
||||
@@ -113,3 +111,166 @@ teardown() {
|
||||
assert_failure
|
||||
assert_output_contains "Invalid flag passed"
|
||||
}
|
||||
|
||||
@test "(scheduler-k3s:annotations:set) --replace writes the declared map in one call" {
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set $TEST_APP --resource-type deployment keep old-value"
|
||||
assert_success
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set $TEST_APP --resource-type deployment drop dropped-value"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set --replace $TEST_APP --resource-type deployment keep=new-value add=added-value"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --format json | jq -r 'keys | sort | join(\",\")'"
|
||||
assert_success
|
||||
assert_output "global.deployment.add,global.deployment.keep"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --format json | jq -r '.\"global.deployment.keep\"'"
|
||||
assert_success
|
||||
assert_output "new-value"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set --replace $TEST_APP --resource-type deployment --process-type web scoped=scoped-value"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --format json | jq -r 'keys | sort | join(\",\")'"
|
||||
assert_success
|
||||
assert_output "global.deployment.add,global.deployment.keep,web.deployment.scoped"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set --replace --global --resource-type deployment global-key=global-value"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:report --global --format json | jq -r '.\"global.deployment.global-key\"'"
|
||||
assert_success
|
||||
assert_output "global-value"
|
||||
}
|
||||
|
||||
@test "(scheduler-k3s:annotations:set) --replace stores empty values and rejects malformed pair lists" {
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set --replace $TEST_APP --resource-type deployment empty="
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --format json | jq -r '.\"global.deployment.empty\"'"
|
||||
assert_success
|
||||
assert_output ""
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set --replace $TEST_APP --resource-type deployment"
|
||||
assert_failure
|
||||
assert_output_contains "Must specify at least one key=value pair, use scheduler-k3s:annotations:clear to remove all annotations"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set --replace $TEST_APP --resource-type deployment nodelimiter"
|
||||
assert_failure
|
||||
assert_output_contains "Invalid key=value pair: nodelimiter"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set --replace $TEST_APP --resource-type deployment foo=bar foo=qux"
|
||||
assert_failure
|
||||
assert_output_contains "Duplicate key specified: foo"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --format json | jq -r 'keys | sort | join(\",\")'"
|
||||
assert_success
|
||||
assert_output "global.deployment.empty"
|
||||
}
|
||||
|
||||
@test "(scheduler-k3s:annotations:set) rejects an unknown resource-type and a missing app" {
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set $TEST_APP --resource-type deploymnet foo bar"
|
||||
assert_failure
|
||||
assert_output_contains "Invalid resource-type specified, valid resource types include:"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set --replace $TEST_APP --resource-type deploymnet foo=bar"
|
||||
assert_failure
|
||||
assert_output_contains "Invalid resource-type specified, valid resource types include:"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set ${TEST_APP}-missing --resource-type deployment foo bar"
|
||||
assert_failure
|
||||
assert_output_contains "App ${TEST_APP}-missing does not exist"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:set --replace ${TEST_APP}-missing --resource-type deployment foo=bar"
|
||||
assert_failure
|
||||
assert_output_contains "App ${TEST_APP}-missing does not exist"
|
||||
}
|
||||
|
||||
@test "(scheduler-k3s:annotations:clear) removes annotations, honouring 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:clear $TEST_APP --process-type web"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --format json | jq -r 'keys | sort | join(\",\")'"
|
||||
assert_success
|
||||
assert_output "global.deployment.foo,global.service.alpha"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:clear $TEST_APP --resource-type service"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --format json | jq -r 'keys | sort | join(\",\")'"
|
||||
assert_success
|
||||
assert_output "global.deployment.foo"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:clear $TEST_APP"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --format json"
|
||||
assert_success
|
||||
assert_output "{}"
|
||||
}
|
||||
|
||||
@test "(scheduler-k3s:annotations:clear) leaves neighbouring scheduler-k3s properties alone" {
|
||||
run /bin/bash -c "dokku scheduler-k3s:set $TEST_APP deploy-timeout 300s"
|
||||
assert_success
|
||||
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:set --global vm.max_map_count 262144"
|
||||
assert_success
|
||||
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:annotations:set $TEST_APP --resource-type deployment foo bar"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:clear $TEST_APP"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:report $TEST_APP --format json"
|
||||
assert_success
|
||||
assert_output "{}"
|
||||
|
||||
run /bin/bash -c "dokku --quiet scheduler-k3s:report $TEST_APP --scheduler-k3s-deploy-timeout"
|
||||
assert_success
|
||||
assert_output "300s"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:report --format json | jq -r '.\"--global\".\"vm.max_map_count\"'"
|
||||
assert_success
|
||||
assert_output "262144"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:report $TEST_APP --format json | jq -r '.\"datadog.apiKey\"'"
|
||||
assert_success
|
||||
assert_output "secret-1"
|
||||
}
|
||||
|
||||
@test "(scheduler-k3s:annotations:clear) supports --global and requires an app" {
|
||||
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:clear"
|
||||
assert_failure
|
||||
assert_output_contains "Please specify an app to run the command on"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:clear ${TEST_APP}-missing"
|
||||
assert_failure
|
||||
assert_output_contains "App ${TEST_APP}-missing does not exist"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:clear $TEST_APP --resource-type deploymnet"
|
||||
assert_failure
|
||||
assert_output_contains "Invalid resource-type specified, valid resource types include:"
|
||||
|
||||
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:clear --global"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:annotations:report --global --format json"
|
||||
assert_success
|
||||
assert_output "{}"
|
||||
}
|
||||
Reference in new issue
Block a user