Skip to content

fix: wrong k8s client configuration#576

Merged
bsquizz merged 1 commit into
RedHatInsights:masterfrom
JuanmaBM:fix-kubeconfig-validation
May 27, 2026
Merged

fix: wrong k8s client configuration#576
bsquizz merged 1 commit into
RedHatInsights:masterfrom
JuanmaBM:fix-kubeconfig-validation

Conversation

@JuanmaBM
Copy link
Copy Markdown
Contributor

Fix a problem with the k8s configuration

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

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

More reviews will be available in 56 minutes and 29 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: 60a55ac4-9c26-4735-957e-b96b4cf52c78

📥 Commits

Reviewing files that changed from the base of the PR and between e54f7e5 and 9b5ba5f.

📒 Files selected for processing (2)
  • bonfire_lib/k8s_client.py
  • tests/test_bonfire_lib/test_k8s_client.py

Walkthrough

EphemeralK8sClient now loads Kubernetes credentials using explicitly created client.Configuration() instances passed to the Kubernetes client library config functions, replacing reliance on default/global configuration. The probe ApiClient is built from these explicit instances. All tests are updated to assert the new client_configuration argument in the config loading calls.

Changes

Explicit K8s Configuration Loading

Layer / File(s) Summary
Explicit Configuration instance loading in EphemeralK8sClient
bonfire_lib/k8s_client.py, tests/test_bonfire_lib/test_k8s_client.py
Kubeconfig and in-cluster auth now pass explicit client.Configuration() instances to config.load_kube_config and config.load_incluster_config respectively, with the probe ApiClient built from those configurations. All three affected tests (test_in_cluster_mode, test_kubeconfig_mode, test_kubeconfig_invalid_fallback_to_incluster) are updated to verify client_configuration=ANY is passed to the config loading calls.

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: wrong k8s client configuration' directly relates to the main change: fixing how Kubernetes client configuration is initialized with explicit Configuration objects.
Description check ✅ Passed The description 'Fix a problem with the k8s configuration' is related to the changeset, which fixes configuration handling in the Kubernetes client initialization.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✨ 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.

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 `@tests/test_bonfire_lib/test_k8s_client.py`:
- Around line 66-69: Add a single module-level import for ANY from unittest.mock
at the top of tests/test_bonfire_lib/test_k8s_client.py (add ANY to the existing
import list) and remove the three inline imports like "from unittest.mock import
ANY" inside the individual test functions that call
mock_config.load_incluster_config (the usages around the assertions at the
locations shown). This centralizes the ANY symbol and eliminates the duplicate
in-function imports so ruff/formatting pre-commit checks pass.
🪄 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: e681f7e0-4887-45df-90c5-fafb43873f63

📥 Commits

Reviewing files that changed from the base of the PR and between 39863bb and e54f7e5.

📒 Files selected for processing (2)
  • bonfire_lib/k8s_client.py
  • tests/test_bonfire_lib/test_k8s_client.py

Comment on lines +66 to +69
from unittest.mock import ANY
mock_config.load_incluster_config.assert_called_once_with(
client_configuration=ANY
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Move ANY import to module level to fix pipeline failure.

The from unittest.mock import ANY is imported three times inside test function bodies (lines 66, 82, 114). This is causing the ruff-format pre-commit failure. Import ANY once at the top of the file.

Proposed fix

At line 1, add ANY to the existing import:

-from unittest.mock import patch, MagicMock
+from unittest.mock import ANY, patch, MagicMock

Then remove the inline imports from the test functions:

         EphemeralK8sClient()
-        from unittest.mock import ANY
         mock_config.load_incluster_config.assert_called_once_with(
             client_configuration=ANY
         )
         EphemeralK8sClient(kubeconfig_path="/tmp/kubeconfig", context="mycontext")
         # Verify load_kube_config was called with the right args (client_configuration is ANY)
-        from unittest.mock import ANY
         mock_config.load_kube_config.assert_called_once_with(
             config_file="/tmp/kubeconfig",
             context="mycontext",
             client_configuration=ANY,
         )
         EphemeralK8sClient()

         # Should have fallen back to in-cluster
-        from unittest.mock import ANY
         mock_config.load_incluster_config.assert_called_once_with(
             client_configuration=ANY
         )

Also applies to: 82-86, 114-117

🤖 Prompt for 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.

In `@tests/test_bonfire_lib/test_k8s_client.py` around lines 66 - 69, Add a single
module-level import for ANY from unittest.mock at the top of
tests/test_bonfire_lib/test_k8s_client.py (add ANY to the existing import list)
and remove the three inline imports like "from unittest.mock import ANY" inside
the individual test functions that call mock_config.load_incluster_config (the
usages around the assertions at the locations shown). This centralizes the ANY
symbol and eliminates the duplicate in-function imports so ruff/formatting
pre-commit checks pass.

Signed-off-by: JuanmaBM <juanmabareamartinez@gmail.com>
@JuanmaBM JuanmaBM force-pushed the fix-kubeconfig-validation branch from e54f7e5 to 9b5ba5f Compare May 26, 2026 21:51
Comment thread bonfire_lib/k8s_client.py
@bsquizz bsquizz merged commit 5fd6470 into RedHatInsights:master May 27, 2026
12 checks passed
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.

3 participants