Skip to content

⚠️ refactor(grpc): change TLSMinVersion/TLSMaxVersion from uint16 to string - #220

Merged
openshift-merge-bot[bot] merged 1 commit into
open-cluster-management-io:mainfrom
zhujian7:feat/grpc-tls-string-config
Apr 3, 2026
Merged

⚠️ refactor(grpc): change TLSMinVersion/TLSMaxVersion from uint16 to string#220
openshift-merge-bot[bot] merged 1 commit into
open-cluster-management-io:mainfrom
zhujian7:feat/grpc-tls-string-config

Conversation

@zhujian7

@zhujian7 zhujian7 commented Apr 2, 2026

Copy link
Copy Markdown
Member

Summary

  • Change TLSMinVersion and TLSMaxVersion from uint16 to string in GRPCServerOptions, so config files use human-readable names (e.g. "VersionTLS12") instead of raw numeric constants (e.g. 771)
  • Parsed to uint16 internally by Validate() using pkgtls.ParseTLSVersion, keeping runtime behavior identical
  • ApplyTLSFlags simplified — just sets the string directly, validation deferred to Validate()

Related issue(s)

Follow-up to #219 (comment: #219 (comment))

Summary by CodeRabbit

Release Notes

  • Improvements
    • Enhanced TLS version validation with comprehensive error handling and minimum version enforcement.
    • Improved TLS configuration to ensure proper version constraints are applied.

…string

Change TLSMinVersion and TLSMaxVersion from uint16 to string in
GRPCServerOptions, so config files use human-readable names like
"VersionTLS12" instead of raw numeric constants like 771.

The string values are parsed to uint16 by Validate() using
pkgtls.ParseTLSVersion, keeping the runtime behavior identical.
ApplyTLSFlags is simplified to just set the string directly.

Signed-off-by: Jia Zhu <jiazhu@redhat.com>
Signed-off-by: zhujian <jiazhu@redhat.com>
@openshift-ci
openshift-ci Bot requested review from deads2k and qiujian16 April 2, 2026 08:42
@coderabbitai

coderabbitai Bot commented Apr 2, 2026

Copy link
Copy Markdown

Walkthrough

TLS version fields in GRPCServerOptions are changed from uint16 to string type, with corresponding internal uint16 fields added. Validation logic now parses string TLS versions and enforces version constraints, while option application defers parsing to validation. Server TLS configuration updated to use internal parsed fields.

Changes

Cohort / File(s) Summary
TLS Version Field Conversion
pkg/server/grpc/options.go
Converted TLSMinVersion and TLSMaxVersion from uint16 to string fields; added internal parsed tlsMinVersion/tlsMaxVersion fields; updated Validate() to parse string versions via pkgtls.ParseTLSVersion, enforce minVer >= tls.VersionTLS12, and validate minVer <= maxVer; modified ApplyTLSFlags() to set string values directly.
Test Updates
pkg/server/grpc/options_test.go
Updated test assertions to expect string TLS version values ("VersionTLS12", "VersionTLS13"); adjusted TestApplyTLSFlags to validate against internal parsed tlsMinVersion/tlsMaxVersion fields.
Server TLS Configuration
pkg/server/grpc/server.go
Updated TLS configuration to reference internal parsed fields b.options.tlsMinVersion and b.options.tlsMaxVersion instead of exported fields, including cipher-suite conditional logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

approved, lgtm

Suggested reviewers

  • qiujian16
  • skeeey
  • deads2k
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: refactoring TLSMinVersion/TLSMaxVersion field types from uint16 to string in the GRPC server options.
Description check ✅ Passed The description covers the main change with clear explanation of motivation and implementation approach, though it lacks a direct issue reference (uses 'Follow-up to #219' instead of the standard 'Fixes #' format).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zhujian7

zhujian7 commented Apr 2, 2026

Copy link
Copy Markdown
Member Author

/cc @skeeey @ncr38

@openshift-ci
openshift-ci Bot requested a review from skeeey April 2, 2026 08:50
@openshift-ci

openshift-ci Bot commented Apr 2, 2026

Copy link
Copy Markdown

@zhujian7: GitHub didn't allow me to request PR reviews from the following users: ncr38.

