Merge pull request #4372 from dokku/clear-individual-resource

Add ability to clear an individual resource
This commit is contained in:
Jose Diaz-Gonzalez
2021-02-07 20:57:33 -05:00
committed by GitHub
4 changed files with 78 additions and 3 deletions

View File

@@ -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.

View File

@@ -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
}
}

View File

@@ -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
}

View File

@@ -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
}