mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Improve the output of the swagger API for watch events
Stopgap to improve this prior to converting watch resources to versioned objects.
This commit is contained in:
parent
d2f4734657
commit
7a6b2ec227
@ -357,6 +357,12 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||||||
if err := addObjectParams(ws, route, versionedListOptions); err != nil {
|
if err := addObjectParams(ws, route, versionedListOptions); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
switch {
|
||||||
|
case isLister && isWatcher:
|
||||||
|
route.Doc("list or watch objects of kind " + kind)
|
||||||
|
case isWatcher:
|
||||||
|
route.Doc("watch objects of kind " + kind)
|
||||||
|
}
|
||||||
addParams(route, action.Params)
|
addParams(route, action.Params)
|
||||||
ws.Route(route)
|
ws.Route(route)
|
||||||
case "PUT": // Update a resource.
|
case "PUT": // Update a resource.
|
||||||
@ -405,7 +411,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||||||
Doc("watch changes to an object of kind " + kind).
|
Doc("watch changes to an object of kind " + kind).
|
||||||
Operation("watch" + kind).
|
Operation("watch" + kind).
|
||||||
Produces("application/json").
|
Produces("application/json").
|
||||||
Writes(watchjson.NewWatchEvent())
|
Writes(watchjson.WatchEvent{})
|
||||||
if err := addObjectParams(ws, route, versionedListOptions); err != nil {
|
if err := addObjectParams(ws, route, versionedListOptions); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -418,7 +424,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||||||
Doc("watch individual changes to a list of " + kind).
|
Doc("watch individual changes to a list of " + kind).
|
||||||
Operation("watch" + kind + "list").
|
Operation("watch" + kind + "list").
|
||||||
Produces("application/json").
|
Produces("application/json").
|
||||||
Writes(watchjson.NewWatchEvent())
|
Writes(watchjson.WatchEvent{})
|
||||||
if err := addObjectParams(ws, route, versionedListOptions); err != nil {
|
if err := addObjectParams(ws, route, versionedListOptions); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func NewDecoder(r io.ReadCloser, codec runtime.Codec) *Decoder {
|
|||||||
// Decode blocks until it can return the next object in the writer. Returns an error
|
// Decode blocks until it can return the next object in the writer. Returns an error
|
||||||
// if the writer is closed or an object can't be decoded.
|
// if the writer is closed or an object can't be decoded.
|
||||||
func (d *Decoder) Decode() (watch.EventType, runtime.Object, error) {
|
func (d *Decoder) Decode() (watch.EventType, runtime.Object, error) {
|
||||||
var got watchEvent
|
var got WatchEvent
|
||||||
if err := d.decoder.Decode(&got); err != nil {
|
if err := d.decoder.Decode(&got); err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ func TestDecoder(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
if err := encoder.Encode(&watchEvent{eventType, runtime.RawExtension{json.RawMessage(data)}}); err != nil {
|
if err := encoder.Encode(&WatchEvent{eventType, runtime.RawExtension{json.RawMessage(data)}}); err != nil {
|
||||||
t.Errorf("Unexpected error %v", err)
|
t.Errorf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
in.Close()
|
in.Close()
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Encoder implements the json.Encoder interface for io.Writers that
|
// Encoder implements the json.Encoder interface for io.Writers that
|
||||||
// should serialize watchEvent objects into JSON. It will encode any object
|
// should serialize WatchEvent objects into JSON. It will encode any object
|
||||||
// registered in the supplied codec and return an error otherwies.
|
// registered in the supplied codec and return an error otherwies.
|
||||||
type Encoder struct {
|
type Encoder struct {
|
||||||
w io.Writer
|
w io.Writer
|
||||||
|
@ -25,21 +25,18 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||||
)
|
)
|
||||||
|
|
||||||
// watchEvent objects are streamed from the api server in response to a watch request.
|
// WatchEvent objects are streamed from the api server in response to a watch request.
|
||||||
// These are not API objects and are unversioned today.
|
// These are not API objects and may not be changed in a backward-incompatible way.
|
||||||
type watchEvent struct {
|
// TODO: move to a public, versioned object now that RawExtension conversions are possible
|
||||||
// The type of the watch event; added, modified, or deleted.
|
// in the schema.
|
||||||
Type watch.EventType `json:"type,omitempty"`
|
type WatchEvent struct {
|
||||||
|
// The type of the watch event; added, modified, deleted, or error.
|
||||||
|
Type watch.EventType `json:"type,omitempty" description:"the type of watch event; may be ADDED, MODIFIED, DELETED, or ERROR"`
|
||||||
|
|
||||||
// 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.
|
||||||
// For errors, it's an api.Status.
|
// For errors, it's an api.Status.
|
||||||
Object runtime.RawExtension `json:"object,omitempty"`
|
Object runtime.RawExtension `json:"object,omitempty" description:"the object being watched; will match the type of the resource endpoint or be a Status object if the type is ERROR"`
|
||||||
}
|
|
||||||
|
|
||||||
// NewWatchEvent returns the serialization form of watchEvent for structured schemas
|
|
||||||
func NewWatchEvent() interface{} {
|
|
||||||
return &watchEvent{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object converts a watch.Event into an appropriately serializable JSON object
|
// Object converts a watch.Event into an appropriately serializable JSON object
|
||||||
@ -52,5 +49,5 @@ func Object(codec runtime.Codec, event *watch.Event) (interface{}, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &watchEvent{event.Type, runtime.RawExtension{json.RawMessage(data)}}, nil
|
return &WatchEvent{event.Type, runtime.RawExtension{json.RawMessage(data)}}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user