Skip to content

Commit

Permalink
Change runtime.Object signature
Browse files Browse the repository at this point in the history
  • Loading branch information
smarterclayton committed Dec 15, 2015
1 parent 114f6f7 commit 8f203a2
Show file tree
Hide file tree
Showing 64 changed files with 831 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ func addKnownTypes() {
&unversioned.ListOptions{})
}

func (*TestType) IsAnAPIObject() {}
func (*TestTypeList) IsAnAPIObject() {}
func (obj *TestType) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
func (obj *TestTypeList) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ func addKnownTypes() {
&unversioned.ListOptions{})
}

func (*TestType) IsAnAPIObject() {}
func (*TestTypeList) IsAnAPIObject() {}
func (obj *TestType) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
func (obj *TestTypeList) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
3 changes: 2 additions & 1 deletion contrib/mesos/pkg/election/etcd_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

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

// NewEtcdMasterElector returns an implementation of election.MasterElector backed by etcd.
func NewEtcdMasterElector(h *etcd.Client) MasterElector {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func Test_reasonForError(t *testing.T) {

type TestType struct{}

func (*TestType) IsAnAPIObject() {}
func (obj *TestType) GetObjectKind() unversioned.ObjectKind { return unversioned.EmptyObjectKind }

func TestFromObject(t *testing.T) {
table := []struct {
Expand Down
20 changes: 20 additions & 0 deletions pkg/api/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
)

Expand Down Expand Up @@ -60,3 +61,22 @@ func ListMetaFor(obj runtime.Object) (*unversioned.ListMeta, error) {
err = runtime.FieldPtr(v, "ListMeta", &meta)
return meta, err
}

// Namespace implements meta.Object for any object with an ObjectMeta typed field. Allows
// fast, direct access to metadata fields for API objects.
func (meta *ObjectMeta) GetNamespace() string { return meta.Namespace }
func (meta *ObjectMeta) SetNamespace(namespace string) { meta.Namespace = namespace }
func (meta *ObjectMeta) GetName() string { return meta.Name }
func (meta *ObjectMeta) SetName(name string) { meta.Name = name }
func (meta *ObjectMeta) GetGenerateName() string { return meta.GenerateName }
func (meta *ObjectMeta) SetGenerateName(generateName string) { meta.GenerateName = generateName }
func (meta *ObjectMeta) GetUID() types.UID { return meta.UID }
func (meta *ObjectMeta) SetUID(uid types.UID) { meta.UID = uid }
func (meta *ObjectMeta) GetResourceVersion() string { return meta.ResourceVersion }
func (meta *ObjectMeta) SetResourceVersion(version string) { meta.ResourceVersion = version }
func (meta *ObjectMeta) GetSelfLink() string { return meta.SelfLink }
func (meta *ObjectMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink }
func (meta *ObjectMeta) GetLabels() map[string]string { return meta.Labels }
func (meta *ObjectMeta) SetLabels(labels map[string]string) { meta.Labels = labels }
func (meta *ObjectMeta) GetAnnotations() map[string]string { return meta.Annotations }
func (meta *ObjectMeta) SetAnnotations(annotations map[string]string) { meta.Annotations = annotations }
9 changes: 7 additions & 2 deletions pkg/api/meta/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
Expand Down Expand Up @@ -114,7 +115,9 @@ type fakePtrInterfaceList struct {
Items *[]runtime.Object
}

func (f fakePtrInterfaceList) IsAnAPIObject() {}
func (obj fakePtrInterfaceList) GetObjectKind() unversioned.ObjectKind {
return unversioned.EmptyObjectKind
}

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

func (f fakePtrValueList) IsAnAPIObject() {}
func (obj fakePtrValueList) GetObjectKind() unversioned.ObjectKind {
return unversioned.EmptyObjectKind
}

func TestExtractListOfValuePtrs(t *testing.T) {
pl := &fakePtrValueList{
Expand Down
45 changes: 28 additions & 17 deletions pkg/api/meta/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,48 @@ type VersionInterfaces struct {
MetadataAccessor
}

// Interface lets you work with object and list metadata from any of the versioned or
type ObjectMetaAccessor interface {
GetObjectMeta() Object
}

// Object lets you work with object metadata from any of the versioned or
// internal API objects. Attempting to set or retrieve a field on an object that does
// not support that field (Name, UID, Namespace on lists) will be a no-op and return
// a default value.
// TODO: rename to ObjectInterface when we clear up these interfaces.
type Interface interface {
TypeInterface

Namespace() string
type Object interface {
GetNamespace() string
SetNamespace(namespace string)
Name() string
GetName() string
SetName(name string)
GenerateName() string
GetGenerateName() string
SetGenerateName(name string)
UID() types.UID
GetUID() types.UID
SetUID(uid types.UID)
ResourceVersion() string
GetResourceVersion() string
SetResourceVersion(version string)
SelfLink() string
GetSelfLink() string
SetSelfLink(selfLink string)
Labels() map[string]string
GetLabels() map[string]string
SetLabels(labels map[string]string)
Annotations() map[string]string
GetAnnotations() map[string]string
SetAnnotations(annotations map[string]string)
}

// TypeInterface exposes the type and APIVersion of versioned or internal API objects.
type TypeInterface interface {
APIVersion() string
// List lets you work with list metadata from any of the versioned or
// internal API objects. Attempting to set or retrieve a field on an object that does
// not support that field will be a no-op and return a default value.
type List interface {
GetResourceVersion() string
SetResourceVersion(version string)
GetSelfLink() string
SetSelfLink(selfLink string)
}

// Type exposes the type and APIVersion of versioned or internal API objects.
type Type interface {
GetAPIVersion() string
SetAPIVersion(version string)
Kind() string
GetKind() string
SetKind(kind string)
}

Expand Down
Loading

0 comments on commit 8f203a2

Please sign in to comment.