mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 14:14:39 +00:00
@@ -51,8 +51,8 @@ func GetReference(obj runtime.Object) (*ObjectReference, error) {
|
|||||||
return &ObjectReference{
|
return &ObjectReference{
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
APIVersion: version[1],
|
APIVersion: version[1],
|
||||||
// TODO: correct Name and UID when TypeMeta makes a distinction
|
|
||||||
Name: meta.Name(),
|
Name: meta.Name(),
|
||||||
|
Namespace: meta.Namespace(),
|
||||||
UID: meta.UID(),
|
UID: meta.UID(),
|
||||||
ResourceVersion: meta.ResourceVersion(),
|
ResourceVersion: meta.ResourceVersion(),
|
||||||
}, nil
|
}, nil
|
||||||
|
@@ -624,5 +624,29 @@ func init() {
|
|||||||
}
|
}
|
||||||
return s.Convert(&in.Items, &out.Items, 0)
|
return s.Convert(&in.Items, &out.Items, 0)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Object ID <-> Name
|
||||||
|
// TODO: amend the conversion package to allow overriding specific fields.
|
||||||
|
func(in *ObjectReference, out *newer.ObjectReference, s conversion.Scope) error {
|
||||||
|
out.Kind = in.Kind
|
||||||
|
out.Namespace = in.Namespace
|
||||||
|
out.Name = in.ID
|
||||||
|
out.UID = in.UID
|
||||||
|
out.APIVersion = in.APIVersion
|
||||||
|
out.ResourceVersion = in.ResourceVersion
|
||||||
|
out.FieldPath = in.FieldPath
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
func(in *newer.ObjectReference, out *ObjectReference, s conversion.Scope) error {
|
||||||
|
out.ID = in.Name
|
||||||
|
out.Kind = in.Kind
|
||||||
|
out.Namespace = in.Namespace
|
||||||
|
out.ID = in.Name
|
||||||
|
out.UID = in.UID
|
||||||
|
out.APIVersion = in.APIVersion
|
||||||
|
out.ResourceVersion = in.ResourceVersion
|
||||||
|
out.FieldPath = in.FieldPath
|
||||||
|
return nil
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -683,7 +683,7 @@ type ServerOpList struct {
|
|||||||
type ObjectReference struct {
|
type ObjectReference struct {
|
||||||
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
|
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
|
||||||
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
||||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
ID string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||||
UID string `json:"uid,omitempty" yaml:"uid,omitempty"`
|
UID string `json:"uid,omitempty" yaml:"uid,omitempty"`
|
||||||
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
|
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
|
||||||
ResourceVersion string `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"`
|
ResourceVersion string `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"`
|
||||||
|
@@ -574,5 +574,29 @@ func init() {
|
|||||||
}
|
}
|
||||||
return s.Convert(&in.Items, &out.Items, 0)
|
return s.Convert(&in.Items, &out.Items, 0)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Object ID <-> Name
|
||||||
|
// TODO: amend the conversion package to allow overriding specific fields.
|
||||||
|
func(in *ObjectReference, out *newer.ObjectReference, s conversion.Scope) error {
|
||||||
|
out.Kind = in.Kind
|
||||||
|
out.Namespace = in.Namespace
|
||||||
|
out.Name = in.ID
|
||||||
|
out.UID = in.UID
|
||||||
|
out.APIVersion = in.APIVersion
|
||||||
|
out.ResourceVersion = in.ResourceVersion
|
||||||
|
out.FieldPath = in.FieldPath
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
func(in *newer.ObjectReference, out *ObjectReference, s conversion.Scope) error {
|
||||||
|
out.ID = in.Name
|
||||||
|
out.Kind = in.Kind
|
||||||
|
out.Namespace = in.Namespace
|
||||||
|
out.ID = in.Name
|
||||||
|
out.UID = in.UID
|
||||||
|
out.APIVersion = in.APIVersion
|
||||||
|
out.ResourceVersion = in.ResourceVersion
|
||||||
|
out.FieldPath = in.FieldPath
|
||||||
|
return nil
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -658,7 +658,7 @@ type ServerOpList struct {
|
|||||||
type ObjectReference struct {
|
type ObjectReference struct {
|
||||||
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
|
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
|
||||||
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
||||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
ID string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||||
UID string `json:"uid,omitempty" yaml:"uid,omitempty"`
|
UID string `json:"uid,omitempty" yaml:"uid,omitempty"`
|
||||||
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
|
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
|
||||||
ResourceVersion string `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"`
|
ResourceVersion string `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"`
|
||||||
|
@@ -50,7 +50,7 @@ func newEvents(c *Client) *events {
|
|||||||
// Create makes a new event. Returns the copy of the event the server returns, or an error.
|
// Create makes a new event. Returns the copy of the event the server returns, or an error.
|
||||||
func (c *events) Create(event *api.Event) (*api.Event, error) {
|
func (c *events) Create(event *api.Event) (*api.Event, error) {
|
||||||
result := &api.Event{}
|
result := &api.Event{}
|
||||||
err := c.r.Post().Path("events").Body(event).Do().Into(result)
|
err := c.r.Post().Path("events").Namespace(event.Namespace).Body(event).Do().Into(result)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,6 +29,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// EventRecorder knows how to store events (client.Client implements it.)
|
// EventRecorder knows how to store events (client.Client implements it.)
|
||||||
|
// EventRecorder must respect the namespace that will be embedded in 'event'.
|
||||||
type EventRecorder interface {
|
type EventRecorder interface {
|
||||||
Create(event *api.Event) (*api.Event, error)
|
Create(event *api.Event) (*api.Event, error)
|
||||||
}
|
}
|
||||||
@@ -96,6 +97,8 @@ var events = watch.NewMux(queueLen)
|
|||||||
// handling of events, so imagine people writing switch statements to handle them. You want to
|
// handling of events, so imagine people writing switch statements to handle them. You want to
|
||||||
// make that easy.
|
// make that easy.
|
||||||
// 'message' is intended to be human readable.
|
// '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, fieldPath, status, reason, message string) {
|
||||||
ref, err := api.GetReference(object)
|
ref, err := api.GetReference(object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -103,12 +106,18 @@ func Event(object runtime.Object, fieldPath, status, reason, message string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ref.FieldPath = fieldPath
|
ref.FieldPath = fieldPath
|
||||||
|
t := util.Now()
|
||||||
|
|
||||||
e := &api.Event{
|
e := &api.Event{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: fmt.Sprintf("%v.%x", ref.Name, t.UnixNano()),
|
||||||
|
Namespace: ref.Namespace,
|
||||||
|
},
|
||||||
InvolvedObject: *ref,
|
InvolvedObject: *ref,
|
||||||
Status: status,
|
Status: status,
|
||||||
Reason: reason,
|
Reason: reason,
|
||||||
Message: message,
|
Message: message,
|
||||||
Timestamp: util.Now(),
|
Timestamp: t,
|
||||||
}
|
}
|
||||||
|
|
||||||
events.Action(watch.Added, e)
|
events.Action(watch.Added, e)
|
||||||
|
@@ -19,6 +19,7 @@ package record_test
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
@@ -57,6 +58,7 @@ func TestEventf(t *testing.T) {
|
|||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
SelfLink: "/api/v1beta1/pods/foo",
|
SelfLink: "/api/v1beta1/pods/foo",
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
Namespace: "baz",
|
||||||
UID: "bar",
|
UID: "bar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -66,9 +68,14 @@ func TestEventf(t *testing.T) {
|
|||||||
messageFmt: "some verbose message: %v",
|
messageFmt: "some verbose message: %v",
|
||||||
elements: []interface{}{1},
|
elements: []interface{}{1},
|
||||||
expect: &api.Event{
|
expect: &api.Event{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
Namespace: "baz",
|
||||||
|
},
|
||||||
InvolvedObject: api.ObjectReference{
|
InvolvedObject: api.ObjectReference{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
Namespace: "baz",
|
||||||
UID: "bar",
|
UID: "bar",
|
||||||
APIVersion: "v1beta1",
|
APIVersion: "v1beta1",
|
||||||
FieldPath: "desiredState.manifest.containers[2]",
|
FieldPath: "desiredState.manifest.containers[2]",
|
||||||
@@ -78,7 +85,7 @@ func TestEventf(t *testing.T) {
|
|||||||
Message: "some verbose message: 1",
|
Message: "some verbose message: 1",
|
||||||
Source: "eventTest",
|
Source: "eventTest",
|
||||||
},
|
},
|
||||||
expectLog: `Event(api.ObjectReference{Kind:"Pod", Namespace:"", 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:"desiredState.manifest.containers[2]"}): status: 'running', reason: 'started' some verbose message: 1`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +99,11 @@ func TestEventf(t *testing.T) {
|
|||||||
t.Errorf("timestamp wasn't set")
|
t.Errorf("timestamp wasn't set")
|
||||||
}
|
}
|
||||||
a.Timestamp = item.expect.Timestamp
|
a.Timestamp = item.expect.Timestamp
|
||||||
|
// Check that name has the right prefix.
|
||||||
|
if n, en := a.Name, item.expect.Name; !strings.HasPrefix(n, en) {
|
||||||
|
t.Errorf("Name '%v' does not contain prefix '%v'", n, en)
|
||||||
|
}
|
||||||
|
a.Name = item.expect.Name
|
||||||
if e, a := item.expect, &a; !reflect.DeepEqual(e, a) {
|
if e, a := item.expect, &a; !reflect.DeepEqual(e, a) {
|
||||||
t.Errorf("diff: %s", util.ObjectDiff(e, a))
|
t.Errorf("diff: %s", util.ObjectDiff(e, a))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user