-
Notifications
You must be signed in to change notification settings - Fork 38
🐛 fix: add registry client TLS connection idle timeout #389
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: add registry client TLS connection idle timeout #389
Conversation
Welcome @mhrabovcin! |
Hi @mhrabovcin. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/ok-to-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes seem reasonable! Do you think it would be feasible to add some unit tests given that we have quite a few more functions and if/else branches?
18fc46c
to
83da56f
Compare
34852b7
to
85b8c39
Compare
Thanks for the review @Jont828 . I've added unit tests for the refactored function:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few minor comments. After that, please squash commits and we will be good to go!
return registry.NewClient(opts...) | ||
} | ||
|
||
func newClientTLS(caFile string, insecureSkipTLSverify bool) (*tls.Config, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a doc comment for this function?
return &config, nil | ||
} | ||
|
||
func certPoolFromFile(filename string) (*x509.CertPool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a doc comment for this as well?
internal/helm_client.go
Outdated
func certPoolFromFile(filename string) (*x509.CertPool, error) { | ||
b, err := os.ReadFile(filename) | ||
if err != nil { | ||
return nil, errors.Errorf("can't read CA file: %v", filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, errors.Errorf("can't read CA file: %v", filename) | |
return nil, errors.Wrapf(err, "...") |
Just so we don't lose the original error message
e7a2929
to
4efe7c4
Compare
4efe7c4
to
6432b3f
Compare
Thanks for working on this! /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Jont828, mhrabovcin The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
Currently the controller runtime creates a new registry client for interaction with OCI registries when
HelmReleaseProxy
orHelmChartProxy
is reconciled. The client is not being reused and is discarded after the reconciliation loop for a single item exits. When a TLS configuration is provided in k8s resources spec the controller uses helm libraryNewRegistryClientWithTLS
function, that creates ahttp.Client
andhttp.Transport
on for each registry client instance.This causes a problem with registry servers that won't close the http connection. The
http.Transport
implementation will keep the connection open and ready for re-use. This can result in many leaked goroutines with TCP connections opened in memory with no chance of reusing those.In our tests when the controller was handling 100s
HelmReleaseProxy
andHelmChartProxy
objects the memory consumption was high, and the controller hit a limit of maximum number of ephemeral TCP ports for outgoing TCP connections.By adding the
IdleConnTimeout
the TCP connections are correctly closed by the client and goroutines are cleaned up. Example:Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #