-
Notifications
You must be signed in to change notification settings - Fork 459
/
healthz.go
37 lines (32 loc) · 915 Bytes
/
healthz.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package healthz
import (
"context"
"errors"
"net/http"
"sigs.k8s.io/controller-runtime/pkg/healthz"
)
// Manager is an interface for health managers.
type Manager interface {
// Name returns the name of the health manager.
Name() string
// Start starts the health manager.
Start(context.Context) error
// Stop stops the health manager.
Stop()
// Get returns the current health status.
Get() bool
// Set updates the current health status with the given value.
Set(bool)
}
// CheckerFunc returns a new healthz.Checker that will pass only if the given health manager returns true.
func CheckerFunc(h Manager) healthz.Checker {
return func(_ *http.Request) error {
if !h.Get() {
return errors.New("current health status is 'unhealthy'")
}
return nil
}
}