Update go dependencies
This commit is contained in:
parent
432f534383
commit
f4a4daed84
1299 changed files with 71186 additions and 91183 deletions
56
vendor/k8s.io/apiserver/pkg/server/healthz/healthz.go
generated
vendored
56
vendor/k8s.io/apiserver/pkg/server/healthz/healthz.go
generated
vendored
|
|
@ -25,8 +25,9 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
)
|
||||
|
||||
|
|
@ -76,7 +77,7 @@ func (l *log) Check(_ *http.Request) error {
|
|||
l.startOnce.Do(func() {
|
||||
l.lastVerified.Store(time.Now())
|
||||
go wait.Forever(func() {
|
||||
glog.Flush()
|
||||
klog.Flush()
|
||||
l.lastVerified.Store(time.Now())
|
||||
}, time.Minute)
|
||||
})
|
||||
|
|
@ -108,11 +109,11 @@ func InstallHandler(mux mux, checks ...HealthzChecker) {
|
|||
// result in a panic.
|
||||
func InstallPathHandler(mux mux, path string, checks ...HealthzChecker) {
|
||||
if len(checks) == 0 {
|
||||
glog.V(5).Info("No default health checks specified. Installing the ping handler.")
|
||||
klog.V(5).Info("No default health checks specified. Installing the ping handler.")
|
||||
checks = []HealthzChecker{PingHealthz}
|
||||
}
|
||||
|
||||
glog.V(5).Info("Installing healthz checkers:", strings.Join(checkerNames(checks...), ", "))
|
||||
klog.V(5).Info("Installing healthz checkers:", formatQuoted(checkerNames(checks...)...))
|
||||
|
||||
mux.Handle(path, handleRootHealthz(checks...))
|
||||
for _, check := range checks {
|
||||
|
|
@ -141,22 +142,43 @@ func (c *healthzCheck) Check(r *http.Request) error {
|
|||
return c.check(r)
|
||||
}
|
||||
|
||||
// getExcludedChecks extracts the health check names to be excluded from the query param
|
||||
func getExcludedChecks(r *http.Request) sets.String {
|
||||
checks, found := r.URL.Query()["exclude"]
|
||||
if found {
|
||||
return sets.NewString(checks...)
|
||||
}
|
||||
return sets.NewString()
|
||||
}
|
||||
|
||||
// handleRootHealthz returns an http.HandlerFunc that serves the provided checks.
|
||||
func handleRootHealthz(checks ...HealthzChecker) http.HandlerFunc {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
failed := false
|
||||
excluded := getExcludedChecks(r)
|
||||
var verboseOut bytes.Buffer
|
||||
for _, check := range checks {
|
||||
// no-op the check if we've specified we want to exclude the check
|
||||
if excluded.Has(check.Name()) {
|
||||
excluded.Delete(check.Name())
|
||||
fmt.Fprintf(&verboseOut, "[+]%v excluded: ok\n", check.Name())
|
||||
continue
|
||||
}
|
||||
if err := check.Check(r); err != nil {
|
||||
// don't include the error since this endpoint is public. If someone wants more detail
|
||||
// they should have explicit permission to the detailed checks.
|
||||
glog.V(6).Infof("healthz check %v failed: %v", check.Name(), err)
|
||||
klog.V(6).Infof("healthz check %v failed: %v", check.Name(), err)
|
||||
fmt.Fprintf(&verboseOut, "[-]%v failed: reason withheld\n", check.Name())
|
||||
failed = true
|
||||
} else {
|
||||
fmt.Fprintf(&verboseOut, "[+]%v ok\n", check.Name())
|
||||
}
|
||||
}
|
||||
if excluded.Len() > 0 {
|
||||
fmt.Fprintf(&verboseOut, "warn: some health checks cannot be excluded: no matches for %v\n", formatQuoted(excluded.List()...))
|
||||
klog.Warningf("cannot exclude some health checks, no health checks are installed matching %v",
|
||||
formatQuoted(excluded.List()...))
|
||||
}
|
||||
// always be verbose on failure
|
||||
if failed {
|
||||
http.Error(w, fmt.Sprintf("%vhealthz check failed", verboseOut.String()), http.StatusInternalServerError)
|
||||
|
|
@ -187,14 +209,20 @@ func adaptCheckToHandler(c func(r *http.Request) error) http.HandlerFunc {
|
|||
|
||||
// checkerNames returns the names of the checks in the same order as passed in.
|
||||
func checkerNames(checks ...HealthzChecker) []string {
|
||||
if len(checks) > 0 {
|
||||
// accumulate the names of checks for printing them out.
|
||||
checkerNames := make([]string, 0, len(checks))
|
||||
for _, check := range checks {
|
||||
// quote the Name so we can disambiguate
|
||||
checkerNames = append(checkerNames, fmt.Sprintf("%q", check.Name()))
|
||||
}
|
||||
return checkerNames
|
||||
// accumulate the names of checks for printing them out.
|
||||
checkerNames := make([]string, 0, len(checks))
|
||||
for _, check := range checks {
|
||||
checkerNames = append(checkerNames, check.Name())
|
||||
}
|
||||
return nil
|
||||
return checkerNames
|
||||
}
|
||||
|
||||
// formatQuoted returns a formatted string of the health check names,
|
||||
// preserving the order passed in.
|
||||
func formatQuoted(names ...string) string {
|
||||
quoted := make([]string, 0, len(names))
|
||||
for _, name := range names {
|
||||
quoted = append(quoted, fmt.Sprintf("%q", name))
|
||||
}
|
||||
return strings.Join(quoted, ",")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue