2022-05-17 14:40:51 +00:00
|
|
|
package dclient
|
2019-05-15 14:30:22 +00:00
|
|
|
|
|
|
|
import (
|
2019-06-11 21:35:26 +00:00
|
|
|
"strings"
|
|
|
|
|
2021-01-30 01:38:23 +00:00
|
|
|
"k8s.io/client-go/discovery"
|
2019-05-15 14:30:22 +00:00
|
|
|
)
|
|
|
|
|
2022-05-03 05:30:04 +00:00
|
|
|
func logDiscoveryErrors(err error, c serverPreferredResources) {
|
|
|
|
discoveryError := err.(*discovery.ErrGroupDiscoveryFailed)
|
|
|
|
for gv, e := range discoveryError.Groups {
|
|
|
|
if gv.Group == "custom.metrics.k8s.io" || gv.Group == "metrics.k8s.io" || gv.Group == "external.metrics.k8s.io" {
|
|
|
|
// These errors occur when Prometheus is installed as an external metrics server
|
|
|
|
// See: https://github.com/kyverno/kyverno/issues/1490
|
2022-05-03 08:24:30 +00:00
|
|
|
logger.V(3).Info("failed to retrieve metrics API group", "gv", gv)
|
2022-05-03 05:30:04 +00:00
|
|
|
continue
|
2019-06-11 21:35:26 +00:00
|
|
|
}
|
2022-05-03 08:24:30 +00:00
|
|
|
logger.Error(e, "failed to retrieve API group", "gv", gv)
|
2019-06-14 23:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 05:30:04 +00:00
|
|
|
func isMetricsServerUnavailable(kind string, err error) bool {
|
|
|
|
// error message is defined at:
|
|
|
|
// https://github.com/kubernetes/apimachinery/blob/2456ebdaba229616fab2161a615148884b46644b/pkg/api/errors/errors.go#L432
|
|
|
|
return strings.HasPrefix(kind, "metrics.k8s.io/") &&
|
|
|
|
strings.Contains(err.Error(), "the server is currently unable to handle the request")
|
2019-06-14 23:02:28 +00:00
|
|
|
}
|