mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Add UID to MetaAccessor and Ref
This commit is contained in:
parent
1ccb86c760
commit
35eaf90255
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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",
|
||||
},
|
||||
},
|
||||
|
@ -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`,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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"`
|
||||
|
Loading…
Reference in New Issue
Block a user