Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f327a2a4
Commit
f327a2a4
authored
Mar 05, 2018
by
Mik Vyatskov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add retrying to audit logging e2e tests
Signed-off-by:
Mik Vyatskov
<
vmik@google.com
>
parent
a8178705
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
7 deletions
+30
-7
audit.go
test/e2e/auth/audit.go
+30
-7
No files found.
test/e2e/auth/audit.go
View file @
f327a2a4
...
...
@@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"strings"
"time"
apiv1
"k8s.io/api/core/v1"
extensions
"k8s.io/api/extensions/v1beta1"
...
...
@@ -29,13 +30,13 @@ import (
"k8s.io/apiextensions-apiserver/test/integration/testserver"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/apis/audit/v1beta1"
"k8s.io/kubernetes/test/e2e/framework"
imageutils
"k8s.io/kubernetes/test/utils/image"
"github.com/evanphx/json-patch"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
)
var
(
...
...
@@ -630,7 +631,18 @@ var _ = SIGDescribe("Advanced Audit", func() {
expectedEvents
=
append
(
expectedEvents
,
t
.
events
...
)
}
expectAuditLines
(
f
,
expectedEvents
)
// The default flush timeout is 30 seconds, therefore it should be enough to retry once
// to find all expected events. However, we're waiting for 5 minutes to avoid flakes.
pollingInterval
:=
30
*
time
.
Second
pollingTimeout
:=
5
*
time
.
Minute
err
=
wait
.
Poll
(
pollingInterval
,
pollingTimeout
,
func
()
(
bool
,
error
)
{
ok
,
err
:=
checkAuditLines
(
f
,
expectedEvents
)
if
err
!=
nil
{
framework
.
Logf
(
"Failed to observe audit events: %v"
,
err
)
}
return
ok
,
nil
})
framework
.
ExpectNoError
(
err
,
"after %v failed to observe audit events"
,
pollingTimeout
)
})
})
...
...
@@ -648,7 +660,7 @@ type auditEvent struct {
}
// Search the audit log for the expected audit lines.
func
expectAuditLines
(
f
*
framework
.
Framework
,
expected
[]
auditEvent
)
{
func
checkAuditLines
(
f
*
framework
.
Framework
,
expected
[]
auditEvent
)
(
bool
,
error
)
{
expectations
:=
map
[
auditEvent
]
bool
{}
for
_
,
event
:=
range
expected
{
expectations
[
event
]
=
false
...
...
@@ -656,25 +668,36 @@ func expectAuditLines(f *framework.Framework, expected []auditEvent) {
// Fetch the log stream.
stream
,
err
:=
f
.
ClientSet
.
CoreV1
()
.
RESTClient
()
.
Get
()
.
AbsPath
(
"/logs/kube-apiserver-audit.log"
)
.
Stream
()
framework
.
ExpectNoError
(
err
,
"could not read audit log"
)
if
err
!=
nil
{
return
false
,
err
}
defer
stream
.
Close
()
scanner
:=
bufio
.
NewScanner
(
stream
)
for
scanner
.
Scan
()
{
line
:=
scanner
.
Text
()
event
,
err
:=
parseAuditLine
(
line
)
framework
.
ExpectNoError
(
err
)
if
err
!=
nil
{
return
false
,
err
}
// If the event was expected, mark it as found.
if
_
,
found
:=
expectations
[
event
];
found
{
expectations
[
event
]
=
true
}
}
framework
.
ExpectNoError
(
scanner
.
Err
(),
"error reading audit log"
)
if
err
:=
scanner
.
Err
();
err
!=
nil
{
return
false
,
err
}
noneMissing
:=
true
for
event
,
found
:=
range
expectations
{
Expect
(
found
)
.
To
(
BeTrue
(),
"Event %#v not found!"
,
event
)
if
!
found
{
framework
.
Logf
(
"Event %#v not found!"
,
event
)
}
noneMissing
=
noneMissing
&&
found
}
return
noneMissing
,
nil
}
func
parseAuditLine
(
line
string
)
(
auditEvent
,
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment