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
25bd151d
Commit
25bd151d
authored
Nov 03, 2014
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make fieldPath part of getting a reference rather than part of making an event.
parent
ecebe958
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
23 deletions
+65
-23
ref.go
pkg/api/ref.go
+10
-0
ref_test.go
pkg/api/ref_test.go
+4
-1
event.go
pkg/client/record/event.go
+6
-6
event_test.go
pkg/client/record/event_test.go
+42
-13
scheduler.go
plugin/pkg/scheduler/scheduler.go
+3
-3
No files found.
pkg/api/ref.go
View file @
25bd151d
...
...
@@ -62,6 +62,16 @@ func GetReference(obj runtime.Object) (*ObjectReference, error) {
},
nil
}
// GetPartialReference is exactly like GetReference, but allows you to set the FieldPath.
func
GetPartialReference
(
obj
runtime
.
Object
,
fieldPath
string
)
(
*
ObjectReference
,
error
)
{
ref
,
err
:=
GetReference
(
obj
)
if
err
!=
nil
{
return
nil
,
err
}
ref
.
FieldPath
=
fieldPath
return
ref
,
nil
}
// Allow clients to preemptively get a reference to an API object and pass it to places that
// intend only to get a reference to that object. This simplifies the event recording interface.
func
(
*
ObjectReference
)
IsAnAPIObject
()
{}
pkg/api/ref_test.go
View file @
25bd151d
...
...
@@ -31,6 +31,7 @@ func TestGetReference(t *testing.T) {
table
:=
map
[
string
]
struct
{
obj
runtime
.
Object
ref
*
ObjectReference
fieldPath
string
shouldErr
bool
}{
"pod"
:
{
...
...
@@ -42,12 +43,14 @@ func TestGetReference(t *testing.T) {
SelfLink
:
"/api/v1beta1/pods/foo"
,
},
},
fieldPath
:
".desiredState.containers[0]"
,
ref
:
&
ObjectReference
{
Kind
:
"Pod"
,
APIVersion
:
"v1beta1"
,
Name
:
"foo"
,
UID
:
"bar"
,
ResourceVersion
:
"42"
,
FieldPath
:
".desiredState.containers[0]"
,
},
},
"serviceList"
:
{
...
...
@@ -85,7 +88,7 @@ func TestGetReference(t *testing.T) {
}
for
name
,
item
:=
range
table
{
ref
,
err
:=
Get
Reference
(
item
.
obj
)
ref
,
err
:=
Get
PartialReference
(
item
.
obj
,
item
.
fieldPath
)
if
e
,
a
:=
item
.
shouldErr
,
(
err
!=
nil
);
e
!=
a
{
t
.
Errorf
(
"%v: expected %v, got %v"
,
name
,
e
,
a
)
continue
...
...
pkg/client/record/event.go
View file @
25bd151d
...
...
@@ -91,7 +91,8 @@ const queueLen = 1000
var
events
=
watch
.
NewMux
(
queueLen
)
// Event constructs an event from the given information and puts it in the queue for sending.
// 'object' is the object this event is about; 'fieldPath', if not "", locates a part of 'object'.
// 'object' is the object this event is about. Event will make a reference-- or you may also
// pass a reference to the object directly.
// 'status' is the new status of the object. 'reason' is the reason it now has this status.
// Both 'status' and 'reason' should be short and unique; they will be used to automate
// handling of events, so imagine people writing switch statements to handle them. You want to
...
...
@@ -99,13 +100,12 @@ var events = watch.NewMux(queueLen)
// 'message' is intended to be human readable.
//
// The resulting event will be created in the same namespace as the reference object.
func
Event
(
object
runtime
.
Object
,
fieldPath
,
status
,
reason
,
message
string
)
{
func
Event
(
object
runtime
.
Object
,
status
,
reason
,
message
string
)
{
ref
,
err
:=
api
.
GetReference
(
object
)
if
err
!=
nil
{
glog
.
Errorf
(
"Could not construct reference to:
%#v due to: %v"
,
object
,
err
)
glog
.
Errorf
(
"Could not construct reference to:
'%#v' due to: '%v'. Will not report event: '%v' '%v' '%v'"
,
object
,
err
,
status
,
reason
,
message
)
return
}
ref
.
FieldPath
=
fieldPath
t
:=
util
.
Now
()
e
:=
&
api
.
Event
{
...
...
@@ -124,6 +124,6 @@ func Event(object runtime.Object, fieldPath, status, reason, message string) {
}
// Eventf is just like Event, but with Sprintf for the message field.
func
Eventf
(
object
runtime
.
Object
,
fieldPath
,
status
,
reason
,
messageFmt
string
,
args
...
interface
{})
{
Event
(
object
,
fieldPath
,
status
,
reason
,
fmt
.
Sprintf
(
messageFmt
,
args
...
))
func
Eventf
(
object
runtime
.
Object
,
status
,
reason
,
messageFmt
string
,
args
...
interface
{})
{
Event
(
object
,
status
,
reason
,
fmt
.
Sprintf
(
messageFmt
,
args
...
))
}
pkg/client/record/event_test.go
View file @
25bd151d
...
...
@@ -45,24 +45,54 @@ func (t *testEventRecorder) clearOnEvent() {
}
func
TestEventf
(
t
*
testing
.
T
)
{
testPod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
SelfLink
:
"/api/v1beta1/pods/foo"
,
Name
:
"foo"
,
Namespace
:
"baz"
,
UID
:
"bar"
,
},
}
testRef
,
err
:=
api
.
GetPartialReference
(
testPod
,
"desiredState.manifest.containers[2]"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
table
:=
[]
struct
{
obj
runtime
.
Object
fieldPath
,
status
,
reason
string
messageFmt
string
elements
[]
interface
{}
expect
*
api
.
Event
expectLog
string
obj
runtime
.
Object
status
,
reason
string
messageFmt
string
elements
[]
interface
{}
expect
*
api
.
Event
expectLog
string
}{
{
obj
:
&
api
.
Pod
{
obj
:
testRef
,
status
:
"running"
,
reason
:
"started"
,
messageFmt
:
"some verbose message: %v"
,
elements
:
[]
interface
{}{
1
},
expect
:
&
api
.
Event
{
ObjectMeta
:
api
.
ObjectMeta
{
SelfLink
:
"/api/v1beta1/pods/foo"
,
Name
:
"foo"
,
Namespace
:
"baz"
,
UID
:
"bar"
,
},
InvolvedObject
:
api
.
ObjectReference
{
Kind
:
"Pod"
,
Name
:
"foo"
,
Namespace
:
"baz"
,
UID
:
"bar"
,
APIVersion
:
"v1beta1"
,
FieldPath
:
"desiredState.manifest.containers[2]"
,
},
Status
:
"running"
,
Reason
:
"started"
,
Message
:
"some verbose message: 1"
,
Source
:
"eventTest"
,
},
fieldPath
:
"desiredState.manifest.containers[2]"
,
expectLog
:
`Event(api.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1beta1", ResourceVersion:"", FieldPath:"desiredState.manifest.containers[2]"}): status: 'running', reason: 'started' some verbose message: 1`
,
},
{
obj
:
testPod
,
status
:
"running"
,
reason
:
"started"
,
messageFmt
:
"some verbose message: %v"
,
...
...
@@ -78,14 +108,13 @@ func TestEventf(t *testing.T) {
Namespace
:
"baz"
,
UID
:
"bar"
,
APIVersion
:
"v1beta1"
,
FieldPath
:
"desiredState.manifest.containers[2]"
,
},
Status
:
"running"
,
Reason
:
"started"
,
Message
:
"some verbose message: 1"
,
Source
:
"eventTest"
,
},
expectLog
:
`Event(api.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1beta1", ResourceVersion:"", FieldPath:"
desiredState.manifest.containers[2]
"}): status: 'running', reason: 'started' some verbose message: 1`
,
expectLog
:
`Event(api.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1beta1", ResourceVersion:"", FieldPath:""}): status: 'running', reason: 'started' some verbose message: 1`
,
},
}
...
...
@@ -120,7 +149,7 @@ func TestEventf(t *testing.T) {
called
<-
struct
{}{}
})
record
.
Eventf
(
item
.
obj
,
item
.
fieldPath
,
item
.
status
,
item
.
reason
,
item
.
messageFmt
,
item
.
elements
...
)
record
.
Eventf
(
item
.
obj
,
item
.
status
,
item
.
reason
,
item
.
messageFmt
,
item
.
elements
...
)
<-
called
<-
called
...
...
plugin/pkg/scheduler/scheduler.go
View file @
25bd151d
...
...
@@ -68,7 +68,7 @@ func (s *Scheduler) scheduleOne() {
pod
:=
s
.
config
.
NextPod
()
dest
,
err
:=
s
.
config
.
Algorithm
.
Schedule
(
*
pod
,
s
.
config
.
MinionLister
)
if
err
!=
nil
{
record
.
Eventf
(
pod
,
""
,
string
(
api
.
PodPending
),
"failedScheduling"
,
"Error scheduling: %v"
,
err
)
record
.
Eventf
(
pod
,
string
(
api
.
PodPending
),
"failedScheduling"
,
"Error scheduling: %v"
,
err
)
s
.
config
.
Error
(
pod
,
err
)
return
}
...
...
@@ -78,9 +78,9 @@ func (s *Scheduler) scheduleOne() {
Host
:
dest
,
}
if
err
:=
s
.
config
.
Binder
.
Bind
(
b
);
err
!=
nil
{
record
.
Eventf
(
pod
,
""
,
string
(
api
.
PodPending
),
"failedScheduling"
,
"Binding rejected: %v"
,
err
)
record
.
Eventf
(
pod
,
string
(
api
.
PodPending
),
"failedScheduling"
,
"Binding rejected: %v"
,
err
)
s
.
config
.
Error
(
pod
,
err
)
return
}
record
.
Eventf
(
pod
,
""
,
string
(
api
.
PodPending
),
"scheduled"
,
"Successfully assigned %v to %v"
,
pod
.
Name
,
dest
)
record
.
Eventf
(
pod
,
string
(
api
.
PodPending
),
"scheduled"
,
"Successfully assigned %v to %v"
,
pod
.
Name
,
dest
)
}
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