Skip to content

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

Closed
adietish wants to merge 0 commit into
redhat-developer:mainfrom
adietish:dedupe_kubeconfigupdate
Closed

fix: removed duplicate code in KubeConfigUpdate. Added tests#309
adietish wants to merge 0 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

Warning

Review limit reached

@adietish, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 3 minutes and 53 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 01653e90-523f-491f-a00b-2ff0a8621fc4

📥 Commits

Reviewing files that changed from the base of the PR and between 1c42bdb and c40fe65.

📒 Files selected for processing (3)
  • src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigEntries.kt
  • src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdate.kt
  • src/test/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdateTest.kt
📝 Walkthrough

Walkthrough

Centralizes kubeconfig write and context-entry construction in KubeConfigUpdate: new saveConfigs/saveConfig persistence helpers and shared unique-name/context creation utilities. UpdateToken/UpdateClientCert now mutate users and set current context, and CreateContext/CreateContextWithClientCert reuse the base helpers. Tests add client-certificate creation and persistence assertions.

Changes

Kubeconfig context creation refactoring

Layer / File(s) Summary
Persistence helpers and save selection
src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdate.kt
Introduce saveConfigs(...) and saveConfig(...) helpers that choose which kubeconfig file(s) to write based on current-context presence and config path equality.
Shared entry construction and unique-name utilities
src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdate.kt, src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigEntries.kt
Add ContextEntries and base helpers (uniqueUserName, createCluster, createContext, getAllExistingNames) and expose KubeConfigNamedContext.Companion.toName via @JvmStatic for shared name construction.
UpdateToken mutation and helper
src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdate.kt
Find target kubeconfig user, set user.token, update current-context via setContext(...) on the config holding the current context, and persist using saveConfigs(...). Token write extracted to a helper.
CreateContext refactored to use shared helpers
src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdate.kt
Build users/clusters/contexts with uniqueUserName and createContext, set current context, and persist via saveConfig(...). Constructor param renamed from token to authToken.
UpdateClientCert mutation flow
src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdate.kt
Update user's client-certificate-data and client-key-data, remove any existing user.token, set current context on the appropriate config, and persist via saveConfigs(...).
CreateContextWithClientCert refactored to use shared helpers
src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdate.kt
Construct user with token = null, convert PEM inputs to client-certificate/key entries, use createContext(...) to produce uniquely named entries, then persist.
Client certificate and update tests
src/test/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdateTest.kt
Add CreateContextWithClientCert tests and extend UpdateToken/UpdateClientCert tests to validate base64 client-certificate/key storage, save invocation counts, current-context persistence across primary/secondary configs, and null-list/preferences handling.

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: removing duplicate code in KubeConfigUpdate and adding tests, which aligns with the refactoring to centralize logic and expanded test coverage.
Description check ✅ Passed No pull request description was provided by the author; however, the PR objectives clearly indicate the changes are about removing code duplication and adding tests, which is related to the changeset.
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 86.41975% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 23.10%. Comparing base (71098f6) to head (c40fe65).
⚠️ Report is 351 commits behind head on main.

Files with missing lines Patch % Lines
...at/devtools/gateway/kubeconfig/KubeConfigUpdate.kt 86.41% 5 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            main     #309       +/-   ##
==========================================
+ Coverage   0.00%   23.10%   +23.10%     
==========================================
  Files          4       99       +95     
  Lines         26     4176     +4150     
  Branches       0      770      +770     
==========================================
+ Hits           0      965      +965     
- Misses        26     3087     +3061     
- Partials       0      124      +124     

☔ 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 9 times, most recently from f49bf42 to 1c42bdb Compare May 26, 2026 08:12
@adietish adietish self-assigned this May 26, 2026
@adietish adietish changed the title fix: removed code duplication in KubeConfigUpdate. Added tests fix: removed duplicate code in KubeConfigUpdate. Added tests May 26, 2026
@adietish adietish marked this pull request as ready for review May 26, 2026 08:14
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/test/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdateTest.kt`:
- Line 1013: The test helper setupUpdateExistingContextMocks currently stubs
KubeConfigUtils.getAllConfigFiles() to always return listOf(tempKubeConfigFile),
which hides multi-file behavior; update the helper so it derives the returned
list from the kubeconfig files passed into the helper (or add an explicit
parameter for the expected file list) and have
KubeConfigUtils.getAllConfigFiles() return that derived/explicit list instead of
the fixed tempKubeConfigFile, ensuring tests that use multiple distinct files
exercise the real path-selection and save-splitting logic.
🪄 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: Enterprise

Run ID: a0758978-6824-4911-b6b2-9228fdb618d2

📥 Commits

Reviewing files that changed from the base of the PR and between ccd4f10 and 1c42bdb.

📒 Files selected for processing (3)
  • src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigEntries.kt
  • src/main/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdate.kt
  • src/test/kotlin/com/redhat/devtools/gateway/kubeconfig/KubeConfigUpdateTest.kt

@adietish adietish moved this to Ready for Review in Eclipse Che Team C Backlog May 26, 2026
@adietish adietish force-pushed the dedupe_kubeconfigupdate branch 2 times, most recently from 7f7542d to c40fe65 Compare May 26, 2026 09:10
@adietish adietish closed this May 26, 2026
@adietish adietish force-pushed the dedupe_kubeconfigupdate branch from c40fe65 to 9f7b425 Compare May 26, 2026 09:23
@adietish adietish deleted the dedupe_kubeconfigupdate branch May 26, 2026 09:25
@adietish adietish restored the dedupe_kubeconfigupdate branch May 26, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants