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

os exit when option is true #76732

Merged
merged 2 commits into from
Apr 27, 2019
Merged

Conversation

LexCC
Copy link
Contributor

@LexCC LexCC commented Apr 17, 2019

What type of PR is this?

/kind bug

What this PR does / why we need it:
When CleanupAndExit is true , kube-proxy doesn't exit
Related:

go func() {
err := o.proxyServer.Run()
o.errCh <- err
}()
for {
select {
case err := <-o.errCh:
if err != nil {
return err
}
}
}

if s.CleanupAndExit {
encounteredError := userspace.CleanupLeftovers(s.IptInterface)
encounteredError = iptables.CleanupLeftovers(s.IptInterface) || encounteredError
encounteredError = ipvs.CleanupLeftovers(s.IpvsInterface, s.IptInterface, s.IpsetInterface, s.CleanupIPVS) || encounteredError
if encounteredError {
return errors.New("encountered an error while tearing down rules")
}
return nil
}

klog.Fatal(opts.Run())

Which issue(s) this PR fixes:

Fixes #76727

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

kube-proxy: os exit when CleanupAndExit is set to true

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 17, 2019
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 17, 2019
Copy link
Member

@neolit123 neolit123 left a 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

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. sig/network Categorizes an issue or PR as relevant to SIG Network. kind/bug Categorizes issue or PR as related to a bug. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 17, 2019
@vllry
Copy link
Contributor

vllry commented Apr 19, 2019

/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.

Copy link
Member

@dixudx dixudx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 19, 2019
@LexCC
Copy link
Contributor Author

LexCC commented Apr 19, 2019

@vllry

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.

Yeah it solved the issue but it can be better.
I think it can be something like this.
errCh chan error change into errCh chan errChannel

type errChannel struct {
      Message string
      Err           error
 }

But the change will affect some places , I will create another PR to refactor this.

@@ -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")
Copy link
Member

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.

Copy link
Contributor Author

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.

// run the proxy in goroutine
go func() {
err := o.proxyServer.Run()
o.errCh <- err
}()

Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 from me

@vllry
Copy link
Contributor

vllry commented Apr 19, 2019

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.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 19, 2019
@LexCC LexCC force-pushed the proxy/server branch 2 times, most recently from 2debcb5 to 84e9d12 Compare April 23, 2019 12:58
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Apr 23, 2019
@LexCC
Copy link
Contributor Author

LexCC commented Apr 23, 2019

/retest

@LexCC
Copy link
Contributor Author

LexCC commented Apr 23, 2019

@andrewsykim Updated. Thanks

@@ -307,6 +308,11 @@ func (o *Options) Run() error {
if err != nil {
return err
}

if o.CleanupAndExit {
return proxyServer.CleanUpAndExit()
Copy link
Member

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 {
Copy link
Member

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?

@LexCC
Copy link
Contributor Author

LexCC commented Apr 24, 2019

@thockin Updated. PTAL.

@andrewsykim
Copy link
Member

andrewsykim commented Apr 24, 2019

@jiejhih I think @thockin mentioned to also remove the field CleanupAndExit field from the ProxyServer struct. See here (ideally in a separate commit please)

@LexCC
Copy link
Contributor Author

LexCC commented Apr 24, 2019

@andrewsykim Yeah, I have removed that field in the newest commit. Thanks
https://github.com/kubernetes/kubernetes/pull/76732/files#diff-cf93bbed37202b7d58b5841f07ddd89fL500

Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 26, 2019
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 26, 2019
@LexCC
Copy link
Contributor Author

LexCC commented Apr 27, 2019

/retest

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 27, 2019
@LexCC
Copy link
Contributor Author

LexCC commented Apr 27, 2019

/test pull-kubernetes-integration

@andrewsykim
Copy link
Member

/lgtm

Thanks for iterating @jiejhih!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 27, 2019
@LexCC
Copy link
Contributor Author

LexCC commented Apr 27, 2019

/test pull-kubernetes-node-e2e

@k8s-ci-robot k8s-ci-robot merged commit a0b8d1c into kubernetes:master Apr 27, 2019

// CleanupAndExit remove iptables rules and exit if success return nil
func (s *ProxyServer) CleanupAndExit() error {
encounteredError := userspace.CleanupLeftovers(s.IptInterface)
Copy link
Contributor

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.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/network Categorizes an issue or PR as relevant to SIG Network. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kube-proxy does not exit after --cleanup
9 participants