Skip to content

Commit c07ce9a

Browse files
committed
chore(healthcheck): delete outdated healthcheck style
1 parent 236bf2a commit c07ce9a

9 files changed

Lines changed: 54 additions & 70 deletions

File tree

cmd/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func parseSSHKey(value string) (string, error) {
290290
}
291291
}
292292

293-
return "", fmt.Errorf("Could not parse SSH private key:\n %s", value)
293+
return "", fmt.Errorf("could not parse SSH private key:\n %s", value)
294294
}
295295

296296
func formatConfig(configVars map[string]interface{}) string {

cmd/healthchecks.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,11 @@ func getHealthcheckString(procType, probeType string, healthcheck *api.Healthche
3737
}
3838

3939
func getHealthchecksStrings(procType string, healthchecks *api.Healthchecks) []string {
40-
var livenessProbe, readinessProbe string
41-
if probe, found := (*healthchecks)["livenessProbe"]; found {
42-
livenessProbe = getHealthcheckString(procType, "liveness", probe)
43-
} else {
44-
livenessProbe = ""
45-
}
46-
if probe, found := (*healthchecks)["readinessProbe"]; found {
47-
readinessProbe = getHealthcheckString(procType, "readiness", probe)
48-
} else {
49-
readinessProbe = ""
40+
var probes []string
41+
for key := range *healthchecks {
42+
probes = append(probes, getHealthcheckString(procType, key, (*healthchecks)[key]))
5043
}
51-
return []string{livenessProbe, readinessProbe}
44+
return probes
5245
}
5346

5447
// HealthchecksList lists an app's healthchecks.

cmd/healthchecks_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestHealthchecksList(t *testing.T) {
3333
"tags": {},
3434
"registry": {},
3535
"healthcheck": {
36-
"web/cmd": {
36+
"web": {
3737
"livenessProbe": {
3838
"initialDelaySeconds": 50,
3939
"timeoutSeconds": 50,
@@ -52,16 +52,16 @@ func TestHealthchecksList(t *testing.T) {
5252
}`)
5353
})
5454

55-
err = cmdr.HealthchecksList("foo", "web/cmd")
55+
err = cmdr.HealthchecksList("foo", "web")
5656
assert.NoError(t, err)
5757

58-
assert.Equal(t, b.String(), `App: foo
59-
UUID: c039a380-6068-4511-b35a-535a73b86ef5
60-
Owner: bar
61-
Created: 2016-09-12T22:20:14Z
62-
Updated: 2016-09-12T22:20:14Z
58+
assert.Equal(t, b.String(), `App: foo
59+
UUID: c039a380-6068-4511-b35a-535a73b86ef5
60+
Owner: bar
61+
Created: 2016-09-12T22:20:14Z
62+
Updated: 2016-09-12T22:20:14Z
6363
Healthchecks:
64-
liveness web/cmd http-get headers=[] path=/ port=80 delay=50s timeout=50s period=10s #success=1 #failure=3
64+
livenessProbe web http-get headers=[] path=/ port=80 delay=50s timeout=50s period=10s #success=1 #failure=3
6565
`, "output")
6666
}
6767

@@ -121,7 +121,7 @@ func TestHealthchecksListAllHealthChecks(t *testing.T) {
121121
"tags": {},
122122
"registry": {},
123123
"healthcheck": {
124-
"web/cmd": {
124+
"web": {
125125
"livenessProbe": {
126126
"initialDelaySeconds": 50,
127127
"timeoutSeconds": 50,
@@ -134,14 +134,14 @@ func TestHealthchecksListAllHealthChecks(t *testing.T) {
134134
"successThreshold": 1
135135
}
136136
},
137-
"web": {
137+
"task": {
138138
"livenessProbe": {
139139
"initialDelaySeconds": 50,
140140
"timeoutSeconds": 50,
141141
"periodSeconds": 10,
142142
"failureThreshold": 3,
143143
"httpGet": {
144-
"port": 80,
144+
"port": 8000,
145145
"path": "/"
146146
},
147147
"successThreshold": 1
@@ -156,14 +156,14 @@ func TestHealthchecksListAllHealthChecks(t *testing.T) {
156156
err = cmdr.HealthchecksList("foo", "")
157157
assert.NoError(t, err)
158158

159-
assert.Equal(t, b.String(), `App: foo
160-
UUID: c039a380-6068-4511-b35a-535a73b86ef5
161-
Owner: bar
162-
Created: 2016-09-12T22:20:14Z
163-
Updated: 2016-09-12T22:20:14Z
159+
assert.Equal(t, b.String(), `App: foo
160+
UUID: c039a380-6068-4511-b35a-535a73b86ef5
161+
Owner: bar
162+
Created: 2016-09-12T22:20:14Z
163+
Updated: 2016-09-12T22:20:14Z
164164
Healthchecks:
165-
liveness web http-get headers=[] path=/ port=80 delay=50s timeout=50s period=10s #success=1 #failure=3
166-
liveness web/cmd http-get headers=[] path=/ port=80 delay=50s timeout=50s period=10s #success=1 #failure=3
165+
livenessProbe task http-get headers=[] path=/ port=8000 delay=50s timeout=50s period=10s #success=1 #failure=3
166+
livenessProbe web http-get headers=[] path=/ port=80 delay=50s timeout=50s period=10s #success=1 #failure=3
167167
`, "output")
168168
}
169169

@@ -189,7 +189,7 @@ func TestHealthchecksSet(t *testing.T) {
189189
"tags": {},
190190
"registry": {},
191191
"healthcheck": {
192-
"web/cmd": {
192+
"web": {
193193
"livenessProbe": {
194194
"initialDelaySeconds": 50,
195195
"timeoutSeconds": 50,
@@ -208,17 +208,17 @@ func TestHealthchecksSet(t *testing.T) {
208208
}`)
209209
})
210210

211-
err = cmdr.HealthchecksSet("foo", "liveness", "web/cmd", &api.Healthcheck{})
211+
err = cmdr.HealthchecksSet("foo", "livenessProbe", "web", &api.Healthcheck{})
212212
assert.NoError(t, err)
213-
assert.Equal(t, testutil.StripProgress(b.String()), `Applying liveness healthcheck... done
213+
assert.Equal(t, testutil.StripProgress(b.String()), `Applying livenessProbe healthcheck... done
214214
215-
App: foo
216-
UUID: c039a380-6068-4511-b35a-535a73b86ef5
217-
Owner: bar
218-
Created: 2016-09-12T22:20:14Z
219-
Updated: 2016-09-12T22:20:14Z
215+
App: foo
216+
UUID: c039a380-6068-4511-b35a-535a73b86ef5
217+
Owner: bar
218+
Created: 2016-09-12T22:20:14Z
219+
Updated: 2016-09-12T22:20:14Z
220220
Healthchecks:
221-
liveness web/cmd http-get headers=[] path=/ port=80 delay=50s timeout=50s period=10s #success=1 #failure=3
221+
livenessProbe web http-get headers=[] path=/ port=80 delay=50s timeout=50s period=10s #success=1 #failure=3
222222
`, "output")
223223
}
224224

@@ -249,7 +249,7 @@ func TestHealthchecksUnset(t *testing.T) {
249249
}`)
250250
})
251251

252-
err = cmdr.HealthchecksUnset("foo", "web/cmd", []string{"liveness"})
252+
err = cmdr.HealthchecksUnset("foo", "web", []string{"livenessProbe"})
253253
assert.NoError(t, err)
254254
assert.Equal(t, testutil.StripProgress(b.String()), `Removing healthchecks... done
255255

cmd/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var defaultLimit = -1
1919
func progress(wOut io.Writer) chan bool {
2020
frames := []string{"...", "o..", ".o.", "..o"}
2121
backspaces := strings.Repeat("\b", 3)
22-
tick := time.Tick(400 * time.Millisecond)
22+
tick := time.NewTicker(400 * time.Millisecond)
2323
quit := make(chan bool)
2424
go func() {
2525
for {
@@ -30,7 +30,7 @@ func progress(wOut io.Writer) chan bool {
3030
fmt.Fprint(wOut, backspaces)
3131
close(quit)
3232
return
33-
case <-tick:
33+
case <-tick.C:
3434
fmt.Fprint(wOut, backspaces)
3535
}
3636
}

cmd/volumes.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ func (d *DryccCmd) VolumesUnmount(appID string, name string, volumeVars []string
199199
for _, volumeVar := range volumeVars {
200200
valuesMap[volumeVar] = nil
201201
}
202-
if err != nil {
203-
return err
204-
}
205202

206203
d.Print("Unmounting volume... ")
207204

parser/autoscale_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ func TestAutoscale(t *testing.T) {
4646
expected: "",
4747
},
4848
{
49-
args: []string{"autoscale:set", "web/cmd", "--min=1", "--max=3", "--cpu-percent=50"},
49+
args: []string{"autoscale:set", "web", "--min=1", "--max=3", "--cpu-percent=50"},
5050
expected: "",
5151
},
5252
{
53-
args: []string{"autoscale:unset", "web/cmd"},
53+
args: []string{"autoscale:unset", "web"},
5454
expected: "",
5555
},
5656
{

parser/healthchecks.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// TODO: This is for supporting backward compatibility and should be removed
1515
// in future when next major version will be released.
1616
const (
17-
defaultProcType string = "web/cmd"
17+
defaultProcType string = "web"
1818
)
1919

2020
// Healthchecks routes ealthcheck commands to their specific function
@@ -110,7 +110,7 @@ Usage: drycc healthchecks:set <health-type> <probe-type> [options] [--] <args>..
110110
111111
Arguments:
112112
<health-type>
113-
the healthcheck type, such as 'liveness' or 'readiness'.
113+
the healthcheck type, such as 'livenessProbe' or 'readinessProbe'.
114114
<probe-type>
115115
the healthcheck probe type, such as 'httpGet', 'exec' or 'tcpSocket'.
116116
<args>
@@ -168,10 +168,6 @@ Options:
168168
return err
169169
}
170170

171-
// NOTE(bacongobbler): k8s healthchecks use the term "livenessProbe" and "readinessProbe", so let's
172-
// add that to the end of the healthcheck type so the controller sees the right probe type
173-
healthcheckType += "Probe"
174-
175171
probe := &api.Healthcheck{
176172
InitialDelaySeconds: initialDelayTimeout,
177173
TimeoutSeconds: timeoutSeconds,
@@ -208,7 +204,7 @@ Options:
208204
Port: port,
209205
}
210206
default:
211-
return fmt.Errorf("Invalid probe type. Must be one of: \"httpGet\", \"exec\"")
207+
return fmt.Errorf("invalid probe type. Must be one of: \"httpGet\", \"exec\"")
212208
}
213209

214210
return cmdr.HealthchecksSet(app, healthcheckType, procType, probe)
@@ -244,13 +240,10 @@ Options:
244240
procType = defaultProcType
245241
}
246242

247-
// NOTE(bacongobbler): k8s healthchecks use the term "livenessProbe" and "readinessProbe", so let's
248-
// add that to the end of the healthcheck type so the controller sees the right probe type
249243
for healthcheck := range healthchecks {
250244
if err := checkProbeType(healthchecks[healthcheck]); err != nil {
251245
return err
252246
}
253-
healthchecks[healthcheck] += "Probe"
254247
}
255248

256249
return cmdr.HealthchecksUnset(app, procType, healthchecks)
@@ -282,8 +275,9 @@ func parseHeader(header string) (*api.KVPair, error) {
282275
func checkProbeType(probe string) error {
283276
var found bool
284277
probeTypes := []string{
285-
"liveness",
286-
"readiness",
278+
"startupProbe",
279+
"livenessProbe",
280+
"readinessProbe",
287281
}
288282
for _, ptype := range probeTypes {
289283
if probe == ptype {

parser/limits.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Options:
9696
-c --cpu
9797
value apply to CPU.
9898
-m --memory
99-
value apply to memory.
99+
value apply to memory. [default: true]
100100
101101
Use 'drycc help [command]' to learn more.
102102
`
@@ -110,14 +110,22 @@ Use 'drycc help [command]' to learn more.
110110
app := safeGetString(args, "--app")
111111
cpuLimits := []string{}
112112
memoryLimits := []string{}
113+
cpuRegex, err := regexp.Compile(`\d+m?$`)
114+
if err != nil {
115+
return err
116+
}
117+
memoryRegex, err := regexp.Compile(`\d+[M|G]$`)
118+
if err != nil {
119+
return err
120+
}
113121
for _, value := range args["<type>=<value>"].([]string) {
114122
if args["--cpu"].(bool) {
115-
isCPU, _ := regexp.MatchString("\\d+m?$", value)
123+
isCPU := cpuRegex.MatchString(value)
116124
if isCPU {
117125
cpuLimits = append(cpuLimits, value)
118126
}
119127
}
120-
isMemory, _ := regexp.MatchString("\\d+[M|G]$", value)
128+
isMemory := memoryRegex.MatchString(value)
121129
if isMemory {
122130
memoryLimits = append(memoryLimits, value)
123131
}

parser/users.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ Arguments:
8383
}
8484
username := safeGetString(args, "<username>")
8585

86-
if err != nil {
87-
return err
88-
}
89-
9086
return cmdr.UsersEnable(username)
9187
}
9288

@@ -108,9 +104,5 @@ Arguments:
108104
}
109105
username := safeGetString(args, "<username>")
110106

111-
if err != nil {
112-
return err
113-
}
114-
115107
return cmdr.UsersDisable(username)
116108
}

0 commit comments

Comments
 (0)