Skip to content

Commit 9f6dcf3

Browse files
deads2ksoltysh
authored andcommitted
UPSTREAM: <carry>: annotate audit events for requests during unready phase and graceful termination phase
openshift-rebase(v1.24):source=2f57c5b68bd
1 parent d86823d commit 9f6dcf3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package server
1818

1919
import (
20+
"fmt"
2021
"net"
2122
"net/http"
2223
"strings"
@@ -26,6 +27,7 @@ import (
2627
"go.uber.org/atomic"
2728

2829
corev1 "k8s.io/api/core/v1"
30+
"k8s.io/apiserver/pkg/audit"
2931
"k8s.io/klog/v2"
3032
netutils "k8s.io/utils/net"
3133
)
@@ -80,8 +82,10 @@ func WithLateConnectionFilter(handler http.Handler) http.Handler {
8082
if late {
8183
if pth := "/" + strings.TrimLeft(r.URL.Path, "/"); pth != "/readyz" && pth != "/healthz" && pth != "/livez" {
8284
if isLocal(r) {
85+
audit.AddAuditAnnotation(r.Context(), "openshift.io/during-graceful", fmt.Sprintf("loopback=true,%v,readyz=false", r.URL.Host))
8386
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())
8487
} else {
88+
audit.AddAuditAnnotation(r.Context(), "openshift.io/during-graceful", fmt.Sprintf("loopback=false,%v,readyz=false", r.URL.Host))
8589
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())
8690

8791
// create only one event to avoid event spam.
@@ -118,9 +122,11 @@ func WithNonReadyRequestLogging(handler http.Handler, hasBeenReadySignal lifecyc
118122
if pth := "/" + strings.TrimLeft(r.URL.Path, "/"); pth != "/readyz" && pth != "/healthz" && pth != "/livez" {
119123
if isLocal(r) {
120124
if !isKubeApiserverLoopBack(r) {
125+
audit.AddAuditAnnotation(r.Context(), "openshift.io/unready", fmt.Sprintf("loopback=true,%v,readyz=false", r.URL.Host))
121126
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())
122127
}
123128
} else {
129+
audit.AddAuditAnnotation(r.Context(), "openshift.io/unready", fmt.Sprintf("loopback=false,%v,readyz=false", r.URL.Host))
124130
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())
125131

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

0 commit comments

Comments
 (0)