|
| 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 | +} |
0 commit comments