diff --git a/pkg/api/meta/meta.go b/pkg/api/meta/meta.go index 449c500c4e3..12d9ce3c044 100644 --- a/pkg/api/meta/meta.go +++ b/pkg/api/meta/meta.go @@ -108,6 +108,8 @@ func NewSelfLinker() runtime.SelfLinker { type Accessor interface { Name() string SetName(name string) + UID() string + SetUID(uid string) APIVersion() string SetAPIVersion(version string) Kind() string @@ -120,6 +122,7 @@ type Accessor interface { type genericTypeMeta struct { name *string + uid *string apiVersion *string kind *string resourceVersion *string @@ -134,6 +137,14 @@ func (g genericTypeMeta) SetName(name string) { *g.name = name } +func (g genericTypeMeta) UID() string { + return *g.uid +} + +func (g genericTypeMeta) SetUID(uid string) { + *g.uid = uid +} + func (g genericTypeMeta) APIVersion() string { return *g.apiVersion } @@ -199,6 +210,9 @@ func newGenericTypeMeta(v reflect.Value) (genericTypeMeta, error) { if err := fieldPtr(v, "Name", &g.name); err != nil { return g, err } + if err := fieldPtr(v, "UID", &g.uid); err != nil { + return g, err + } if err := fieldPtr(v, "APIVersion", &g.apiVersion); err != nil { return g, err } diff --git a/pkg/api/meta/meta_test.go b/pkg/api/meta/meta_test.go index daf6d471246..1acb7ebf65f 100644 --- a/pkg/api/meta/meta_test.go +++ b/pkg/api/meta/meta_test.go @@ -28,6 +28,7 @@ func TestGenericTypeMeta(t *testing.T) { type TypeMeta struct { Kind string `json:"kind,omitempty" yaml:"kind,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` + UID string `json:"uid,omitempty" yaml:"uid,omitempty"` CreationTimestamp util.Time `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"` SelfLink string `json:"selfLink,omitempty" yaml:"selfLink,omitempty"` ResourceVersion string `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"` @@ -35,6 +36,7 @@ func TestGenericTypeMeta(t *testing.T) { } j := TypeMeta{ Name: "foo", + UID: "uid", APIVersion: "a", Kind: "b", ResourceVersion: "1", @@ -49,6 +51,9 @@ func TestGenericTypeMeta(t *testing.T) { if e, a := "foo", jbi.Name(); e != a { t.Errorf("expected %v, got %v", e, a) } + if e, a := "uid", jbi.UID(); e != a { + t.Errorf("expected %v, got %v", e, a) + } if e, a := "a", jbi.APIVersion(); e != a { t.Errorf("expected %v, got %v", e, a) } @@ -63,6 +68,7 @@ func TestGenericTypeMeta(t *testing.T) { } jbi.SetName("bar") + jbi.SetUID("other") jbi.SetAPIVersion("c") jbi.SetKind("d") jbi.SetResourceVersion("2") @@ -72,6 +78,9 @@ func TestGenericTypeMeta(t *testing.T) { if e, a := "bar", j.Name; e != a { t.Errorf("expected %v, got %v", e, a) } + if e, a := "other", j.UID; e != a { + t.Errorf("expected %v, got %v", e, a) + } if e, a := "c", j.APIVersion; e != a { t.Errorf("expected %v, got %v", e, a) } diff --git a/pkg/api/ref.go b/pkg/api/ref.go index 2e56d3aa5be..200fa34b557 100644 --- a/pkg/api/ref.go +++ b/pkg/api/ref.go @@ -53,7 +53,7 @@ func GetReference(obj runtime.Object) (*ObjectReference, error) { APIVersion: version[1], // TODO: correct Name and UID when TypeMeta makes a distinction Name: accessor.Name(), - UID: accessor.Name(), + UID: accessor.UID(), ResourceVersion: accessor.ResourceVersion(), }, nil } diff --git a/pkg/api/ref_test.go b/pkg/api/ref_test.go index 14be5bb1600..fefb668c8a5 100644 --- a/pkg/api/ref_test.go +++ b/pkg/api/ref_test.go @@ -37,6 +37,7 @@ func TestGetReference(t *testing.T) { obj: &Pod{ TypeMeta: TypeMeta{ Name: "foo", + UID: "bar", ResourceVersion: "42", SelfLink: "/api/v1beta1/pods/foo", }, @@ -45,7 +46,7 @@ func TestGetReference(t *testing.T) { Kind: "Pod", APIVersion: "v1beta1", Name: "foo", - UID: "foo", + UID: "bar", ResourceVersion: "42", }, }, @@ -53,6 +54,7 @@ func TestGetReference(t *testing.T) { obj: &ServiceList{ TypeMeta: TypeMeta{ Name: "foo", + UID: "bar", ResourceVersion: "42", SelfLink: "/api/v1beta2/services", }, @@ -61,7 +63,7 @@ func TestGetReference(t *testing.T) { Kind: "ServiceList", APIVersion: "v1beta2", Name: "foo", - UID: "foo", + UID: "bar", ResourceVersion: "42", }, }, diff --git a/pkg/client/record/event_test.go b/pkg/client/record/event_test.go index 9c58b23ec18..d515d28d0bf 100644 --- a/pkg/client/record/event_test.go +++ b/pkg/client/record/event_test.go @@ -57,6 +57,7 @@ func TestEventf(t *testing.T) { TypeMeta: api.TypeMeta{ SelfLink: "/api/v1beta1/pods/foo", Name: "foo", + UID: "bar", }, }, fieldPath: "desiredState.manifest.containers[2]", @@ -68,7 +69,7 @@ func TestEventf(t *testing.T) { InvolvedObject: api.ObjectReference{ Kind: "Pod", Name: "foo", - UID: "foo", + UID: "bar", APIVersion: "v1beta1", FieldPath: "desiredState.manifest.containers[2]", }, @@ -77,7 +78,7 @@ func TestEventf(t *testing.T) { Message: "some verbose message: 1", Source: "eventTest", }, - expectLog: `Event(api.ObjectReference{Kind:"Pod", Namespace:"", Name:"foo", UID:"foo", APIVersion:"v1beta1", ResourceVersion:"", FieldPath:"desiredState.manifest.containers[2]"}): status: 'running', reason: 'started' some verbose message: 1`, + 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`, }, } diff --git a/pkg/runtime/types.go b/pkg/runtime/types.go index 7475444166b..c20c6a9df74 100644 --- a/pkg/runtime/types.go +++ b/pkg/runtime/types.go @@ -39,6 +39,7 @@ type TypeMeta struct { Kind string `json:"kind,omitempty" yaml:"kind,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` + UID string `json:"uid,omitempty" yaml:"uid,omitempty"` CreationTimestamp util.Time `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"` SelfLink string `json:"selfLink,omitempty" yaml:"selfLink,omitempty"` ResourceVersion string `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"`