Files
dokku/tests/unit/scheduler-k3s-node-sysctls.bats
T
Jose Diaz-Gonzalez c37a71b90b 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.
2026-09-18 05:14:51 -04:00

88 lines
3.6 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
global_setup
}
teardown() {
dokku scheduler-k3s:node-sysctls:clear --global >/dev/null 2>/dev/null || true
dokku scheduler-k3s:node-sysctls:clear --profile edge-workers >/dev/null 2>/dev/null || true
dokku scheduler-k3s:profiles:remove edge-workers >/dev/null 2>/dev/null || true
global_teardown
}
@test "(scheduler-k3s:node-sysctls:set) --replace writes the declared map in one call" {
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:node-sysctls:set --global vm.swappiness 10"
assert_success
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:set --replace --global vm.swappiness=20 vm.overcommit_memory=1"
assert_success
assert_output_contains "Removing vm.max_map_count stops dokku managing it"
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:report --format json | jq -r '.\"--global\" | keys | sort | join(\",\")'"
assert_success
assert_output "vm.overcommit_memory,vm.swappiness"
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:report --format json | jq -r '.\"--global\".\"vm.swappiness\"'"
assert_success
assert_output "20"
run /bin/bash -c "dokku scheduler-k3s:profiles:add edge-workers --role worker"
assert_success
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:set --replace --profile edge-workers vm.swappiness=60"
assert_success
# a profile scope inherits the global sysctls and overrides them on conflict
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:report --format json | jq -r '.\"edge-workers\" | to_entries | sort_by(.key) | map(\"\(.key)=\(.value)\") | join(\",\")'"
assert_success
assert_output "vm.overcommit_memory=1,vm.swappiness=60"
}
@test "(scheduler-k3s:node-sysctls:set) --replace rejects malformed pair lists without writing" {
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:node-sysctls:set --replace --global"
assert_failure
assert_output_contains "Must specify at least one key=value pair, use scheduler-k3s:node-sysctls:clear to remove all sysctls"
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:set --replace --global nodelimiter"
assert_failure
assert_output_contains "Invalid key=value pair: nodelimiter"
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:set --replace --global vm.swappiness=10 vm.swappiness=20"
assert_failure
assert_output_contains "Duplicate key specified: vm.swappiness"
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:report --format json | jq -r '.\"--global\" | keys | join(\",\")'"
assert_success
assert_output "vm.max_map_count"
}
@test "(scheduler-k3s:node-sysctls:clear) removes every sysctl for a scope" {
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:set --replace --global vm.max_map_count=262144 vm.swappiness=10"
assert_success
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:clear --global --profile edge-workers"
assert_failure
assert_output_contains "Only one of --global and --profile may be specified"
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:clear --profile missing-profile"
assert_failure
assert_output_contains "Node profile missing-profile not found"
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:clear --global"
assert_success
assert_output_contains "Removing vm.max_map_count stops dokku managing it"
assert_output_contains "Removing vm.swappiness stops dokku managing it"
run /bin/bash -c "dokku scheduler-k3s:node-sysctls:report --format json | jq -r '.\"--global\" | length'"
assert_success
assert_output "0"
}