-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlimits.go
More file actions
188 lines (145 loc) · 4.17 KB
/
limits.go
File metadata and controls
188 lines (145 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package parser
import (
docopt "github.com/docopt/docopt-go"
"github.com/drycc/workflow-cli/cmd"
)
// Limits routes limits commands to their specific function
func Limits(argv []string, cmdr cmd.Commander) error {
usage := `
Valid commands for limits:
limits:list list resource limits for an app
limits:set set resource limits for an app
limits:unset unset resource limits for an app
limits:specs unset resource limits for an app
limits:plans unset resource limits for an app
Use 'drycc help [command]' to learn more.
`
switch argv[0] {
case "limits:list":
return limitsList(argv, cmdr)
case "limits:set":
return limitSet(argv, cmdr)
case "limits:unset":
return limitUnset(argv, cmdr)
case "limits:specs":
return limitSpecs(argv, cmdr)
case "limits:plans":
return limitPlans(argv, cmdr)
default:
if printHelp(argv, usage) {
return nil
}
if argv[0] == "limits" {
argv[0] = "limits:list"
return limitsList(argv, cmdr)
}
PrintUsage(cmdr)
return nil
}
}
func limitsList(argv []string, cmdr cmd.Commander) error {
usage := `
Lists resource limits for an application.
Usage: drycc limits:list [options]
Options:
-a --app=<app>
the uniquely identifiable name of the application.
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
return cmdr.LimitsList(safeGetString(args, "--app"))
}
func limitSet(argv []string, cmdr cmd.Commander) error {
usage := `
Sets resource limits for an application.
A resource limit is a finite resource within a pod which we can apply
restrictions through Kubernetes.
Usage: drycc limits:set [options] <type>=<value>...
Arguments:
<type>
the process type as defined in your Procfile, such as 'web' or 'worker'.
<value>
The limit plan id to apply to the process type.
Options:
-a --app=<app>
the uniquely identifiable name for the application.
Use 'drycc help [command]' to learn more.
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
app := safeGetString(args, "--app")
limits := args["<type>=<value>"].([]string)
return cmdr.LimitsSet(app, limits)
}
func limitUnset(argv []string, cmdr cmd.Commander) error {
usage := `
Unsets resource limits for an application.
Usage: drycc limits:unset [options] <type>...
Arguments:
<type>
the process type as defined in your Procfile, such as 'web' or 'worker'.
Note that Dockerfile apps have a default 'cmd' process type.
Options:
-a --app=<app>
the uniquely identifiable name for the application.
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
app := safeGetString(args, "--app")
limits := args["<type>"].([]string)
return cmdr.LimitsUnset(app, limits)
}
func limitSpecs(argv []string, cmdr cmd.Commander) error {
usage := `
List all available limit specs.
Usage: drycc limits:specs [options]
Options:
-l --limit=<num>
the maximum number of results to display, defaults to config setting.
-k --keywords=<keywords>
search keywords separated by commas, matching must satisfy all of the specified.
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
results, err := responseLimit(safeGetString(args, "--limit"))
if err != nil {
return err
}
keywords := safeGetString(args, "--keywords")
return cmdr.LimitsSpecs(keywords, results)
}
func limitPlans(argv []string, cmdr cmd.Commander) error {
usage := `
List all available limit plans.
Usage: drycc limits:plans [options]
Options:
--cpu=<cpu>
query plans that meet the specified number of cpu cores.
--memory=<memory>
query plans that meet the specified memory capacity, unit GiB.
--spec-id=<spec-id>
query plans that meet the specified spec id, see [specs] subcommand.
-l --limit=<num>
the maximum number of results to display, defaults to config setting.
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
results, err := responseLimit(safeGetString(args, "--limit"))
if err != nil {
return err
}
specID := safeGetString(args, "--spec-id")
cpu := safeGetInt(args, "--cpu")
memory := safeGetInt(args, "--memory")
return cmdr.LimitsPlans(specID, cpu, memory, results)
}