Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix k8s memory leak #2166

Merged
merged 1 commit into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion util/kubernetes/api/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 11 additions & 10 deletions util/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down