diff --git a/docs/advanced-usage/resource-management.md b/docs/advanced-usage/resource-management.md index 5c9d3bd6a..19dfa721f 100644 --- a/docs/advanced-usage/resource-management.md +++ b/docs/advanced-usage/resource-management.md @@ -71,6 +71,17 @@ dokku resource:limit --cpu 100 --memory 100 --process-type worker node-js-app memory: 100 ``` +A resource value can be individually cleared by setting the value to the special value `clear`. + +```shell +dokku resource:limit --cpu clear node-js-app +``` + +``` +=====> Setting resource limits for node-js-app + cpu: cleared +``` + #### Displaying Resource Limits Running the `resource:limit` command without any flags will display the currently configured default app limits. @@ -169,6 +180,17 @@ dokku resource:reserve --cpu 100 --memory 100 --process-type worker node-js-app memory: 100 ``` +A resource value can be individually cleared by setting the value to the special value `clear`. + +```shell +dokku resource:reserve --cpu clear node-js-app +``` + +``` +=====> Setting resource reservation for node-js-app + cpu: cleared +``` + #### Displaying Resource Reservations Running the `resource:reserve` command without any flags will display the currently configured default app reservations. diff --git a/plugins/resource/functions.go b/plugins/resource/functions.go index 72f9dcc56..5d03442db 100644 --- a/plugins/resource/functions.go +++ b/plugins/resource/functions.go @@ -86,10 +86,17 @@ func setResourceType(appName string, processType string, r Resource, resourceTyp continue } - common.LogVerbose(fmt.Sprintf("%v: %v", key, value)) property := propertyKey(processType, resourceType, key) - err := common.PropertyWrite("resource", appName, property, value) - if err != nil { + if value == "clear" { + common.LogVerbose(fmt.Sprintf("%v: cleared", key)) + if err := common.PropertyDelete("resource", appName, property); err != nil { + return err + } + continue + } + + common.LogVerbose(fmt.Sprintf("%v: %v", key, value)) + if err := common.PropertyWrite("resource", appName, property, value); err != nil { return err } } diff --git a/tests/unit/resource_1.bats b/tests/unit/resource_1.bats index 0a828e729..54919bb02 100644 --- a/tests/unit/resource_1.bats +++ b/tests/unit/resource_1.bats @@ -111,3 +111,26 @@ teardown() { echo "status: $status" assert_success } + +@test "(resource) resource:limit clear single" { + run /bin/bash -c "dokku resource:limit --memory 512MB $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku resource:report --resource-_default_.limit.memory $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "512MB" + + run /bin/bash -c "dokku resource:limit --memory clear $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku resource:report --resource-_default_.limit.memory $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_failure +} diff --git a/tests/unit/resource_2.bats b/tests/unit/resource_2.bats index ab5ce4141..2707bdd8a 100644 --- a/tests/unit/resource_2.bats +++ b/tests/unit/resource_2.bats @@ -102,3 +102,26 @@ teardown() { echo "status: $status" assert_success } + +@test "(resource) resource:reserve clear single" { + run /bin/bash -c "dokku resource:reserve --memory 512MB $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku resource:report --resource-_default_.reserve.memory $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "512MB" + + run /bin/bash -c "dokku resource:reserve --memory clear $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku resource:report --resource-_default_.reserve.memory $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_failure +}