Note that only open-cluster-management-io members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

/cc @skeeey @ncr38

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
pkg/server/grpc/options_test.go (1)

59-60: Please cover the max-version/config-file parse path too.

The updated assertions only lock down tlsMinVersion, and the load test still gets the TLS versions from defaults rather than YAML. Add one case with explicit tls_min_version/tls_max_version in the config and assert both tlsMinVersion and tlsMaxVersion so the new parser-backed path is exercised.

Also applies to: 323-325, 349-350

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/server/grpc/options_test.go` around lines 59 - 60, Add a test case that
exercises the parser-backed config path by providing a YAML config with explicit
tls_min_version and tls_max_version and asserting both TLSMinVersion and
TLSMaxVersion on the resulting options; locate the existing tests that assert
TLSMinVersion/TLSMaxVersion (the entries using TLSMinVersion and TLSMaxVersion)
and add a parallel case which loads the YAML, calls the same config-load
function used elsewhere in options_test.go, and verifies both fields match the
provided values (this should also be mirrored for the other failing locations
noted around the other test cases).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/server/grpc/options.go`:
- Around line 38-40: The GRPCServerOptions constructor leaves the parsed TLS
cache fields tlsMinVersion and tlsMaxVersion at zero, but Validate() and runtime
use those fields as the source of truth; update NewGRPCServerOptions to seed
tlsMinVersion and tlsMaxVersion from the default MinVersion/MaxVersion (or
appropriate TLS constants) so the returned GRPCServerOptions is fully
initialized. Locate NewGRPCServerOptions and GRPCServerOptions, assign parsed
tlsMinVersion/tlsMaxVersion to their default parsed values (matching whatever
MinVersion/MaxVersion defaults you already set) and mirror the same change for
the other parsed cache fields noted around lines 72-73 so all parsed caches are
initialized consistently before any Validate() call.
- Around line 21-22: The TLSMinVersion and TLSMaxVersion fields were changed to
strings but existing configs may supply numeric uint16 values; update the config
loading path to accept numeric inputs and convert them to the expected string
form (or to the internal numeric form ParseTLSVersion consumes) to preserve
backward compatibility. Specifically, modify the options
unmarshalling/validation logic that reads TLSMinVersion/TLSMaxVersion (the
struct fields TLSMinVersion and TLSMaxVersion and the function ParseTLSVersion)
to detect numeric values (e.g., json/yaml numbers or strings containing digits),
convert them to the equivalent named/version string or pass the numeric value
through to ParseTLSVersion, and add unit tests for numeric and named inputs;
alternatively add clear migration error messages recommending the new string
format if conversion is not possible.

---

Nitpick comments:
In `@pkg/server/grpc/options_test.go`:
- Around line 59-60: Add a test case that exercises the parser-backed config
path by providing a YAML config with explicit tls_min_version and
tls_max_version and asserting both TLSMinVersion and TLSMaxVersion on the
resulting options; locate the existing tests that assert
TLSMinVersion/TLSMaxVersion (the entries using TLSMinVersion and TLSMaxVersion)
and add a parallel case which loads the YAML, calls the same config-load
function used elsewhere in options_test.go, and verifies both fields match the
provided values (this should also be mirrored for the other failing locations
noted around the other test cases).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ce67e64-640d-40fb-9bcf-0abc43cb7094

📥 Commits

Reviewing files that changed from the base of the PR and between 996da9f and 3fac15e.

📒 Files selected for processing (3)
  • pkg/server/grpc/options.go
  • pkg/server/grpc/options_test.go
  • pkg/server/grpc/server.go

Comment thread pkg/server/grpc/options.go
Comment thread pkg/server/grpc/options.go
@skeeey

skeeey commented Apr 2, 2026

Copy link
Copy Markdown
Member

LGTM

@qiujian16

Copy link
Copy Markdown
Member

/approve
/lgtm

@openshift-ci

openshift-ci Bot commented Apr 3, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16, zhujian7

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

@openshift-ci openshift-ci Bot added the approved label Apr 3, 2026
@openshift-merge-bot
openshift-merge-bot Bot merged commit 883108b into open-cluster-management-io:main Apr 3, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants