Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit e309583

Browse files
author
k8s-merge-robot
committed
Merge pull request kubernetes#18473 from smarterclayton/change_runtime_object
Auto commit by PR queue bot
2 parents 6716290 + 8f203a2 commit e309583

File tree

64 files changed

+831
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+831
-364
lines changed

cmd/libs/go2idl/client-gen/testdata/apis/testgroup/register.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ func addKnownTypes() {
3939
&unversioned.ListOptions{})
4040
}
4141

42-
func (*TestType) IsAnAPIObject() {}
43-
func (*TestTypeList) IsAnAPIObject() {}
42+
func (obj *TestType) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
43+
func (obj *TestTypeList) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }

cmd/libs/go2idl/client-gen/testdata/apis/testgroup/v1/register.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ func addKnownTypes() {
4242
&unversioned.ListOptions{})
4343
}
4444

45-
func (*TestType) IsAnAPIObject() {}
46-
func (*TestTypeList) IsAnAPIObject() {}
45+
func (obj *TestType) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
46+
func (obj *TestTypeList) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }

contrib/mesos/pkg/election/etcd_master.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/coreos/go-etcd/etcd"
2424
"github.com/golang/glog"
25+
"k8s.io/kubernetes/pkg/api/unversioned"
2526
etcdutil "k8s.io/kubernetes/pkg/storage/etcd/util"
2627
"k8s.io/kubernetes/pkg/util"
2728
"k8s.io/kubernetes/pkg/watch"
@@ -34,7 +35,7 @@ type Master string
3435
// TODO(k8s): Either fix watch so this isn't necessary, or make this a real API Object.
3536
// TODO(k8s): when it becomes clear how this package will be used, move these declarations to
3637
// to the proper place.
37-
func (Master) IsAnAPIObject() {}
38+
func (obj Master) GetObjectKind() unversioned.ObjectKind { return unversioned.EmptyObjectKind }
3839

3940
// NewEtcdMasterElector returns an implementation of election.MasterElector backed by etcd.
4041
func NewEtcdMasterElector(h *etcd.Client) MasterElector {

pkg/api/errors/errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func Test_reasonForError(t *testing.T) {
169169

170170
type TestType struct{}
171171

172-
func (*TestType) IsAnAPIObject() {}
172+
func (obj *TestType) GetObjectKind() unversioned.ObjectKind { return unversioned.EmptyObjectKind }
173173

174174
func TestFromObject(t *testing.T) {
175175
table := []struct {

pkg/api/meta.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"k8s.io/kubernetes/pkg/api/unversioned"
2121
"k8s.io/kubernetes/pkg/conversion"
2222
"k8s.io/kubernetes/pkg/runtime"
23+
"k8s.io/kubernetes/pkg/types"
2324
"k8s.io/kubernetes/pkg/util"
2425
)
2526

@@ -60,3 +61,22 @@ func ListMetaFor(obj runtime.Object) (*unversioned.ListMeta, error) {
6061
err = runtime.FieldPtr(v, "ListMeta", &meta)
6162
return meta, err
6263
}
64+
65+
// Namespace implements meta.Object for any object with an ObjectMeta typed field. Allows
66+
// fast, direct access to metadata fields for API objects.
67+
func (meta *ObjectMeta) GetNamespace() string { return meta.Namespace }
68+
func (meta *ObjectMeta) SetNamespace(namespace string) { meta.Namespace = namespace }
69+
func (meta *ObjectMeta) GetName() string { return meta.Name }
70+
func (meta *ObjectMeta) SetName(name string) { meta.Name = name }
71+
func (meta *ObjectMeta) GetGenerateName() string { return meta.GenerateName }
72+
func (meta *ObjectMeta) SetGenerateName(generateName string) { meta.GenerateName = generateName }
73+
func (meta *ObjectMeta) GetUID() types.UID { return meta.UID }
74+
func (meta *ObjectMeta) SetUID(uid types.UID) { meta.UID = uid }
75+
func (meta *ObjectMeta) GetResourceVersion() string { return meta.ResourceVersion }
76+
func (meta *ObjectMeta) SetResourceVersion(version string) { meta.ResourceVersion = version }
77+
func (meta *ObjectMeta) GetSelfLink() string { return meta.SelfLink }
78+
func (meta *ObjectMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink }
79+
func (meta *ObjectMeta) GetLabels() map[string]string { return meta.Labels }
80+
func (meta *ObjectMeta) SetLabels(labels map[string]string) { meta.Labels = labels }
81+
func (meta *ObjectMeta) GetAnnotations() map[string]string { return meta.Annotations }
82+
func (meta *ObjectMeta) SetAnnotations(annotations map[string]string) { meta.Annotations = annotations }

pkg/api/meta/help_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"k8s.io/kubernetes/pkg/api"
2424
"k8s.io/kubernetes/pkg/api/meta"
25+
"k8s.io/kubernetes/pkg/api/unversioned"
2526
"k8s.io/kubernetes/pkg/api/v1"
2627
"k8s.io/kubernetes/pkg/runtime"
2728
"k8s.io/kubernetes/pkg/util"
@@ -114,7 +115,9 @@ type fakePtrInterfaceList struct {
114115
Items *[]runtime.Object
115116
}
116117

117-
func (f fakePtrInterfaceList) IsAnAPIObject() {}
118+
func (obj fakePtrInterfaceList) GetObjectKind() unversioned.ObjectKind {
119+
return unversioned.EmptyObjectKind
120+
}
118121

119122
func TestExtractListOfInterfacePtrs(t *testing.T) {
120123
pl := &fakePtrInterfaceList{
@@ -133,7 +136,9 @@ type fakePtrValueList struct {
133136
Items []*api.Pod
134137
}
135138

136-
func (f fakePtrValueList) IsAnAPIObject() {}
139+
func (obj fakePtrValueList) GetObjectKind() unversioned.ObjectKind {
140+
return unversioned.EmptyObjectKind
141+
}
137142

138143
func TestExtractListOfValuePtrs(t *testing.T) {
139144
pl := &fakePtrValueList{

pkg/api/meta/interfaces.go

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,48 @@ type VersionInterfaces struct {
2929
MetadataAccessor
3030
}
3131

32-
// Interface lets you work with object and list metadata from any of the versioned or
32+
type ObjectMetaAccessor interface {
33+
GetObjectMeta() Object
34+
}
35+
36+
// Object lets you work with object metadata from any of the versioned or
3337
// internal API objects. Attempting to set or retrieve a field on an object that does
3438
// not support that field (Name, UID, Namespace on lists) will be a no-op and return
3539
// a default value.
36-
// TODO: rename to ObjectInterface when we clear up these interfaces.
37-
type Interface interface {
38-
TypeInterface
39-
40-
Namespace() string
40+
type Object interface {
41+
GetNamespace() string
4142
SetNamespace(namespace string)
42-
Name() string
43+
GetName() string
4344
SetName(name string)
44-
GenerateName() string
45+
GetGenerateName() string
4546
SetGenerateName(name string)
46-
UID() types.UID
47+
GetUID() types.UID
4748
SetUID(uid types.UID)
48-
ResourceVersion() string
49+
GetResourceVersion() string
4950
SetResourceVersion(version string)
50-
SelfLink() string
51+
GetSelfLink() string
5152
SetSelfLink(selfLink string)
52-
Labels() map[string]string
53+
GetLabels() map[string]string
5354
SetLabels(labels map[string]string)
54-
Annotations() map[string]string
55+
GetAnnotations() map[string]string
5556
SetAnnotations(annotations map[string]string)
5657
}
5758

58-
// TypeInterface exposes the type and APIVersion of versioned or internal API objects.
59-
type TypeInterface interface {
60-
APIVersion() string
59+
// List lets you work with list metadata from any of the versioned or
60+
// internal API objects. Attempting to set or retrieve a field on an object that does
61+
// not support that field will be a no-op and return a default value.
62+
type List interface {
63+
GetResourceVersion() string
64+
SetResourceVersion(version string)
65+
GetSelfLink() string
66+
SetSelfLink(selfLink string)
67+
}
68+
69+
// Type exposes the type and APIVersion of versioned or internal API objects.
70+
type Type interface {
71+
GetAPIVersion() string
6172
SetAPIVersion(version string)
62-
Kind() string
73+
GetKind() string
6374
SetKind(kind string)
6475
}
6576

0 commit comments

Comments
 (0)