Skip to content

Commit 712b94e

Browse files
tkashembertinatto
authored andcommitted
UPSTREAM: <carry>: annotate audit events for requests during unready phase and graceful termination phase
This reverts commit 85f0f2c.
1 parent 45eff96 commit 712b94e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

staging/src/k8s.io/apiserver/pkg/server/patch_genericapiserver.go

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
corev1 "k8s.io/api/core/v1"
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/types"
35+
"k8s.io/apiserver/pkg/audit"
3536
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
3637
"k8s.io/klog/v2"
3738
netutils "k8s.io/utils/net"
@@ -196,8 +197,10 @@ func WithLateConnectionFilter(handler http.Handler) http.Handler {
196197
if late {
197198
if pth := "/" + strings.TrimLeft(r.URL.Path, "/"); pth != "/readyz" && pth != "/healthz" && pth != "/livez" {
198199
if isLocal(r) {
200+
audit.AddAuditAnnotation(r.Context(), "openshift.io/during-graceful", fmt.Sprintf("loopback=true,%v,readyz=false", r.URL.Host))
199201
klog.V(4).Infof("Loopback request to %q (user agent %q) through connection created very late in the graceful termination process (more than 80%% has passed). This client probably does not watch /readyz and might get failures when termination is over.", r.URL.Path, r.UserAgent())
200202
} else {
203+
audit.AddAuditAnnotation(r.Context(), "openshift.io/during-graceful", fmt.Sprintf("loopback=false,%v,readyz=false", r.URL.Host))
201204
klog.Warningf("Request to %q (source IP %s, user agent %q) through a connection created very late in the graceful termination process (more than 80%% has passed), possibly a sign for a broken load balancer setup.", r.URL.Path, r.RemoteAddr, r.UserAgent())
202205

203206
// create only one event to avoid event spam.
@@ -234,9 +237,11 @@ func WithNonReadyRequestLogging(handler http.Handler, hasBeenReadySignal lifecyc
234237
if pth := "/" + strings.TrimLeft(r.URL.Path, "/"); pth != "/readyz" && pth != "/healthz" && pth != "/livez" {
235238
if isLocal(r) {
236239
if !isKubeApiserverLoopBack(r) {
240+
audit.AddAuditAnnotation(r.Context(), "openshift.io/unready", fmt.Sprintf("loopback=true,%v,readyz=false", r.URL.Host))
237241
klog.V(2).Infof("Loopback request to %q (user agent %q) before server is ready. This client probably does not watch /readyz and might get inconsistent answers.", r.URL.Path, r.UserAgent())
238242
}
239243
} else {
244+
audit.AddAuditAnnotation(r.Context(), "openshift.io/unready", fmt.Sprintf("loopback=false,%v,readyz=false", r.URL.Host))
240245
klog.Warningf("Request to %q (source IP %s, user agent %q) before server is ready, possibly a sign for a broken load balancer setup.", r.URL.Path, r.RemoteAddr, r.UserAgent())
241246

242247
// create only one event to avoid event spam.

0 commit comments

Comments
 (0)