← Back to Pull requests

fix(controller): parse etcdOptions consistently and normalize '--flag value' #574

Merged
ahrtr merged 7 files (224 lines) on Nov 26, 2026 13:38 UTC
View on GitHub
ahrtr ahrtr commented on Nov 25, 2026 17:53 UTC
Author

For each item in the EtcdOptions, we accept the following four formats:

  • "--flag=value"

  • "--flag value"

  • "--flag" "value"

  • --flag // for bool flag
  • If users provide "--flag value", etcd will reject it since it read it as a single flag with space inside, so we need to normalize it into "--flag=value".

    This PR is finished with the help of claude code. I made some manual change, and also reviewed the change.

    cc @Abhayrkhot @silentred

    Diff: 224 lines (+192 / -32) across 7 files Reviewer: silentred Review duration: 1184m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.49) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.49 · 224 lines diff across 7 files
    0.49
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.81 · 5 substantive comment(s)
    0.81
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    86%
    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.324
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    9 items
    ahrtr ahrtr commented on Nov 25, 2026 17:59 UTC
    Author

    /test pull-etcd-operator-test

    silentred silentred approved these changes on Nov 26, 2026 01:05 UTC
    Approved Reviewer

    LGTM

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Nov 26, 2026 01:05 UTC
    Bot

    [APPROVALNOTIFIER] This PR is APPROVED

    This pull-request has been approved by: <a href="https://github.com/etcd-io/etcd-operator/pull/574#" title="Author self-approved">ahrtr</a>, <a href="https://github.com/etcd-io/etcd-operator/pull/574#pullrequestreview-6067174933" title="Approved">silentred</a>

    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:

  • ~~OWNERS~~ [ahrtr,silentred]
  • 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":[]} -->

    silentred silentred commented on code on Nov 26, 2026 02:07 UTC
    Code Review
    internal/controller/utils_test.go:1
    @@ -648,3 +648,78 @@ func TestVerifySecretHasCA(t *testing.T) {
     		assert.Contains(t, err.Error(), "cert-manager")
     	})
     }
    +
    +func TestParseEtcdOption(t *testing.T) {
    +	tests := []struct {
    +		name      string
    +		input     string
    +		wantName  string
    +		wantValue string
    +		wantHas   bool
    +	}{
    +		{name: "equals form", input: "--quota-backend-bytes=1024", wantName: "--quota-backend-bytes", wantValue: "1024", wantHas: true},
    +		{name: "space form in one element", input: "--quota-backend-bytes 1024", wantName: "--quota-backend-bytes", wantValue: "1024", wantHas: true},
    +		{name: "bare boolean flag", input: "--enable-pprof", wantName: "--enable-pprof"},
    +		{name: "space form with equals in value", input: "--initial-cluster-token a=b", wantName: "--initial-cluster-token", wantValue: "a=b", wantHas: true},
    +		{name: "equals form with space in value", input: "--flag=a b", wantName: "--flag", wantValue: "a b", wantHas: true},
    +		{name: "bare flag with trailing space", input: "--enable-pprof ", wantName: "--enable-pprof"},
    +		{name: "value containing equals", input: "--initial-cluster=a=http://x:2380", wantName: "--initial-cluster", wantValue: "a=http://x:2380", wantHas: true},
    +		{name: "empty value", input: "--flag=", wantName: "--flag", wantHas: true},
    +		{name: "value in separate element is not a value", input: "1024", wantName: "1024"},
    +	}
    +	for _, tt := range tests {
    +		t.Run(tt.name, func(t *testing.T) {
    +			name, value, has := parseEtcdOption(tt.input)
    +			assert.Equal(t, tt.wantName, name)
    +			assert.Equal(t, tt.wantValue, value)
    +			assert.Equal(t, tt.wantHas, has)
    +		})
    +	}
    +}
    +
    +func TestBackendQuotaBytes(t *testing.T) {
    +	tests := []struct {
    +		name string
    +		opts []string
    +		want int64
    +	}{
    +		{name: "unset", want: defaultBackendQuotaBytes},
    +		{name: "equals form", opts: []string{"--quota-backend-bytes=4096"}, want: 4096},
    +		{name: "space form", opts: []string{"--quota-backend-bytes 4096"}, want: 4096},
    +		{name: "other flags ignored", opts: []string{"--name=x", "--quota-backend-bytes=4096"}, want: 4096},
    +		{name: "last occurrence wins", opts: []string{"--quota-backend-bytes=1", "--quota-backend-bytes=2"}, want: 2},
    +		{name: "later invalid occurrence is skipped", opts: []string{"--quota-backend-bytes=4096", "--quota-backend-bytes=abc"}, want: 4096},
    +		{name: "invalid value falls back to default", opts: []string{"--quota-backend-bytes=abc"}, want: defaultBackendQuotaBytes},
    +		{name: "non-positive falls back to default", opts: []string{"--quota-backend-bytes=0"}, want: defaultBackendQuotaBytes},
    +		{name: "bare flag falls back to default", opts: []string{"--quota-backend-bytes"}, want: defaultBackendQuotaBytes},
    +		{name: "separate-element value is not recognised", opts: []string{"--quota-backend-bytes", "4096"}, want: defaultBackendQuotaBytes},

    Sorry I missed this. I thought []string{"--quota-backend-bytes", "4096"} is a valid case, why this should be unrecognised?

    ahrtr ahrtr commented on code on Nov 26, 2026 12:05 UTC
    Code Review
    internal/controller/utils_test.go:1
    @@ -648,3 +648,78 @@ func TestVerifySecretHasCA(t *testing.T) {
     		assert.Contains(t, err.Error(), "cert-manager")
     	})
     }
    +
    +func TestParseEtcdOption(t *testing.T) {
    +	tests := []struct {
    +		name      string
    +		input     string
    +		wantName  string
    +		wantValue string
    +		wantHas   bool
    +	}{
    +		{name: "equals form", input: "--quota-backend-bytes=1024", wantName: "--quota-backend-bytes", wantValue: "1024", wantHas: true},
    +		{name: "space form in one element", input: "--quota-backend-bytes 1024", wantName: "--quota-backend-bytes", wantValue: "1024", wantHas: true},
    +		{name: "bare boolean flag", input: "--enable-pprof", wantName: "--enable-pprof"},
    +		{name: "space form with equals in value", input: "--initial-cluster-token a=b", wantName: "--initial-cluster-token", wantValue: "a=b", wantHas: true},
    +		{name: "equals form with space in value", input: "--flag=a b", wantName: "--flag", wantValue: "a b", wantHas: true},
    +		{name: "bare flag with trailing space", input: "--enable-pprof ", wantName: "--enable-pprof"},
    +		{name: "value containing equals", input: "--initial-cluster=a=http://x:2380", wantName: "--initial-cluster", wantValue: "a=http://x:2380", wantHas: true},
    +		{name: "empty value", input: "--flag=", wantName: "--flag", wantHas: true},
    +		{name: "value in separate element is not a value", input: "1024", wantName: "1024"},
    +	}
    +	for _, tt := range tests {
    +		t.Run(tt.name, func(t *testing.T) {
    +			name, value, has := parseEtcdOption(tt.input)
    +			assert.Equal(t, tt.wantName, name)
    +			assert.Equal(t, tt.wantValue, value)
    +			assert.Equal(t, tt.wantHas, has)
    +		})
    +	}
    +}
    +
    +func TestBackendQuotaBytes(t *testing.T) {
    +	tests := []struct {
    +		name string
    +		opts []string
    +		want int64
    +	}{
    +		{name: "unset", want: defaultBackendQuotaBytes},
    +		{name: "equals form", opts: []string{"--quota-backend-bytes=4096"}, want: 4096},
    +		{name: "space form", opts: []string{"--quota-backend-bytes 4096"}, want: 4096},
    +		{name: "other flags ignored", opts: []string{"--name=x", "--quota-backend-bytes=4096"}, want: 4096},
    +		{name: "last occurrence wins", opts: []string{"--quota-backend-bytes=1", "--quota-backend-bytes=2"}, want: 2},
    +		{name: "later invalid occurrence is skipped", opts: []string{"--quota-backend-bytes=4096", "--quota-backend-bytes=abc"}, want: 4096},
    +		{name: "invalid value falls back to default", opts: []string{"--quota-backend-bytes=abc"}, want: defaultBackendQuotaBytes},
    +		{name: "non-positive falls back to default", opts: []string{"--quota-backend-bytes=0"}, want: defaultBackendQuotaBytes},
    +		{name: "bare flag falls back to default", opts: []string{"--quota-backend-bytes"}, want: defaultBackendQuotaBytes},
    +		{name: "separate-element value is not recognised", opts: []string{"--quota-backend-bytes", "4096"}, want: defaultBackendQuotaBytes},

    fixed, now we accept the following four formats:

  • "--flag=value"

  • "--flag value"

  • "--flag" "value"

  • --flag // for bool flag
  • silentred silentred commented on code on Nov 26, 2026 12:20 UTC
    Code Review
    internal/controller/utils_test.go:1
    @@ -648,3 +648,78 @@ func TestVerifySecretHasCA(t *testing.T) {
     		assert.Contains(t, err.Error(), "cert-manager")
     	})
     }
    +
    +func TestParseEtcdOption(t *testing.T) {
    +	tests := []struct {
    +		name      string
    +		input     string
    +		wantName  string
    +		wantValue string
    +		wantHas   bool
    +	}{
    +		{name: "equals form", input: "--quota-backend-bytes=1024", wantName: "--quota-backend-bytes", wantValue: "1024", wantHas: true},
    +		{name: "space form in one element", input: "--quota-backend-bytes 1024", wantName: "--quota-backend-bytes", wantValue: "1024", wantHas: true},
    +		{name: "bare boolean flag", input: "--enable-pprof", wantName: "--enable-pprof"},
    +		{name: "space form with equals in value", input: "--initial-cluster-token a=b", wantName: "--initial-cluster-token", wantValue: "a=b", wantHas: true},
    +		{name: "equals form with space in value", input: "--flag=a b", wantName: "--flag", wantValue: "a b", wantHas: true},
    +		{name: "bare flag with trailing space", input: "--enable-pprof ", wantName: "--enable-pprof"},
    +		{name: "value containing equals", input: "--initial-cluster=a=http://x:2380", wantName: "--initial-cluster", wantValue: "a=http://x:2380", wantHas: true},
    +		{name: "empty value", input: "--flag=", wantName: "--flag", wantHas: true},
    +		{name: "value in separate element is not a value", input: "1024", wantName: "1024"},
    +	}
    +	for _, tt := range tests {
    +		t.Run(tt.name, func(t *testing.T) {
    +			name, value, has := parseEtcdOption(tt.input)
    +			assert.Equal(t, tt.wantName, name)
    +			assert.Equal(t, tt.wantValue, value)
    +			assert.Equal(t, tt.wantHas, has)
    +		})
    +	}
    +}
    +
    +func TestBackendQuotaBytes(t *testing.T) {
    +	tests := []struct {
    +		name string
    +		opts []string
    +		want int64
    +	}{
    +		{name: "unset", want: defaultBackendQuotaBytes},
    +		{name: "equals form", opts: []string{"--quota-backend-bytes=4096"}, want: 4096},
    +		{name: "space form", opts: []string{"--quota-backend-bytes 4096"}, want: 4096},
    +		{name: "other flags ignored", opts: []string{"--name=x", "--quota-backend-bytes=4096"}, want: 4096},
    +		{name: "last occurrence wins", opts: []string{"--quota-backend-bytes=1", "--quota-backend-bytes=2"}, want: 2},
    +		{name: "later invalid occurrence is skipped", opts: []string{"--quota-backend-bytes=4096", "--quota-backend-bytes=abc"}, want: 4096},
    +		{name: "invalid value falls back to default", opts: []string{"--quota-backend-bytes=abc"}, want: defaultBackendQuotaBytes},
    +		{name: "non-positive falls back to default", opts: []string{"--quota-backend-bytes=0"}, want: defaultBackendQuotaBytes},
    +		{name: "bare flag falls back to default", opts: []string{"--quota-backend-bytes"}, want: defaultBackendQuotaBytes},
    +		{name: "separate-element value is not recognised", opts: []string{"--quota-backend-bytes", "4096"}, want: defaultBackendQuotaBytes},

    Thanks. LGTM.

    silentred silentred commented on Nov 26, 2026 13:44 UTC
    Contributor

    The commit history seems not right. Should I choose "Squash and merge"? Sorry for the mistake.

    ahrtr ahrtr commented on Nov 26, 2026 14:08 UTC
    Author

    The commit history seems not right. Should I choose "Squash and merge"?

    There is no standard. Either way works.

    My personal rules:

  • for dependabot PRs, use rebase and merge

  • for normal PRs, if there are multiple commits, use create a merge commit; otherwise, use rebase and merge for super simple change, otherwise still use create a merge commit
  • Reviewers
    Assignees
    ahrtr ahrtr
    Labels
    risk: low confidence: 86% 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: 49.2% (MEDIUM) · Higher = larger blast radius
    49.2%
    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: 86% · Lower = rushed or shallow review
    86%
    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: 6.9% · Safe to merge
    6.9%