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
@@ -149,3 +149,44 @@ teardown() {
|
||||
assert_failure
|
||||
assert_output_contains "Invalid flag passed"
|
||||
}
|
||||
|
||||
@test "(scheduler-k3s:autoscaling-auth:set) --replace drops metadata keys not named" {
|
||||
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:set $TEST_APP datadog --metadata apiKey=secret-1 --metadata appKey=secret-2 --metadata datadogSite=us5.datadoghq.com"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:set $TEST_APP datadog --metadata apiKey=secret-3"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:report $TEST_APP --format json | jq -r 'keys | sort | join(\",\")'"
|
||||
assert_success
|
||||
assert_output "datadog.apiKey,datadog.appKey,datadog.datadogSite"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:set --replace $TEST_APP datadog --metadata apiKey=secret-4"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:report $TEST_APP --format json | jq -r 'keys | sort | join(\",\")'"
|
||||
assert_success
|
||||
assert_output "datadog.apiKey"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:report $TEST_APP --format json | jq -r '.\"datadog.apiKey\"'"
|
||||
assert_success
|
||||
assert_output "secret-4"
|
||||
}
|
||||
|
||||
@test "(scheduler-k3s:autoscaling-auth:set) --replace requires metadata and leaves other triggers alone" {
|
||||
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 memory --metadata some-key=some-value"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:set --replace $TEST_APP datadog"
|
||||
assert_failure
|
||||
assert_output_contains "Must specify at least one --metadata flag, omit --replace to remove all metadata for the trigger"
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:set --replace $TEST_APP datadog --metadata appKey=secret-2"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku scheduler-k3s:autoscaling-auth:report $TEST_APP --format json | jq -r 'keys | sort | join(\",\")'"
|
||||
assert_success
|
||||
assert_output "datadog.appKey,memory.some-key"
|
||||
}
|
||||
Reference in new issue
Block a user