Skip to content

Conversation

@majiayu000
Copy link
Contributor

@majiayu000 majiayu000 commented Jan 4, 2026

What\n- funnel startEtcdOrProxyV2 exit paths through a single osutil.Exit call\n- convert config parsing help/version/flag exits into exit errors\n- add a small exit code helper for etcdmain\n\n## Why\nFollow-up to #21032 (step 2 after #21062) to unify exit calls.\n\n## Testing\n- not run (not requested)

@k8s-ci-robot
Copy link

Hi @majiayu000. Thanks for your PR.

I'm waiting for a github.com 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.

Details

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.

@serathius
Copy link
Member

This doesn't follow the proposal at #21032 (comment), please align.

@majiayu000 majiayu000 force-pushed the unify-exit-calls-v2 branch from 6e32546 to 68a3f58 Compare January 5, 2026 16:17
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: majiayu000, serathius

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@serathius
Copy link
Member

Please sign the DCO

@majiayu000 majiayu000 force-pushed the unify-exit-calls-v2 branch from 68a3f58 to eeb0047 Compare January 5, 2026 16:40
@majiayu000 majiayu000 force-pushed the unify-exit-calls-v2 branch from eeb0047 to 2f8b52b Compare January 5, 2026 16:42
@majiayu000
Copy link
Contributor Author

Sorry for the dco, caused by a new computer.

@serathius
Copy link
Member

/ok-to-test

@serathius
Copy link
Member

/cc @fuweid @ahrtr

@k8s-ci-robot k8s-ci-robot requested review from ahrtr and fuweid January 5, 2026 16:58
@k8s-ci-robot
Copy link

@majiayu000: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-etcd-verify 2f8b52b link true /test pull-etcd-verify

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

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. I understand the commands that are listed here.

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

❌ Patch coverage is 0% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.48%. Comparing base (a438759) to head (2f8b52b).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
server/etcdmain/etcd.go 0.00% 29 Missing ⚠️
server/etcdmain/config.go 0.00% 4 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
server/etcdmain/config.go 72.51% <0.00%> (ø)
server/etcdmain/etcd.go 0.00% <0.00%> (ø)

... and 17 files with indirect coverage changes

@@            Coverage Diff             @@
##             main   #21081      +/-   ##
==========================================
+ Coverage   68.44%   68.48%   +0.03%     
==========================================
  Files         429      429              
  Lines       35281    35303      +22     
==========================================
+ Hits        24149    24178      +29     
+ Misses       9732     9729       -3     
+ Partials     1400     1396       -4     

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a438759...2f8b52b. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@serathius
Copy link
Member

Please fix:

../server/etcdmain/config.go:133:49: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
		return fmt.Errorf("%w: %v", ErrArgumentError, perr)
		                                              ^
../server/etcdmain/etcd.go:82:75: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
			return fmt.Errorf("%w: error creating zap logger %v", ErrGeneralError, zapError)
			                                                                       ^
../server/etcdmain/etcd.go:94:72: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
		return fmt.Errorf("%w: failed to verify flags %v", ErrArgumentError, err)
		                                                                     ^
../server/etcdmain/etcd.go:166:66: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
			return fmt.Errorf("%w: discovery failed %v", ErrGeneralError, err)
			                                                              ^
../server/etcdmain/etcd.go:180:65: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
			return fmt.Errorf("%w: failed to start %v", ErrGeneralError, err)
			                                                             ^
../server/etcdmain/etcd.go:183:65: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
		return fmt.Errorf("%w: discovery failed %v", ErrGeneralError, err)
		                                                              ^
../server/etcdmain/etcd.go:199:64: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
		return fmt.Errorf("%w: listener failed %v", ErrGeneralError, lerr)
		```

case errors.Is(perr, flag.ErrHelp):
fmt.Println(flagsline)
os.Exit(0)
return ErrExitOK
Copy link
Member

@fuweid fuweid Jan 6, 2026

Choose a reason for hiding this comment

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

what about returning nil here?
without ErrExitOK, it's easy to handle error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment!

The reason for using ErrExitOK instead of nil is to control the execution flow.

In startEtcdOrProxyV2Error, we call cfg.parse(args). If cfg.parse returns nil (as suggested for the --help case), the function would assume everything is fine and continue to execute the subsequent logic (initializing the logger and eventually calling startEtcd to boot up the server).

For --help and --version, we want to terminate the flow immediately and exit with 0. Since we wanted to avoid calling os.Exit deeply inside config.go, returning a specific sentinel error ErrExitOK allows us to bubble up this "exit request" to the main entry point and handle it gracefully there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants