Skip to content

Commit 322d3b0

Browse files
author
Matthew Fisher
committed
feat(deis.go): add deis healthchecks
1 parent 09bc773 commit 322d3b0

7 files changed

Lines changed: 406 additions & 3 deletions

File tree

cmd/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ func ConfigSet(appID string, configVars []string) error {
9090
configMap["SSH_KEY"] = base64.StdEncoding.EncodeToString([]byte(sshKey))
9191
}
9292

93+
// NOTE(bacongobbler): check if the user is using the old way to set healthchecks. If so,
94+
// send them a deprecation notice.
95+
for key, _ := range configMap {
96+
if strings.Contains(key, "HEALTHCHECK_") {
97+
fmt.Println(`Hey there! We've noticed that you're using 'deis config:set HEALTHCHECK_URL'
98+
to set up healthchecks. This functionality has been deprecated. In the future, please use
99+
'deis healthchecks' to set up application health checks. Thanks!`)
100+
}
101+
}
102+
93103
fmt.Print("Creating config... ")
94104

95105
quit := progress()

cmd/healthchecks.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/deis/controller-sdk-go/api"
7+
"github.com/deis/controller-sdk-go/config"
8+
)
9+
10+
// HealthchecksList lists an app's healthchecks.
11+
func HealthchecksList(appID string) error {
12+
c, appID, err := load(appID)
13+
14+
if err != nil {
15+
return err
16+
}
17+
18+
config, err := config.List(c, appID)
19+
20+
if err != nil {
21+
return err
22+
}
23+
24+
fmt.Printf("=== %s Healthchecks\n\n", appID)
25+
26+
fmt.Println("--- Liveness")
27+
if livenessProbe, found := config.Healthcheck["livenessProbe"]; found {
28+
fmt.Println(livenessProbe)
29+
} else {
30+
fmt.Println("No liveness probe configured.")
31+
}
32+
33+
fmt.Println("\n--- Readiness")
34+
if readinessProbe, found := config.Healthcheck["readinessProbe"]; found {
35+
fmt.Println(readinessProbe)
36+
} else {
37+
fmt.Println("No readiness probe configured.")
38+
}
39+
return nil
40+
}
41+
42+
// HealthchecksSet sets an app's healthchecks.
43+
func HealthchecksSet(appID, healthcheckType string, probe *api.Healthcheck) error {
44+
c, appID, err := load(appID)
45+
46+
if err != nil {
47+
return err
48+
}
49+
50+
fmt.Printf("Applying %s healthcheck... ", healthcheckType)
51+
52+
quit := progress()
53+
configObj := api.Config{}
54+
configObj.Healthcheck = make(map[string]*api.Healthcheck)
55+
56+
configObj.Healthcheck[healthcheckType] = probe
57+
58+
_, err = config.Set(c, appID, configObj)
59+
60+
quit <- true
61+
<-quit
62+
63+
if err != nil {
64+
return err
65+
}
66+
67+
fmt.Print("done\n\n")
68+
69+
return HealthchecksList(appID)
70+
}
71+
72+
// HealthchecksUnset removes an app's healthchecks.
73+
func HealthchecksUnset(appID string, healthchecks []string) error {
74+
c, appID, err := load(appID)
75+
76+
if err != nil {
77+
return err
78+
}
79+
80+
fmt.Print("Removing healthchecks... ")
81+
82+
quit := progress()
83+
84+
configObj := api.Config{}
85+
86+
healthcheckMap := make(map[string]*api.Healthcheck)
87+
88+
for _, healthcheck := range healthchecks {
89+
healthcheckMap[healthcheck] = nil
90+
}
91+
92+
configObj.Healthcheck = healthcheckMap
93+
94+
_, err = config.Set(c, appID, configObj)
95+
96+
quit <- true
97+
<-quit
98+
99+
if err != nil {
100+
return err
101+
}
102+
103+
fmt.Print("done\n\n")
104+
105+
return HealthchecksList(appID)
106+
}

deis.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Subcommands, use 'deis help [subcommand]' to learn more::
4343
config manage environment variables that define app config
4444
domains manage and assign domain names to your applications
4545
git manage git for applications
46+
healthchecks manage healthchecks for applications
4647
keys manage ssh keys used for 'git push' deployments
4748
limits manage resource limits for your application
4849
perms manage permissions for applications
@@ -98,6 +99,8 @@ Use 'git push deis master' to deploy to an application.
9899
err = parser.Domains(argv)
99100
case "git":
100101
err = parser.Git(argv)
102+
case "healthchecks":
103+
err = parser.Healthchecks(argv)
101104
case "help":
102105
fmt.Print(usage)
103106
return 0

glide.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)