Skip to content

fix: removed code duplication in KubeConfigUpdate. Added tests#309

Draft
adietish wants to merge 1 commit into
redhat-developer:mainfrom
adietish:dedupe_kubeconfigupdate
Draft

fix: removed code duplication in KubeConfigUpdate. Added tests#309
adietish wants to merge 1 commit into
redhat-developer:mainfrom
adietish:dedupe_kubeconfigupdate

Conversation

@adietish
Copy link
Copy Markdown
Collaborator

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: a335a622-d8d0-40dd-8f68-7fc0bb81427d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

KubeConfigUpdate centralizes kubeconfig mutation by adding shared base methods to build contexts with unique naming. CreateContext and CreateContextWithClientCert are refactored to eliminate duplicated logic and use the new applyNewContext flow. Token and client-certificate authentication are both supported through this unified path. New tests cover client certificate context creation and unique user naming.

Changes

Kubeconfig context creation refactoring

Layer / File(s) Summary
Shared base utilities for context updates
src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdate.kt
KubeConfigUpdate adds protected methods to centralize kubeconfig updates: updateCurrentContext saves the current context, applyNewContext generalizes the context-building flow with unique naming, and helper methods uniqueUserName, createClusterForNewContext, createContextForNewContext, and getAllExistingNames support the shared logic.
CreateContext refactored to use shared helpers
src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdate.kt
CreateContext now calls applyNewContext to construct the context, computing a unique user name and creating a named user from the provided auth token. Parameter renamed from token to authToken. The nested updateCurrentContext implementation is removed in favor of the base implementation.
CreateContextWithClientCert refactored to use shared helpers
src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdate.kt
CreateContextWithClientCert now uses applyNewContext to build the context with client certificate and key PEM inputs, computing a unique user name and creating the named user without a token.
Client certificate authentication test coverage
src/test/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdateTest.kt
Two new test cases verify CreateContextWithClientCert creates contexts correctly and generates unique user names when users already exist. Test fixtures provide client certificate PEM data, and a helper method validates base64-encoded certificate and key fields in the kubeconfig user entry.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.26% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided by the author, making it impossible to assess relevance to the changeset. Add a description explaining the refactoring goals, what code duplication was removed, and what new tests were added.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: code deduplication in KubeConfigUpdate and addition of tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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


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.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 21, 2026

Codecov Report

❌ Patch coverage is 75.64103% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 22.60%. Comparing base (71098f6) to head (e8f5ad7).
⚠️ Report is 351 commits behind head on main.

Files with missing lines Patch % Lines
...at/devtools/gateway/kubeconfig/KubeConfigUpdate.kt 75.64% 7 Missing and 12 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            main     #309       +/-   ##
==========================================
+ Coverage   0.00%   22.60%   +22.60%     
==========================================
  Files          4       99       +95     
  Lines         26     4176     +4150     
  Branches       0      770      +770     
==========================================
+ Hits           0      944      +944     
- Misses        26     3109     +3083     
- Partials       0      123      +123     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@adietish adietish marked this pull request as draft May 21, 2026 09:29
@adietish adietish force-pushed the dedupe_kubeconfigupdate branch 2 times, most recently from f537e83 to 55a65c7 Compare May 21, 2026 14:25
Signed-off-by: Andre Dietisheim <adietish@redhat.com>
@adietish adietish force-pushed the dedupe_kubeconfigupdate branch from 55a65c7 to e8f5ad7 Compare May 21, 2026 14:37
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.

2 participants