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
84e2c36c
Commit
84e2c36c
authored
Apr 28, 2015
by
Vishnu Kannan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set namespace of events to "default" if the involved object does not have
any namespace set.
parent
aa487b7c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
1 deletion
+94
-1
event.go
pkg/client/record/event.go
+5
-1
event_test.go
pkg/client/record/event_test.go
+89
-0
No files found.
pkg/client/record/event.go
View file @
84e2c36c
...
@@ -253,10 +253,14 @@ func (recorder *recorderImpl) Eventf(object runtime.Object, reason, messageFmt s
...
@@ -253,10 +253,14 @@ func (recorder *recorderImpl) Eventf(object runtime.Object, reason, messageFmt s
func
makeEvent
(
ref
*
api
.
ObjectReference
,
reason
,
message
string
)
*
api
.
Event
{
func
makeEvent
(
ref
*
api
.
ObjectReference
,
reason
,
message
string
)
*
api
.
Event
{
t
:=
util
.
Now
()
t
:=
util
.
Now
()
namespace
:=
ref
.
Namespace
if
namespace
==
""
{
namespace
=
api
.
NamespaceDefault
}
return
&
api
.
Event
{
return
&
api
.
Event
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
fmt
.
Sprintf
(
"%v.%x"
,
ref
.
Name
,
t
.
UnixNano
()),
Name
:
fmt
.
Sprintf
(
"%v.%x"
,
ref
.
Name
,
t
.
UnixNano
()),
Namespace
:
ref
.
N
amespace
,
Namespace
:
n
amespace
,
},
},
InvolvedObject
:
*
ref
,
InvolvedObject
:
*
ref
,
Reason
:
reason
,
Reason
:
reason
,
...
...
pkg/client/record/event_test.go
View file @
84e2c36c
...
@@ -473,3 +473,92 @@ func TestLotsOfEvents(t *testing.T) {
...
@@ -473,3 +473,92 @@ func TestLotsOfEvents(t *testing.T) {
sinkWatcher
.
Stop
()
sinkWatcher
.
Stop
()
logWatcher
.
Stop
()
logWatcher
.
Stop
()
}
}
func
TestEventfNoNamespace
(
t
*
testing
.
T
)
{
testPod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
SelfLink
:
"/api/version/pods/foo"
,
Name
:
"foo"
,
UID
:
"bar"
,
},
}
testRef
,
err
:=
api
.
GetPartialReference
(
testPod
,
"desiredState.manifest.containers[2]"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
table
:=
[]
struct
{
obj
runtime
.
Object
reason
string
messageFmt
string
elements
[]
interface
{}
expect
*
api
.
Event
expectLog
string
expectUpdate
bool
}{
{
obj
:
testRef
,
reason
:
"Started"
,
messageFmt
:
"some verbose message: %v"
,
elements
:
[]
interface
{}{
1
},
expect
:
&
api
.
Event
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
"default"
,
},
InvolvedObject
:
api
.
ObjectReference
{
Kind
:
"Pod"
,
Name
:
"foo"
,
Namespace
:
""
,
UID
:
"bar"
,
APIVersion
:
"version"
,
FieldPath
:
"desiredState.manifest.containers[2]"
,
},
Reason
:
"Started"
,
Message
:
"some verbose message: 1"
,
Source
:
api
.
EventSource
{
Component
:
"eventTest"
},
Count
:
1
,
},
expectLog
:
`Event(api.ObjectReference{Kind:"Pod", Namespace:"", Name:"foo", UID:"bar", APIVersion:"version", ResourceVersion:"", FieldPath:"desiredState.manifest.containers[2]"}): reason: 'Started' some verbose message: 1`
,
expectUpdate
:
false
,
},
}
for
_
,
item
:=
range
table
{
called
:=
make
(
chan
struct
{})
testEvents
:=
testEventSink
{
OnCreate
:
func
(
event
*
api
.
Event
)
(
*
api
.
Event
,
error
)
{
returnEvent
,
_
:=
validateEvent
(
event
,
item
.
expect
,
t
)
if
item
.
expectUpdate
{
t
.
Errorf
(
"Expected event update(), got event create()"
)
}
called
<-
struct
{}{}
return
returnEvent
,
nil
},
OnUpdate
:
func
(
event
*
api
.
Event
)
(
*
api
.
Event
,
error
)
{
returnEvent
,
_
:=
validateEvent
(
event
,
item
.
expect
,
t
)
if
!
item
.
expectUpdate
{
t
.
Errorf
(
"Expected event create(), got event update()"
)
}
called
<-
struct
{}{}
return
returnEvent
,
nil
},
}
eventBroadcaster
:=
NewBroadcaster
()
sinkWatcher
:=
eventBroadcaster
.
StartRecordingToSink
(
&
testEvents
)
logWatcher1
:=
eventBroadcaster
.
StartLogging
(
t
.
Logf
)
// Prove that it is useful
logWatcher2
:=
eventBroadcaster
.
StartLogging
(
func
(
formatter
string
,
args
...
interface
{})
{
if
e
,
a
:=
item
.
expectLog
,
fmt
.
Sprintf
(
formatter
,
args
...
);
e
!=
a
{
t
.
Errorf
(
"Expected '%v', got '%v'"
,
e
,
a
)
}
called
<-
struct
{}{}
})
recorder
:=
eventBroadcaster
.
NewRecorder
(
api
.
EventSource
{
Component
:
"eventTest"
})
recorder
.
Eventf
(
item
.
obj
,
item
.
reason
,
item
.
messageFmt
,
item
.
elements
...
)
<-
called
<-
called
sinkWatcher
.
Stop
()
logWatcher1
.
Stop
()
logWatcher2
.
Stop
()
}
}
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