mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-08 04:32:37 +00:00
Allow clients to determine the difference between create or update on PUT
PUT allows an object to be created (http 201). This allows REST code to indicate an object has been created and clients to react to it. APIServer now deals with <-chan RESTResult instead of <-chan runtime.Object, allowing more data to be passed through.
This commit is contained in:
@@ -272,7 +272,7 @@ func (r *Request) Do() Result {
|
||||
if err != nil {
|
||||
return Result{err: err}
|
||||
}
|
||||
respBody, err := r.c.doRequest(req)
|
||||
respBody, created, err := r.c.doRequest(req)
|
||||
if err != nil {
|
||||
if s, ok := err.(APIStatus); ok {
|
||||
status := s.Status()
|
||||
@@ -292,14 +292,16 @@ func (r *Request) Do() Result {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result{respBody, err, r.c.Codec}
|
||||
return Result{respBody, created, err, r.c.Codec}
|
||||
}
|
||||
}
|
||||
|
||||
// Result contains the result of calling Request.Do().
|
||||
type Result struct {
|
||||
body []byte
|
||||
err error
|
||||
body []byte
|
||||
created bool
|
||||
err error
|
||||
|
||||
codec runtime.Codec
|
||||
}
|
||||
|
||||
@@ -324,6 +326,13 @@ func (r Result) Into(obj runtime.Object) error {
|
||||
return r.codec.DecodeInto(r.body, obj)
|
||||
}
|
||||
|
||||
// WasCreated updates the provided bool pointer to whether the server returned
|
||||
// 201 created or a different response.
|
||||
func (r Result) WasCreated(wasCreated *bool) Result {
|
||||
*wasCreated = r.created
|
||||
return r
|
||||
}
|
||||
|
||||
// Error returns the error executing the request, nil if no error occurred.
|
||||
func (r Result) Error() error {
|
||||
return r.err
|
||||
|
Reference in New Issue
Block a user