mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #1197 from lavalamp/fixApi
Rename Object to EmbeddedObject
This commit is contained in:
commit
8e10ee5169
@ -552,5 +552,5 @@ type WatchEvent struct {
|
|||||||
|
|
||||||
// For added or modified objects, this is the new object; for deleted objects,
|
// For added or modified objects, this is the new object; for deleted objects,
|
||||||
// it's the state of the object immediately prior to its deletion.
|
// it's the state of the object immediately prior to its deletion.
|
||||||
Object runtime.Object
|
Object runtime.EmbeddedObject
|
||||||
}
|
}
|
||||||
|
@ -553,5 +553,5 @@ type WatchEvent struct {
|
|||||||
|
|
||||||
// For added or modified objects, this is the new object; for deleted objects,
|
// For added or modified objects, this is the new object; for deleted objects,
|
||||||
// it's the state of the object immediately prior to its deletion.
|
// it's the state of the object immediately prior to its deletion.
|
||||||
Object runtime.Object
|
Object runtime.EmbeddedObject
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ func (w *WatchServer) HandleWS(ws *websocket.Conn) {
|
|||||||
}
|
}
|
||||||
err := websocket.JSON.Send(ws, &api.WatchEvent{
|
err := websocket.JSON.Send(ws, &api.WatchEvent{
|
||||||
Type: event.Type,
|
Type: event.Type,
|
||||||
Object: runtime.Object{event.Object},
|
Object: runtime.EmbeddedObject{event.Object},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Client disconnect.
|
// Client disconnect.
|
||||||
@ -160,7 +160,7 @@ func (self *WatchServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
err := encoder.Encode(&api.WatchEvent{
|
err := encoder.Encode(&api.WatchEvent{
|
||||||
Type: event.Type,
|
Type: event.Type,
|
||||||
Object: runtime.Object{event.Object},
|
Object: runtime.EmbeddedObject{event.Object},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Client disconnect.
|
// Client disconnect.
|
||||||
|
@ -401,7 +401,7 @@ func TestWatch(t *testing.T) {
|
|||||||
|
|
||||||
encoder := json.NewEncoder(w)
|
encoder := json.NewEncoder(w)
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
encoder.Encode(&api.WatchEvent{item.t, runtime.Object{item.obj}})
|
encoder.Encode(&api.WatchEvent{item.t, runtime.EmbeddedObject{item.obj}})
|
||||||
flusher.Flush()
|
flusher.Flush()
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
@ -45,14 +45,14 @@ func TestEventToPods(t *testing.T) {
|
|||||||
input: watch.Event{
|
input: watch.Event{
|
||||||
Object: &api.ContainerManifestList{
|
Object: &api.ContainerManifestList{
|
||||||
Items: []api.ContainerManifest{
|
Items: []api.ContainerManifest{
|
||||||
api.ContainerManifest{ID: "foo"},
|
{ID: "foo"},
|
||||||
api.ContainerManifest{ID: "bar"},
|
{ID: "bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pods: []kubelet.Pod{
|
pods: []kubelet.Pod{
|
||||||
kubelet.Pod{Name: "foo", Manifest: api.ContainerManifest{ID: "foo"}},
|
{Name: "foo", Manifest: api.ContainerManifest{ID: "foo"}},
|
||||||
kubelet.Pod{Name: "bar", Manifest: api.ContainerManifest{ID: "bar"}},
|
{Name: "bar", Manifest: api.ContainerManifest{ID: "bar"}},
|
||||||
},
|
},
|
||||||
fail: false,
|
fail: false,
|
||||||
},
|
},
|
||||||
@ -60,14 +60,14 @@ func TestEventToPods(t *testing.T) {
|
|||||||
input: watch.Event{
|
input: watch.Event{
|
||||||
Object: &api.ContainerManifestList{
|
Object: &api.ContainerManifestList{
|
||||||
Items: []api.ContainerManifest{
|
Items: []api.ContainerManifest{
|
||||||
api.ContainerManifest{ID: ""},
|
{ID: ""},
|
||||||
api.ContainerManifest{ID: ""},
|
{ID: ""},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pods: []kubelet.Pod{
|
pods: []kubelet.Pod{
|
||||||
kubelet.Pod{Name: "1", Manifest: api.ContainerManifest{ID: ""}},
|
{Name: "1", Manifest: api.ContainerManifest{ID: ""}},
|
||||||
kubelet.Pod{Name: "2", Manifest: api.ContainerManifest{ID: ""}},
|
{Name: "2", Manifest: api.ContainerManifest{ID: ""}},
|
||||||
},
|
},
|
||||||
fail: false,
|
fail: false,
|
||||||
},
|
},
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
// embedded within other API types.
|
// embedded within other API types.
|
||||||
|
|
||||||
// UnmarshalJSON implements the json.Unmarshaler interface.
|
// UnmarshalJSON implements the json.Unmarshaler interface.
|
||||||
func (a *Object) UnmarshalJSON(b []byte) error {
|
func (a *EmbeddedObject) UnmarshalJSON(b []byte) error {
|
||||||
// Handle JSON's "null": Decode() doesn't expect it.
|
// Handle JSON's "null": Decode() doesn't expect it.
|
||||||
if len(b) == 4 && string(b) == "null" {
|
if len(b) == 4 && string(b) == "null" {
|
||||||
a.Object = nil
|
a.Object = nil
|
||||||
@ -42,7 +42,7 @@ func (a *Object) UnmarshalJSON(b []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON implements the json.Marshaler interface.
|
// MarshalJSON implements the json.Marshaler interface.
|
||||||
func (a Object) MarshalJSON() ([]byte, error) {
|
func (a EmbeddedObject) MarshalJSON() ([]byte, error) {
|
||||||
if a.Object == nil {
|
if a.Object == nil {
|
||||||
// Encode unset/nil objects as JSON's "null".
|
// Encode unset/nil objects as JSON's "null".
|
||||||
return []byte("null"), nil
|
return []byte("null"), nil
|
||||||
@ -52,7 +52,7 @@ func (a Object) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetYAML implements the yaml.Setter interface.
|
// SetYAML implements the yaml.Setter interface.
|
||||||
func (a *Object) SetYAML(tag string, value interface{}) bool {
|
func (a *EmbeddedObject) SetYAML(tag string, value interface{}) bool {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
a.Object = nil
|
a.Object = nil
|
||||||
return true
|
return true
|
||||||
@ -76,7 +76,7 @@ func (a *Object) SetYAML(tag string, value interface{}) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetYAML implements the yaml.Getter interface.
|
// GetYAML implements the yaml.Getter interface.
|
||||||
func (a Object) GetYAML() (tag string, value interface{}) {
|
func (a EmbeddedObject) GetYAML() (tag string, value interface{}) {
|
||||||
if a.Object == nil {
|
if a.Object == nil {
|
||||||
value = "null"
|
value = "null"
|
||||||
return
|
return
|
@ -22,18 +22,18 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestObject(t *testing.T) {
|
func TestEmbeddedObject(t *testing.T) {
|
||||||
type EmbeddedTest struct {
|
type EmbeddedTest struct {
|
||||||
JSONBase `yaml:",inline" json:",inline"`
|
JSONBase `yaml:",inline" json:",inline"`
|
||||||
Object Object `yaml:"object,omitempty" json:"object,omitempty"`
|
Object EmbeddedObject `yaml:"object,omitempty" json:"object,omitempty"`
|
||||||
EmptyObject Object `yaml:"emptyObject,omitempty" json:"emptyObject,omitempty"`
|
EmptyObject EmbeddedObject `yaml:"emptyObject,omitempty" json:"emptyObject,omitempty"`
|
||||||
}
|
}
|
||||||
AddKnownTypes("", EmbeddedTest{})
|
AddKnownTypes("", EmbeddedTest{})
|
||||||
AddKnownTypes("v1beta1", EmbeddedTest{})
|
AddKnownTypes("v1beta1", EmbeddedTest{})
|
||||||
|
|
||||||
outer := &EmbeddedTest{
|
outer := &EmbeddedTest{
|
||||||
JSONBase: JSONBase{ID: "outer"},
|
JSONBase: JSONBase{ID: "outer"},
|
||||||
Object: Object{
|
Object: EmbeddedObject{
|
||||||
&EmbeddedTest{
|
&EmbeddedTest{
|
||||||
JSONBase: JSONBase{ID: "inner"},
|
JSONBase: JSONBase{ID: "inner"},
|
||||||
},
|
},
|
@ -42,7 +42,7 @@ type JSONBase struct {
|
|||||||
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
|
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object has appropriate encoder and decoder functions, such that on the wire, it's
|
// EmbeddedObject has appropriate encoder and decoder functions, such that on the wire, it's
|
||||||
// stored as a []byte, but in memory, the contained object is accessable as an interface{}
|
// stored as a []byte, but in memory, the contained object is accessable as an interface{}
|
||||||
// via the Get() function. Only objects having a JSONBase may be stored via Object.
|
// via the Get() function. Only objects having a JSONBase may be stored via Object.
|
||||||
// The purpose of this is to allow an API object of type known only at runtime to be
|
// The purpose of this is to allow an API object of type known only at runtime to be
|
||||||
@ -52,7 +52,7 @@ type JSONBase struct {
|
|||||||
//
|
//
|
||||||
// Note that objects will be serialized into the api package's default external versioned type;
|
// Note that objects will be serialized into the api package's default external versioned type;
|
||||||
// this should be fixed in the future to use the version of the current Codec instead.
|
// this should be fixed in the future to use the version of the current Codec instead.
|
||||||
type Object struct {
|
type EmbeddedObject struct {
|
||||||
Object interface{}
|
Object interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ func TestDecoder(t *testing.T) {
|
|||||||
|
|
||||||
expect := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
expect := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
||||||
go func() {
|
go func() {
|
||||||
err := encoder.Encode(api.WatchEvent{watch.Added, runtime.Object{expect}})
|
err := encoder.Encode(api.WatchEvent{watch.Added, runtime.EmbeddedObject{expect}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error %v", err)
|
t.Errorf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user