1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/pkg/clients/dclient/utils.go
Charles-Edouard Brétéché 5160b63154
feat: use kind selectors (#6514)
* fix: compile regex globally

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* feat: use kind selectors

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* clean

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* cache

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* kuttl

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* kuttl

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* webhooks rules

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* kuttl

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-03-10 13:24:55 +00:00

35 lines
1.6 KiB
Go

package dclient
import (
"strings"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
)
func logDiscoveryErrors(err error) {
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
logger.V(3).Info("failed to retrieve metrics API group", "gv", gv)
continue
}
logger.Error(e, "failed to retrieve API group", "gv", gv)
}
}
// isServerCurrentlyUnableToHandleRequest returns true if the error is related to the discovery not able to handle the request
// this can happen with aggregated services when the api server can't get a `TokenReview` and is not able to send requests to
// the underlying service, this is typically due to kyverno blocking `TokenReview` admission requests.
func isServerCurrentlyUnableToHandleRequest(err error) bool {
return err != nil && strings.Contains(err.Error(), "the server is currently unable to handle the request")
}
func isMetricsServerUnavailable(gv schema.GroupVersion, err error) bool {
// error message is defined at:
// https://github.com/kubernetes/apimachinery/blob/2456ebdaba229616fab2161a615148884b46644b/pkg/api/errors/errors.go#L432
return (gv.Group == "metrics.k8s.io" || gv.Group == "custom.metrics.k8s.io" || gv.Group == "external.metrics.k8s.io") &&
isServerCurrentlyUnableToHandleRequest(err)
}