Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/registry/core/serviceaccount/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestCreate_Token_SetsCredentialIDAuditAnnotation(t *testing.T) {
}

auditContext := audit.AuditContextFrom(ctx)
issuedCredentialID, ok := auditContext.Event.Annotations["authentication.kubernetes.io/issued-credential-id"]
issuedCredentialID, ok := auditContext.GetEventAnnotation("authentication.kubernetes.io/issued-credential-id")
if !ok || len(issuedCredentialID) == 0 {
t.Errorf("did not find issued-credential-id in audit event annotations")
}
Expand Down
6 changes: 3 additions & 3 deletions staging/src/k8s.io/apiserver/pkg/admission/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ func ensureAnnotationGetter(a Attributes) error {
}

func (handler *auditHandler) logAnnotations(ctx context.Context, a Attributes) {
ae := audit.AuditEventFrom(ctx)
ae := audit.AuditContextFrom(ctx)
if ae == nil {
return
}

var annotations map[string]string
switch a := a.(type) {
case privateAnnotationsGetter:
annotations = a.getAnnotations(ae.Level)
annotations = a.getAnnotations(ae.GetEventLevel())
case AnnotationsGetter:
annotations = a.GetAnnotations(ae.Level)
annotations = a.GetAnnotations(ae.GetEventLevel())
default:
// this will never happen, because we have already checked it in ensureAnnotationGetter
}
Expand Down
12 changes: 6 additions & 6 deletions staging/src/k8s.io/apiserver/pkg/admission/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ func TestWithAudit(t *testing.T) {
var handler Interface = fakeHandler{tc.admit, tc.admitAnnotations, tc.validate, tc.validateAnnotations, tc.handles}
ctx := audit.WithAuditContext(context.Background())
ac := audit.AuditContextFrom(ctx)
ae := &ac.Event
ae.Level = auditinternal.LevelMetadata
if err := ac.Init(audit.RequestAuditConfig{Level: auditinternal.LevelMetadata}, nil); err != nil {
t.Fatal(err)
}

auditHandler := WithAudit(handler)
a := attributes()

Expand All @@ -171,9 +173,9 @@ func TestWithAudit(t *testing.T) {
annotations[k] = v
}
if len(annotations) == 0 {
assert.Nil(t, ae.Annotations, tcName+": unexptected annotations set in audit event")
assert.Nil(t, ac.GetEventAnnotations(), tcName+": unexptected annotations set in audit event")
} else {
assert.Equal(t, annotations, ae.Annotations, tcName+": unexptected annotations set in audit event")
assert.Equal(t, annotations, ac.GetEventAnnotations(), tcName+": unexptected annotations set in audit event")
}
}
}
Expand All @@ -187,8 +189,6 @@ func TestWithAuditConcurrency(t *testing.T) {
}
var handler Interface = fakeHandler{admitAnnotations: admitAnnotations, handles: true}
ctx := audit.WithAuditContext(context.Background())
ac := audit.AuditContextFrom(ctx)
ac.Event.Level = auditinternal.LevelMetadata
auditHandler := WithAudit(handler)
a := attributes()

Expand Down
Loading