mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
feat: add health checker for trivy when it's enabled
Closes #14055 Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
parent
d3601e5a92
commit
ff9b515630
@ -19,6 +19,8 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -77,6 +79,9 @@ func (h *HealthAPI) CheckHealth() {
|
||||
}
|
||||
components = append(components, componentStatus)
|
||||
}
|
||||
|
||||
sort.Slice(components, func(i, j int) bool { return components[i].Name < components[j].Name })
|
||||
|
||||
status := &overallHealthStatus{}
|
||||
status.Status = isHealthy.String()
|
||||
status.Components = components
|
||||
@ -269,6 +274,14 @@ func redisHealthChecker() health.Checker {
|
||||
return PeriodicHealthChecker(checker, period)
|
||||
}
|
||||
|
||||
func trivyHealthChecker() health.Checker {
|
||||
url := strings.TrimSuffix(config.TrivyAdapterURL(), "/") + "/probe/healthy"
|
||||
timeout := 60 * time.Second
|
||||
period := 10 * time.Second
|
||||
checker := HTTPStatusCodeHealthChecker(http.MethodGet, url, nil, timeout, http.StatusOK)
|
||||
return PeriodicHealthChecker(checker, period)
|
||||
}
|
||||
|
||||
func registerHealthCheckers() {
|
||||
HealthCheckerRegistry["core"] = coreHealthChecker()
|
||||
HealthCheckerRegistry["portal"] = portalHealthChecker()
|
||||
@ -283,6 +296,9 @@ func registerHealthCheckers() {
|
||||
if config.WithNotary() {
|
||||
HealthCheckerRegistry["notary"] = notaryHealthChecker()
|
||||
}
|
||||
if config.WithTrivy() {
|
||||
HealthCheckerRegistry["trivy"] = trivyHealthChecker()
|
||||
}
|
||||
}
|
||||
|
||||
func getRegistryURL() string {
|
||||
|
Loading…
Reference in New Issue
Block a user