Implement a stub of the new endpoint

Signed-off-by: Mikolaj Pawlikowski <mikolaj@pawlikowski.pl>
This commit is contained in:
Mikolaj Pawlikowski
2021-03-12 12:24:42 +00:00
parent bd04fcbc58
commit 3edecea467
2 changed files with 25 additions and 0 deletions

View File

@@ -54,6 +54,13 @@ func CheckNeighboursNeighbours(ctx context.Context) *models.CheckAllResults {
return CheckAllPods(ctx, SelectPods())
}
// CheckCluster does a CheckNeighboursNeighbours and analyses results to produce a binary OK or not OK
func CheckCluster(ctx context.Context) (bool, *models.ClusterHealthResults) {
response := models.ClusterHealthResults{}
return true, &response
}
type PingAllPodsResult struct {
podName string
podResult models.PodResult

View File

@@ -94,6 +94,24 @@ func configureAPI(api *operations.GoldpingerAPI) http.Handler {
return operations.NewCheckAllPodsOK().WithPayload(goldpinger.CheckNeighboursNeighbours(ctx))
})
api.ClusterHealthHandler = operations.ClusterHealthHandlerFunc(
func(params operations.ClusterHealthParams) middleware.Responder {
goldpinger.CountCall("received", "cluster_health")
ctx, cancel := context.WithTimeout(
params.HTTPRequest.Context(),
time.Duration(goldpinger.GoldpingerConfig.CheckAllTimeoutMs)*time.Millisecond,
)
defer cancel()
ok, payload := goldpinger.CheckCluster(ctx)
if ok {
return operations.NewClusterHealthOK().WithPayload(payload)
} else {
return operations.NewClusterHealthServiceUnavailable().WithPayload(payload)
}
})
api.HealthzHandler = operations.HealthzHandlerFunc(
func(params operations.HealthzParams) middleware.Responder {
goldpinger.CountCall("received", "healthz")