-
Notifications
You must be signed in to change notification settings - Fork 38.8k
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
os exit when option is true #76732
os exit when option is true #76732
Conversation
Hi @jiejhih. Thanks for your PR. I'm waiting for a kubernetes 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/test-infra repository. |
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.
thanks for the PR.
this code is from 1.1 (2015).
/kind bug
/priority important-longterm
/ok-to-test
@kubernetes/sig-network-pr-reviews
/assign @andrewsykim Handling exits like this (raising an error as a non-error exit signal) feels like a code smell to me, but this does appear to solve the issue. |
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.
/lgtm
Yeah it solved the issue but it can be better.
But the change will affect some places , I will create another PR to refactor this. |
cmd/kube-proxy/app/server.go
Outdated
@@ -557,7 +557,7 @@ func (s *ProxyServer) Run() error { | |||
if encounteredError { | |||
return errors.New("encountered an error while tearing down rules") | |||
} | |||
return nil | |||
return errors.New("cleaup and exit") |
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.
Agree with @vllry, this seems like a bit of a code smell, we're effectively saying that nil errors are invalid. I personally think we should fix/refactor properly in this PR. I'm wondering if it would be cleaner if we pulled the clean up & exit logic out of Run()
and ran the clean up check prior, that would reduce some of the complexity with passing errors through channels.
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.
That is a good way!
It can run clean up & exit logic before run proxy server if success then os exit else return the error message.
I will refactor in this PR.
kubernetes/cmd/kube-proxy/app/server.go
Lines 321 to 325 in 3b12266
// run the proxy in goroutine | |
go func() { | |
err := o.proxyServer.Run() | |
o.errCh <- err | |
}() |
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.
Yeah that seems like a better approach to me, thoughts @vllry?
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.
+1 from me
I was thinking about test coverage for something like this - e2e would be messy, and unsure how to properly deal with iptables/IPVS scope in a unit test. |
2debcb5
to
84e9d12
Compare
/retest |
@andrewsykim Updated. Thanks |
cmd/kube-proxy/app/server.go
Outdated
@@ -307,6 +308,11 @@ func (o *Options) Run() error { | |||
if err != nil { | |||
return err | |||
} | |||
|
|||
if o.CleanupAndExit { | |||
return proxyServer.CleanUpAndExit() |
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.
Can we name the method the same as the flag?
func (s *ProxyServer) Run() error { | ||
// To help debugging, immediately log version | ||
klog.Infof("Version: %+v", version.Get()) | ||
// remove iptables rules and exit | ||
if s.CleanupAndExit { |
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.
can we remove the ProxyServer.CleanupAndExit
field at the same time?
@thockin Updated. PTAL. |
@andrewsykim Yeah, I have removed that field in the newest commit. Thanks |
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.
Thanks!
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JieJhih, thockin 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 |
/retest |
/test pull-kubernetes-integration |
/lgtm Thanks for iterating @jiejhih! |
/test pull-kubernetes-node-e2e |
|
||
// CleanupAndExit remove iptables rules and exit if success return nil | ||
func (s *ProxyServer) CleanupAndExit() error { | ||
encounteredError := userspace.CleanupLeftovers(s.IptInterface) |
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.
I wonder if CleanupLeftovers should return the (aggregate) error instead of returning just a boolean.
This would be useful for caller for analysis.
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.
I agree that this is a bit ugly but I don't think it'll be easy to fix. A lot of errors from CleanupLeftovers
don't warrant an early return. For what it's worth, most of the errors are still logged via klog.Error
though.
…upstream-release-1.14 Automated cherry pick of #76732: os exit when option is true
What type of PR is this?
What this PR does / why we need it:
When CleanupAndExit is true , kube-proxy doesn't exit
Related:
kubernetes/cmd/kube-proxy/app/server.go
Lines 322 to 334 in 6c55e2d
kubernetes/cmd/kube-proxy/app/server.go
Lines 553 to 561 in 6c55e2d
kubernetes/cmd/kube-proxy/app/server.go
Line 466 in 6c55e2d
Which issue(s) this PR fixes:
Fixes #76727
Special notes for your reviewer:
Does this PR introduce a user-facing change?: