Avoid log spam in servers without auditing enabled

This commit is contained in:
Jordan Liggitt 2022-03-31 01:50:24 -04:00
parent b9792a9dae
commit f23b9a5002

View File

@ -18,7 +18,6 @@ package audit
import ( import (
"context" "context"
"fmt"
"sync" "sync"
auditinternal "k8s.io/apiserver/pkg/apis/audit" auditinternal "k8s.io/apiserver/pkg/apis/audit"
@ -73,7 +72,7 @@ func WithAuditAnnotations(parent context.Context) context.Context {
func AddAuditAnnotation(ctx context.Context, key, value string) { func AddAuditAnnotation(ctx context.Context, key, value string) {
mutex, ok := auditAnnotationsMutex(ctx) mutex, ok := auditAnnotationsMutex(ctx)
if !ok { if !ok {
klog.ErrorS(nil, "Attempted to add audit annotations from unsupported request chain", "annotation", fmt.Sprintf("%s=%s", key, value)) // auditing is not enabled
return return
} }
@ -95,7 +94,7 @@ func AddAuditAnnotation(ctx context.Context, key, value string) {
func AddAuditAnnotations(ctx context.Context, keysAndValues ...string) { func AddAuditAnnotations(ctx context.Context, keysAndValues ...string) {
mutex, ok := auditAnnotationsMutex(ctx) mutex, ok := auditAnnotationsMutex(ctx)
if !ok { if !ok {
klog.ErrorS(nil, "Attempted to add audit annotations from unsupported request chain", "annotations", keysAndValues) // auditing is not enabled
return return
} }
@ -121,7 +120,7 @@ func AddAuditAnnotations(ctx context.Context, keysAndValues ...string) {
func AddAuditAnnotationsMap(ctx context.Context, annotations map[string]string) { func AddAuditAnnotationsMap(ctx context.Context, annotations map[string]string) {
mutex, ok := auditAnnotationsMutex(ctx) mutex, ok := auditAnnotationsMutex(ctx)
if !ok { if !ok {
klog.ErrorS(nil, "Attempted to add audit annotations from unsupported request chain", "annotations", annotations) // auditing is not enabled
return return
} }
@ -154,7 +153,7 @@ func addAuditAnnotationLocked(ae *auditinternal.Event, annotations *[]annotation
func addAuditAnnotationsFrom(ctx context.Context, ev *auditinternal.Event) { func addAuditAnnotationsFrom(ctx context.Context, ev *auditinternal.Event) {
mutex, ok := auditAnnotationsMutex(ctx) mutex, ok := auditAnnotationsMutex(ctx)
if !ok { if !ok {
klog.Errorf("Attempted to copy audit annotations from unsupported request chain") // auditing is not enabled
return return
} }