mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
fix k8s api memory leak (#2166)
This commit is contained in:
parent
8c9c7a5927
commit
32cb1b435b
@ -59,7 +59,10 @@ func (r *Response) Into(data interface{}) error {
|
||||
}
|
||||
|
||||
func (r *Response) Close() error {
|
||||
return r.res.Body.Close()
|
||||
if r.res != nil {
|
||||
return r.res.Body.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func newResponse(res *http.Response, err error) *Response {
|
||||
|
@ -64,15 +64,15 @@ func (c *client) Create(r *Resource, opts ...CreateOption) error {
|
||||
if err := renderTemplate(r.Kind, b, r.Value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return api.NewRequest(c.opts).
|
||||
resp := api.NewRequest(c.opts).
|
||||
Post().
|
||||
SetHeader("Content-Type", "application/yaml").
|
||||
Namespace(options.Namespace).
|
||||
Resource(r.Kind).
|
||||
Body(b).
|
||||
Do().
|
||||
Error()
|
||||
Do()
|
||||
resp.Close()
|
||||
return resp.Error()
|
||||
}
|
||||
|
||||
var (
|
||||
@ -160,8 +160,9 @@ func (c *client) Update(r *Resource, opts ...UpdateOption) error {
|
||||
default:
|
||||
return errors.New("unsupported resource")
|
||||
}
|
||||
|
||||
return req.Do().Error()
|
||||
resp := req.Do()
|
||||
resp.Close()
|
||||
return resp.Error()
|
||||
}
|
||||
|
||||
// Delete removes API object
|
||||
@ -172,14 +173,14 @@ func (c *client) Delete(r *Resource, opts ...DeleteOption) error {
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
return api.NewRequest(c.opts).
|
||||
resp := api.NewRequest(c.opts).
|
||||
Delete().
|
||||
Resource(r.Kind).
|
||||
Name(r.Name).
|
||||
Namespace(options.Namespace).
|
||||
Do().
|
||||
Error()
|
||||
Do()
|
||||
resp.Close()
|
||||
return resp.Error()
|
||||
}
|
||||
|
||||
// List lists API objects and stores the result in r
|
||||
|
Loading…
Reference in New Issue
Block a user