← Back to Pull requests

etcdctl: refactor global flags management and simplify command initialization #21230

Open
hwdef opened this pull request with 180 lines diff across 5 files
View on GitHub
hwdef hwdef commented on Feb 01, 2026 16:19 UTC
Author

This PR is a part of: https://github.com/etcd-io/etcd/pull/20270

It prepares for subsequent unit testing.

Diff: 180 lines (+83 / -97) across 5 files Reviewer: siyuanfoundation Review duration: 385025m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.47) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 180 lines diff across 5 files
0.47
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.93 · 5 substantive comment(s)
0.93
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
90%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.311
Real PR Conversation Timeline
17 items
k8s-ci-robot k8s-ci-robot commented on Feb 01, 2026 16:19 UTC
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: <a href="https://github.com/etcd-io/etcd/pull/21230#" title="Author self-approved">hwdef</a>
Once this PR has been reviewed and has the lgtm label, please assign ahrtr for approval. For more information see the Code Review Process.

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

<details open>
Needs approval from an approver in each of these files:

  • OWNERS
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":["ahrtr"]} -->

    codecov[bot] codecov[bot] commented on Feb 02, 2026 03:31 UTC
    Bot

    Codecov Report


    :x: Patch coverage is 0% with 52 lines in your changes missing coverage. Please review.
    :white_check_mark: Project coverage is 68.39%. Comparing base (36972d6) to head (fc8bef4).
    :warning: Report is 721 commits behind head on main.

    | Files with missing lines | Patch % | Lines |
    |---|---|---|
    | etcdctl/ctlv3/command/global.go | 0.00% | 46 Missing :warning: |
    | etcdctl/ctlv3/command/util.go | 0.00% | 2 Missing :warning: |
    | etcdctl/ctlv3/ctl.go | 0.00% | 2 Missing :warning: |
    | etcdctl/ctlv3/command/diagnosis\_command.go | 0.00% | 1 Missing :warning: |
    | etcdctl/ctlv3/command/ep\_command.go | 0.00% | 1 Missing :warning: |

    <details><summary>Additional details and impacted files</summary>

    | Files with missing lines | Coverage Δ | |
    |---|---|---|
    | etcdctl/ctlv3/command/diagnosis\_command.go | 0.00% <0.00%> (ø) | |
    | etcdctl/ctlv3/command/ep\_command.go | 0.00% <0.00%> (ø) | |
    | etcdctl/ctlv3/command/util.go | 7.29% <0.00%> (+7.29%) | :arrow_up: |
    | etcdctl/ctlv3/ctl.go | 0.00% <0.00%> (ø) | |
    | etcdctl/ctlv3/command/global.go | 0.00% <0.00%> (ø) | |

    ... and 53 files with indirect coverage changes

    @@            Coverage Diff             @@
    ##             main   #21230      +/-   ##
    ==========================================
    - Coverage   68.45%   68.39%   -0.06%     
    ==========================================
      Files         429      428       -1     
      Lines       35288    35292       +4     
    ==========================================
    - Hits        24156    24139      -17     
    - Misses       9746     9754       +8     
    - Partials     1386     1399      +13     
    

    ------

    Continue to review full report in Codecov by Harness.

    Legend - Click here to learn more

    Δ = absolute <relative> (impact), ø = not affected, ? = missing data

    Powered by Codecov. Last update 36972d6...fc8bef4. Read the comment docs.

    </details>
    <details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    hwdef hwdef commented on Feb 02, 2026 03:40 UTC
    Author

    cc @siyuanfoundation

    siyuanfoundation siyuanfoundation commented on code on Feb 25, 2026 17:01 UTC
    Code Review
    etcdctl/ctlv3/command/global.go:1
    @@ -71,12 +44,98 @@ type discoveryCfg struct {
     
     var display printer = &simplePrinter{}
     
    +var newClientFunc = clientv3.New
    +
    +const (
    +	FlagEndpoints             = "endpoints"
    +	FlagDebug                 = "debug"
    +	FlagWriteOut              = "write-out"
    +	FlagHex                   = "hex"
    +	FlagDialTimeout           = "dial-timeout"
    +	FlagCommandTimeout        = "command-timeout"
    +	FlagKeepAliveTime         = "keepalive-time"
    +	FlagKeepAliveTimeout      = "keepalive-timeout"
    +	FlagMaxRequestBytes       = "max-request-bytes"
    +	FlagMaxRecvBytes          = "max-recv-bytes"
    +	FlagInsecureTransport     = "insecure-transport"
    +	FlagInsecureDiscovery     = "insecure-discovery"
    +	FlagInsecureSkipTLSVerify = "insecure-skip-tls-verify"
    +	FlagCert                  = "cert"
    +	FlagKey                   = "key"
    +	FlagCACert                = "cacert"
    +	FlagAuthJWTToken          = "auth-jwt-token"
    +	FlagUser                  = "user"
    +	FlagPassword              = "password"
    +	FlagDiscoverySRV          = "discovery-srv"
    +	FlagDiscoverySRVName      = "discovery-srv-name"
    +)
    +
    +func RegisterGlobalFlags(cmd *cobra.Command) {
    +	cmd.PersistentFlags().StringSlice(FlagEndpoints, []string{"127.0.0.1:2379"}, "gRPC endpoints")
    +	cmd.PersistentFlags().Bool(FlagDebug, false, "enable client-side debug logging")
    +	cmd.PersistentFlags().StringP(FlagWriteOut, "w", "simple", "set the output format (fields, json, protobuf, simple, table)")
    +	cmd.PersistentFlags().Bool(FlagHex, false, "print byte strings as hex encoded strings")
    +	cmd.PersistentFlags().Duration(FlagDialTimeout, 2*time.Second, "dial timeout for client connections")
    +	cmd.PersistentFlags().Duration(FlagCommandTimeout, 5*time.Second, "timeout for short running command (excluding dial timeout)")
    +	cmd.PersistentFlags().Duration(FlagKeepAliveTime, 2*time.Second, "keepalive time for client connections")
    +	cmd.PersistentFlags().Duration(FlagKeepAliveTimeout, 6*time.Second, "keepalive timeout for client connections")
    +	cmd.PersistentFlags().Int(FlagMaxRequestBytes, 0, "client-side request send limit in bytes (if 0, it defaults to 2.0 MiB (2 * 1024 * 1024).)")
    +	cmd.PersistentFlags().Int(FlagMaxRecvBytes, 0, "client-side response receive limit in bytes (if 0, it defaults to \"math.MaxInt32\")")
    +	cmd.PersistentFlags().Bool(FlagInsecureTransport, true, "disable transport security for client connections")
    +	cmd.PersistentFlags().Bool(FlagInsecureDiscovery, true, "accept insecure SRV records describing cluster endpoints")
    +	cmd.PersistentFlags().Bool(FlagInsecureSkipTLSVerify, false, "skip server certificate verification (CAUTION: this option should be enabled only for testing purposes)")
    +	cmd.PersistentFlags().String(FlagCert, "", "identify secure client using this TLS certificate file")
    +	cmd.PersistentFlags().String(FlagKey, "", "identify secure client using this TLS key file")
    +	cmd.PersistentFlags().String(FlagCACert, "", "verify certificates of TLS-enabled secure servers using this CA bundle")
    +	cmd.PersistentFlags().String(FlagAuthJWTToken, "", "JWT token used for authentication (if this option is used, --user and --password should not be set)")
    +	cmd.PersistentFlags().String(FlagUser, "", "username[:password] for authentication (prompt if password is not supplied)")
    +	cmd.PersistentFlags().String(FlagPassword, "", "password for authentication (if this option is used, --user option shouldn't include password)")
    +	cmd.PersistentFlags().StringP(FlagDiscoverySRV, "d", "", "domain name to query for SRV records describing cluster endpoints")
    +	cmd.PersistentFlags().String(FlagDiscoverySRVName, "", "service name to query when using DNS discovery")
    +}
    +
    +type ClientFactory func(clientv3.Config) (*clientv3.Client, error)
    +
    +type clientFactoryKey struct{}
    +
    +// WithClientFactory attaches a custom client factory to the provided context.

    Is this needed for the refactor? I think it is only related to the fake client testing. Let's focus on the refactor only in this PR.

    siyuanfoundation siyuanfoundation commented on code on Feb 25, 2026 17:01 UTC
    Code Review
    etcdctl/ctlv3/command/fakeclient/client.go:1
    @@ -0,0 +1,87 @@
    +// Copyright 2026 The etcd Authors

    Is this needed for the refactor? I think it is only related to the fake client testing. Let's focus on the refactor only in this PR.

    hwdef hwdef commented on Feb 26, 2026 06:45 UTC
    Author

    @siyuanfoundation Thanks for your replay. I have deleted the unnecessary code.

    siyuanfoundation siyuanfoundation commented on Mar 12, 2026 14:26 UTC
    Contributor

    Overall I think the PR looks good. And not using GlobalFlags is beneficial for future changes of adding a cmd based on fake client.
    @hwdef Can you squash the commits?

    hwdef hwdef commented on Mar 13, 2026 03:39 UTC
    Author

    Thank you for your reply. I have already squashed the commits.

    k8s-ci-robot k8s-ci-robot commented on May 02, 2026 05:47 UTC
    Contributor

    PR needs rebase.

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

    akstron akstron commented on Jul 24, 2026 16:38 UTC
    Contributor

    Hi @siyuanfoundation , I wanted to work on this issue: https://github.com/etcd-io/etcd/issues/20171 and came across this PR while exploring it. I can see that this PR is ready to be merged but went stale (not sure of the reason). Can we merge this PR and I can start working on rest of the pieces?

    hwdef hwdef commented on Jul 27, 2026 06:54 UTC
    Author

    If we need to continue with this PR, I can rebase the master to resolve the conflicts.

    akstron akstron commented on Jul 27, 2026 12:05 UTC
    Contributor

    @hwdef if you want I can cherry-pick your commits and use them (if you don't plan to work on it)? This way I won't be taking credit for your commits

    hwdef hwdef commented on Jul 28, 2026 02:25 UTC
    Author

    I suggest waiting for the reviewer's response; otherwise, submitting a pull request will be pointless.

    ivanvc ivanvc commented on code on Jul 30, 2026 05:04 UTC
    Code Review
    etcdctl/ctlv3/command/global.go:1
    @@ -30,39 +30,11 @@ import (
     
     	"go.etcd.io/etcd/client/pkg/v3/logutil"
     	"go.etcd.io/etcd/client/pkg/v3/srv"
    -	"go.etcd.io/etcd/client/pkg/v3/transport"
     	clientv3 "go.etcd.io/etcd/client/v3"
     	"go.etcd.io/etcd/pkg/v3/cobrautl"
     	"go.etcd.io/etcd/pkg/v3/flags"
     )
     
    -// GlobalFlags are flags that defined globally
    -// and are inherited to all sub-commands.
    -type GlobalFlags struct {

    What would be our stance on exported structs in the CLI? Should we consider deprecation rather than removal?

    ivanvc ivanvc commented on Jul 30, 2026 05:06 UTC
    Reviewer

    I don't see a reason to hold this up or reassign. We only need a rebase, and I would like to clear up the question I left.

    akstron akstron commented on code on Aug 04, 2026 06:33 UTC
    Code Review
    etcdctl/ctlv3/command/global.go:1
    @@ -30,39 +30,11 @@ import (
     
     	"go.etcd.io/etcd/client/pkg/v3/logutil"
     	"go.etcd.io/etcd/client/pkg/v3/srv"
    -	"go.etcd.io/etcd/client/pkg/v3/transport"
     	clientv3 "go.etcd.io/etcd/client/v3"
     	"go.etcd.io/etcd/pkg/v3/cobrautl"
     	"go.etcd.io/etcd/pkg/v3/flags"
     )
     
    -// GlobalFlags are flags that defined globally
    -// and are inherited to all sub-commands.
    -type GlobalFlags struct {

    I believe it should go via the deprecation path, but I would rely on @hwdef @siyuanfoundation for a decision here

    Assignees
    hwdef hwdef
    Labels
    risk: low confidence: 90% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 46.9% (MEDIUM) · Higher = larger blast radius
    46.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90% · Lower = rushed or shallow review
    90%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.7% · Safe to merge
    4.7%
    Repository