From 04a6e30e457920631c4d64c2551698e4e60e1658 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 13 Mar 2019 20:53:38 -0400 Subject: [PATCH] refactor: drop `-defaults` command in favor of --global flag This makes usage a bit simpler, at the cost of interface complexity. --- docs/advanced-usage/resource-management.md | 96 ++++++++++++++++--- plugins/resource/Makefile | 2 +- plugins/resource/src/commands/commands.go | 6 +- .../subcommands/limit-clear/limit-clear.go | 3 +- .../limit-defaults/limit-defaults.go | 35 ------- .../resource/src/subcommands/limit/limit.go | 3 +- .../reserve-clear/reserve-clear.go | 3 +- .../reserve-defaults/reserve-defaults.go | 35 ------- .../src/subcommands/reserve/reserve.go | 3 +- plugins/resource/subcommands.go | 50 +++++----- 10 files changed, 114 insertions(+), 122 deletions(-) delete mode 100644 plugins/resource/src/subcommands/limit-defaults/limit-defaults.go delete mode 100644 plugins/resource/src/subcommands/reserve-defaults/reserve-defaults.go diff --git a/docs/advanced-usage/resource-management.md b/docs/advanced-usage/resource-management.md index a646a303c..7725cefec 100644 --- a/docs/advanced-usage/resource-management.md +++ b/docs/advanced-usage/resource-management.md @@ -3,10 +3,8 @@ > New as of 0.15.0 ``` -dokku resource:limit [--process-type ] [RESOURCE_OPTS...] -dokku resource:reserve [--process-type ] [RESOURCE_OPTS...] -dokku resource:limit-defaults [--process-type ] [RESOURCE_OPTS...] -dokku resource:reserve-defaults [--process-type ] [RESOURCE_OPTS...] +dokku resource:limit [--global] [--process-type ] [RESOURCE_OPTS...] +dokku resource:reserve [--global] [--process-type ] [RESOURCE_OPTS...] dokku resource:limit-clear [--process-type ] [] dokku resource:reserve-clear [--process-type ] [] dokku resource:report [] @@ -68,6 +66,8 @@ dokku resource:limit --cpu 100 --memory 100 --process-type worker node-js-app memory: 100 ``` +#### Displaying Resource Limits + Running the `resource:limits` command without any flags will display the currently configured app reservation. ```shell @@ -81,12 +81,12 @@ dokku resource:limits node-js-app network-egress: ``` -#### Default Resource Limits +#### Global Resource Limits -By default, Dokku does not limit any resources, though these can be specified at the server level via the `resource:limit-defaults` command. As with the `resource:limit` command, any and all resource request types can be specified. +By default, Dokku does not limit any resources, though these can be specified at the server level via the `--global` flag on the `resource:limit` command. ```shell -dokku resource:limit-defaults --memory 200 +dokku resource:limit --global --memory 200 ``` ``` @@ -94,10 +94,26 @@ dokku resource:limit-defaults --memory 200 memory: 200 ``` -Running the `resource:limit-defaults` command without any flags will display the currently configured default limits. +This may also be combined with the `--process-type` flag to set global limits on a process-type level: ```shell -dokku resource:limit-defaults +dokku resource:limit --global --memory 150 --process-type web node-js-app +``` + +``` +=====> Setting default resource limits (web) + memory: 150 +``` + +#### Displaying Global Resource Limits + +Running the `resource:limit` command with only the `--global` flag will display the currently configured default limits. + +```shell +dokku resource:limit --global +``` + +``` =====> resource limits default information cpu: memory: 200 @@ -107,7 +123,23 @@ dokku resource:limit-defaults network-egress: ``` -### Clearing Resource Limits +This may also be combined with the `--process-type` flag to see global limits on a process-type level: + +```shell +dokku resource:limit --global --process-type web +``` + +``` +=====> resource limits default information (web) + cpu: + memory-swap: + memory: 150 + network-egress: + network-ingress: + network: +``` + +#### Clearing Resource Limits In cases where the values are incorrect - or there is no desire to limit resources - resource limits may be cleared using the `resource:limit-clear` command. @@ -168,6 +200,8 @@ dokku resource:reserve --cpu 100 --memory 100 --process-type worker node-js-app memory: 100 ``` +#### Displaying Resource Reservations + Running the `resource:reserve` command without any flags will display the currently configured app reservation. ```shell @@ -181,12 +215,12 @@ dokku resource:reserve node-js-app network-egress: ``` -#### Default Resource Reservations +#### Global Resource Reservations -By default, Dokku does not reserve any resources, though these can be specified at the server level via the `resource:reserve-defaults` command. As with the `resource:reserve` command, any and all resource request types can be specified. +By default, Dokku does not reserve any resources, though these can be specified at the server level via the `--global` flag on the `resource:reserve` command. ```shell -dokku resource:reserve-defaults --memory 200 +dokku resource:reserve --global --memory 200 ``` ``` @@ -194,10 +228,26 @@ dokku resource:reserve-defaults --memory 200 memory: 200 ``` -Running the `resource:reserve-defaults` command without any flags will display the currently configured default reservation. +This may also be combined with the `--process-type` flag to set global reservations on a process-type level: ```shell -dokku resource:reserve-defaults +dokku resource:reserve --global --memory 150 --process-type web node-js-app +``` + +``` +=====> Setting default resource reservation (web) + memory: 150 +``` + +#### Displaying Global Resource Reservations + +Running the `resource:reserve` command with only the `--global` flag will display the currently configured default reservation. + +```shell +dokku resource:reserve --global +``` + +``` =====> resource reservation default information cpu: memory: 200 @@ -207,6 +257,22 @@ dokku resource:reserve-defaults network-egress: ``` +This may also be combined with the `--process-type` flag to see global reservations on a process-type level: + +```shell +dokku resource:reserve --global --process-type web +``` + +``` +=====> resource reservation default information (web) + cpu: + memory-swap: + memory: 150 + network-egress: + network-ingress: + network: +``` + #### Clearing Resource Reservations In cases where the values are incorrect - or there is no desire to reserve resources - resource reservations may be cleared using the `resource:reserve-clear` command. diff --git a/plugins/resource/Makefile b/plugins/resource/Makefile index 783f03f82..d2b724c7b 100644 --- a/plugins/resource/Makefile +++ b/plugins/resource/Makefile @@ -2,7 +2,7 @@ include ../../common.mk GO_ARGS ?= -a -SUBCOMMANDS = subcommands/limit subcommands/limit-clear subcommands/limit-defaults subcommands/reserve subcommands/reserve-clear subcommands/reserve-defaults +SUBCOMMANDS = subcommands/limit subcommands/limit-clear subcommands/reserve subcommands/reserve-clear TRIGGERS = triggers/install triggers/post-delete build-in-docker: clean docker run --rm \ diff --git a/plugins/resource/src/commands/commands.go b/plugins/resource/src/commands/commands.go index 0387b7735..5e13ed013 100644 --- a/plugins/resource/src/commands/commands.go +++ b/plugins/resource/src/commands/commands.go @@ -19,10 +19,8 @@ Manages resource settings for an app Additional commands:` helpContent = ` - resource:limit [--process-type process-type] [RESOURCE_OPTS...] , Limit resources for a given app/process-type combination - resource:reserve [--process-type process-type] [RESOURCE_OPTS...] , Reserve resources for a given app/process-type combination - resource:limit-defaults [--process-type process-type] [RESOURCE_OPTS...] , Limit resources for a given app/process-type combination - resource:reserve-defaults [--process-type process-type] [RESOURCE_OPTS...] , Reserve resources for a given app/process-type combination + resource:limit [--global] [--process-type process-type] [RESOURCE_OPTS...] , Limit resources for a given app/process-type combination + resource:reserve [--global] [--process-type process-type] [RESOURCE_OPTS...] , Reserve resources for a given app/process-type combination ` ) diff --git a/plugins/resource/src/subcommands/limit-clear/limit-clear.go b/plugins/resource/src/subcommands/limit-clear/limit-clear.go index b794dfc30..32000d6d6 100644 --- a/plugins/resource/src/subcommands/limit-clear/limit-clear.go +++ b/plugins/resource/src/subcommands/limit-clear/limit-clear.go @@ -11,9 +11,10 @@ import ( func main() { args := flag.NewFlagSet("resource:limit-clear", flag.ExitOnError) processType := args.String("process-type", "", "process-type: A process type to clear") + global := args.Bool("global", false, "global: Whether to clear global settings or not") args.Parse(os.Args[2:]) - err := resource.CommandLimitClear(args.Args(), *processType) + err := resource.CommandLimitClear(args.Args(), *processType, *global) if err != nil { common.LogFail(err.Error()) } diff --git a/plugins/resource/src/subcommands/limit-defaults/limit-defaults.go b/plugins/resource/src/subcommands/limit-defaults/limit-defaults.go deleted file mode 100644 index 9efaa8c0e..000000000 --- a/plugins/resource/src/subcommands/limit-defaults/limit-defaults.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "flag" - "os" - - "github.com/dokku/dokku/plugins/common" - "github.com/dokku/dokku/plugins/resource" -) - -func main() { - args := flag.NewFlagSet("resource:limit-defaults", flag.ExitOnError) - processType := args.String("process-type", "", "process-type: A process type to manage") - cpu := args.String("cpu", "", "cpu: The amount of cpu to limit processes by") - memory := args.String("memory", "", "memory: The amount of memory to limit processes by") - memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to limit processes by") - network := args.String("network", "", "network: The amount of network bandwidth to limit processes by") - networkIngress := args.String("network-ingress", "", "network-ingress: The amount of ingress network bandwidth to limit processes by") - networkEgress := args.String("network-egress", "", "network-egress: The amount of egress network bandwidth to limit processes by") - args.Parse(os.Args[2:]) - - resources := resource.Resource{ - CPU: *cpu, - Memory: *memory, - MemorySwap: *memorySwap, - Network: *network, - NetworkIngress: *networkIngress, - NetworkEgress: *networkEgress, - } - - err := resource.CommandLimitDefaults(args.Args(), *processType, resources) - if err != nil { - common.LogFail(err.Error()) - } -} diff --git a/plugins/resource/src/subcommands/limit/limit.go b/plugins/resource/src/subcommands/limit/limit.go index d45438e3a..024835acd 100644 --- a/plugins/resource/src/subcommands/limit/limit.go +++ b/plugins/resource/src/subcommands/limit/limit.go @@ -11,6 +11,7 @@ import ( func main() { args := flag.NewFlagSet("resource:limit", flag.ExitOnError) processType := args.String("process-type", "", "process-type: A process type to manage") + global := args.Bool("global", false, "global: Whether to clear global settings or not") cpu := args.String("cpu", "", "cpu: The amount of cpu to limit processes by") memory := args.String("memory", "", "memory: The amount of memory to limit processes by") memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to limit processes by") @@ -28,7 +29,7 @@ func main() { NetworkEgress: *networkEgress, } - err := resource.CommandLimit(args.Args(), *processType, resources) + err := resource.CommandLimit(args.Args(), *processType, resources, *global) if err != nil { common.LogFail(err.Error()) } diff --git a/plugins/resource/src/subcommands/reserve-clear/reserve-clear.go b/plugins/resource/src/subcommands/reserve-clear/reserve-clear.go index 4f882388d..c27a02bba 100644 --- a/plugins/resource/src/subcommands/reserve-clear/reserve-clear.go +++ b/plugins/resource/src/subcommands/reserve-clear/reserve-clear.go @@ -11,9 +11,10 @@ import ( func main() { args := flag.NewFlagSet("resource:reserve-clear", flag.ExitOnError) processType := args.String("process-type", "", "process-type: A process type to clear") + global := args.Bool("global", false, "global: Whether to clear global settings or not") args.Parse(os.Args[2:]) - err := resource.CommandReserveClear(args.Args(), *processType) + err := resource.CommandReserveClear(args.Args(), *processType, *global) if err != nil { common.LogFail(err.Error()) } diff --git a/plugins/resource/src/subcommands/reserve-defaults/reserve-defaults.go b/plugins/resource/src/subcommands/reserve-defaults/reserve-defaults.go deleted file mode 100644 index f7edb412a..000000000 --- a/plugins/resource/src/subcommands/reserve-defaults/reserve-defaults.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "flag" - "os" - - "github.com/dokku/dokku/plugins/common" - "github.com/dokku/dokku/plugins/resource" -) - -func main() { - args := flag.NewFlagSet("resource:reserve-defaults", flag.ExitOnError) - processType := args.String("process-type", "", "process-type: A process type to manage") - cpu := args.String("cpu", "", "cpu: The amount of cpu to reserve for processes") - memory := args.String("memory", "", "memory: The amount of memory to reserve for processes") - memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to reserve for processes") - network := args.String("network", "", "network: The amount of network bandwidth to reserve for processes") - networkIngress := args.String("network-ingress", "", "network-ingress: The amount of ingress network bandwidth to reserve for processes") - networkEgress := args.String("network-egress", "", "network-egress: The amount of egress network bandwidth to reserve for processes") - args.Parse(os.Args[2:]) - - resources := resource.Resource{ - CPU: *cpu, - Memory: *memory, - MemorySwap: *memorySwap, - Network: *network, - NetworkIngress: *networkIngress, - NetworkEgress: *networkEgress, - } - - err := resource.CommandReserveDefaults(args.Args(), *processType, resources) - if err != nil { - common.LogFail(err.Error()) - } -} diff --git a/plugins/resource/src/subcommands/reserve/reserve.go b/plugins/resource/src/subcommands/reserve/reserve.go index afeccb551..a62a34d55 100644 --- a/plugins/resource/src/subcommands/reserve/reserve.go +++ b/plugins/resource/src/subcommands/reserve/reserve.go @@ -11,6 +11,7 @@ import ( func main() { args := flag.NewFlagSet("resource:reserve", flag.ExitOnError) processType := args.String("process-type", "", "process-type: A process type to manage") + global := args.Bool("global", false, "global: Whether to clear global settings or not") cpu := args.String("cpu", "", "cpu: The amount of cpu to reserve for processes") memory := args.String("memory", "", "memory: The amount of memory to reserve for processes") memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to reserve for processes") @@ -28,7 +29,7 @@ func main() { NetworkEgress: *networkEgress, } - err := resource.CommandReserve(args.Args(), *processType, resources) + err := resource.CommandReserve(args.Args(), *processType, resources, *global) if err != nil { common.LogFail(err.Error()) } diff --git a/plugins/resource/subcommands.go b/plugins/resource/subcommands.go index 9ee9271f2..d93ebbd2d 100644 --- a/plugins/resource/subcommands.go +++ b/plugins/resource/subcommands.go @@ -7,55 +7,49 @@ import ( ) // CommandLimit implements resource:limit -func CommandLimit(args []string, processType string, r Resource) (err error) { - var appName string - appName, err = getAppName(args) - if err != nil { - return - } +func CommandLimit(args []string, processType string, r Resource, global bool) (err error) { + appName := "_all_" + if !global { + appName, err = getAppName(args) + if err != nil { + return + } - if err = common.VerifyAppName(appName); err != nil { - common.LogFail(err.Error()) + if err = common.VerifyAppName(appName); err != nil { + common.LogFail(err.Error()) + } } return setRequestType(appName, processType, r, "limit") } // CommandLimitClear implements resource:limit-clear -func CommandLimitClear(args []string, processType string) (err error) { +func CommandLimitClear(args []string, processType string, global bool) (err error) { return nil } -// CommandLimitDefaults implements resource:limit-defaults -func CommandLimitDefaults(args []string, processType string, r Resource) (err error) { - return setRequestType("_all_", "", r, "limit") -} - // CommandReserve implements resource:reserve -func CommandReserve(args []string, processType string, r Resource) (err error) { - var appName string - appName, err = getAppName(args) - if err != nil { - return - } +func CommandReserve(args []string, processType string, r Resource, global bool) (err error) { + appName := "_all_" + if !global { + appName, err = getAppName(args) + if err != nil { + return + } - if err = common.VerifyAppName(appName); err != nil { - common.LogFail(err.Error()) + if err = common.VerifyAppName(appName); err != nil { + common.LogFail(err.Error()) + } } return setRequestType(appName, processType, r, "reserve") } // CommandReserveClear implements resource:reserve-clear -func CommandReserveClear(args []string, processType string) (err error) { +func CommandReserveClear(args []string, processType string, global bool) (err error) { return nil } -// CommandReserveDefaults implements resource:reserve-defaults -func CommandReserveDefaults(args []string, processType string, r Resource) (err error) { - return setRequestType("_all_", "", r, "reserve") -} - func setRequestType(appName string, processType string, r Resource, requestType string) (err error) { if len(processType) == 0 { processType = "_all_"