11package cmd
22
33import (
4+ "errors"
45 "fmt"
6+ "io"
7+ "os"
58
69 "github.com/deis/controller-sdk-go/api"
710 "github.com/deis/controller-sdk-go/config"
811)
912
13+ func printHealthCheck (out io.Writer , healthcheck api.Healthchecks ) {
14+ fmt .Fprintln (out , "--- Liveness" )
15+ if livenessProbe , found := healthcheck ["livenessProbe" ]; found {
16+ fmt .Fprintln (out , livenessProbe )
17+ } else {
18+ fmt .Fprintln (out , "No liveness probe configured." )
19+ }
20+
21+ fmt .Fprintln (out , "\n --- Readiness" )
22+ if readinessProbe , found := healthcheck ["readinessProbe" ]; found {
23+ fmt .Fprintln (out , readinessProbe )
24+ } else {
25+ fmt .Fprintln (out , "No readiness probe configured." )
26+ }
27+ }
28+
1029// HealthchecksList lists an app's healthchecks.
11- func HealthchecksList (appID string ) error {
30+ func HealthchecksList (appID , procType string ) error {
1231 s , appID , err := load (appID )
1332
1433 if err != nil {
@@ -22,25 +41,25 @@ func HealthchecksList(appID string) error {
2241 }
2342
2443 fmt .Printf ("=== %s Healthchecks\n \n " , appID )
25-
26- fmt .Println ("--- Liveness" )
27- if livenessProbe , found := config .Healthcheck ["livenessProbe" ]; found {
28- fmt .Println (livenessProbe )
44+ if procType == "" {
45+ for proc , healthcheck := range config .Healthcheck {
46+ fmt .Println (proc + ":" )
47+ printHealthCheck (os .Stdout , * healthcheck )
48+ }
2949 } else {
30- fmt .Println ("No liveness probe configured." )
50+ fmt .Println (procType + ":" )
51+ if healthcheck , found := config .Healthcheck [procType ]; found {
52+ printHealthCheck (os .Stdout , * healthcheck )
53+ } else {
54+ return errors .New (appID + " doesn't have proctype" + procType )
55+ }
3156 }
3257
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- }
3958 return nil
4059}
4160
4261// HealthchecksSet sets an app's healthchecks.
43- func HealthchecksSet (appID , healthcheckType string , probe * api.Healthcheck ) error {
62+ func HealthchecksSet (appID , healthcheckType , procType string , probe * api.Healthcheck ) error {
4463 s , appID , err := load (appID )
4564
4665 if err != nil {
@@ -50,10 +69,11 @@ func HealthchecksSet(appID, healthcheckType string, probe *api.Healthcheck) erro
5069 fmt .Printf ("Applying %s healthcheck... " , healthcheckType )
5170
5271 quit := progress ()
53- configObj := api.Config {}
54- configObj .Healthcheck = make (map [string ]* api.Healthcheck )
5572
56- configObj .Healthcheck [healthcheckType ] = probe
73+ healthcheckMap := make (api.Healthchecks )
74+ healthcheckMap [healthcheckType ] = probe
75+ configObj := api.Config {Healthcheck : make (map [string ]* api.Healthchecks )}
76+ configObj .Healthcheck [procType ] = & healthcheckMap
5777
5878 _ , err = config .Set (s .Client , appID , configObj )
5979
@@ -66,11 +86,11 @@ func HealthchecksSet(appID, healthcheckType string, probe *api.Healthcheck) erro
6686
6787 fmt .Print ("done\n \n " )
6888
69- return HealthchecksList (appID )
89+ return HealthchecksList (appID , procType )
7090}
7191
7292// HealthchecksUnset removes an app's healthchecks.
73- func HealthchecksUnset (appID string , healthchecks []string ) error {
93+ func HealthchecksUnset (appID , procType string , healthchecks []string ) error {
7494 s , appID , err := load (appID )
7595
7696 if err != nil {
@@ -83,13 +103,15 @@ func HealthchecksUnset(appID string, healthchecks []string) error {
83103
84104 configObj := api.Config {}
85105
86- healthcheckMap := make (map [string ]* api.Healthcheck )
106+ healthchecksMap := make (map [string ]* api.Healthchecks )
107+ healthcheckMap := make (api.Healthchecks )
87108
88109 for _ , healthcheck := range healthchecks {
89110 healthcheckMap [healthcheck ] = nil
90111 }
112+ healthchecksMap [procType ] = & healthcheckMap
91113
92- configObj .Healthcheck = healthcheckMap
114+ configObj .Healthcheck = healthchecksMap
93115
94116 _ , err = config .Set (s .Client , appID , configObj )
95117
@@ -102,5 +124,5 @@ func HealthchecksUnset(appID string, healthchecks []string) error {
102124
103125 fmt .Print ("done\n \n " )
104126
105- return HealthchecksList (appID )
127+ return HealthchecksList (appID , procType )
106128}
0 commit comments