Skip to content

use click.Path for --kubeconfig#371

Merged
mangelajo merged 1 commit intojumpstarter-dev:mainfrom
bennyz:fix-kubeconfig
Mar 23, 2026
Merged

use click.Path for --kubeconfig#371
mangelajo merged 1 commit intojumpstarter-dev:mainfrom
bennyz:fix-kubeconfig

Conversation

@bennyz
Copy link
Copy Markdown
Member

@bennyz bennyz commented Mar 23, 2026

kubernetes_asyncio.config.load_kube_config expects a path and will currently fail

kubernetes_asyncio.config.load_kube_config expects a path and will currently
fail

Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 23, 2026

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit 7b408a9
🔍 Latest deploy log https://app.netlify.com/projects/jumpstarter-docs/deploys/69c13f15c019270008dcab9c
😎 Deploy Preview https://deploy-preview-371--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

The opt_kubeconfig option in the jumpstarter CLI common package was updated to accept an existing filesystem path instead of a file object. This changes both input validation timing and the data type passed to downstream code.

Changes

Cohort / File(s) Summary
CLI Option Type Migration
python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py
Changed opt_kubeconfig from click.File() to click.Path(exists=True), shifting from file object handling to path string validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A kubeconfig path takes flight,
No longer wrapped in file buffers tight,
From objects to strings, a cleaner way,
The rabbit hops forward to a brighter day! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: replacing click.File() with click.Path() for the --kubeconfig option.
Description check ✅ Passed The description explains the motivation for the change by referencing that kubernetes_asyncio.config.load_kube_config expects a path, which is directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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
Contributor

@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 the current code and only fix it if needed.

Inline comments:
In `@python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py`:
- Line 60: The "--kubeconfig" option currently uses click.Path(exists=True)
which allows directories; update the click.Path call for the "--kubeconfig"
option in jumpstarter_cli_common.opt to restrict to readable files only by
setting dir_okay=False and readable=True (e.g., click.Path(exists=True,
dir_okay=False, readable=True)) so only existing, readable files are accepted
during CLI parsing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5bca31b3-7955-4d04-a3a1-2360263995d5

📥 Commits

Reviewing files that changed from the base of the PR and between 05867cd and 7b408a9.

📒 Files selected for processing (1)
  • python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py


opt_kubeconfig = click.option(
"--kubeconfig", "kubeconfig", type=click.File(), default=None, help="path to the kubeconfig file"
"--kubeconfig", "kubeconfig", type=click.Path(exists=True), default=None, help="path to the kubeconfig file"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

In Click's official documentation, what are the default values for click.Path parameters (file_okay, dir_okay, readable), and does click.Path(exists=True) accept directories by default?

💡 Result:

In Click's official documentation, the default values for click.Path parameters are: exists=False, file_okay=True, dir_okay=True, readable=True. click.Path(exists=True) accepts directories by default, since dir_okay=True is the default and exists=True only requires the path to exist without changing file_okay or dir_okay.

Citations:


🏁 Script executed:

#!/bin/bash
# Find all usages of kubeconfig parameter in the codebase
rg "kubeconfig" --type py -B 2 -A 2 | head -100

Repository: jumpstarter-dev/jumpstarter

Length of output: 9721


🏁 Script executed:

#!/bin/bash
# Check the file where kubeconfig is used - specifically look at how ClientsV1Alpha1Api handles it
fd "get.py" --type f | xargs grep -l "ClientsV1Alpha1Api" 2>/dev/null

Repository: jumpstarter-dev/jumpstarter

Length of output: 137


🏁 Script executed:

#!/bin/bash
# Look for any kubeconfig file opening or validation code
rg "open.*kubeconfig|kubeconfig.*open" --type py -B 1 -A 1

Repository: jumpstarter-dev/jumpstarter

Length of output: 494


🏁 Script executed:

#!/bin/bash
# Check if there are any tests for kubeconfig handling
fd "test.*\.py|.*_test\.py" --type f | xargs grep -l "kubeconfig" 2>/dev/null | head -10

Repository: jumpstarter-dev/jumpstarter

Length of output: 472


🏁 Script executed:

#!/bin/bash
# Read the opt.py file to see the current structure and context around line 60
cat -n python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py | head -80

Repository: jumpstarter-dev/jumpstarter

Length of output: 3116


🏁 Script executed:

#!/bin/bash
# Read the get.py file to see how kubeconfig is used downstream
cat -n python/packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get.py | head -50

Repository: jumpstarter-dev/jumpstarter

Length of output: 1806


🏁 Script executed:

#!/bin/bash
# Check if there are any existing kubeconfig validation tests
cat -n python/packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get_test.py | grep -A 10 -B 5 "kubeconfig"

Repository: jumpstarter-dev/jumpstarter

Length of output: 1985


🏁 Script executed:

#!/bin/bash
# Verify Ruff configuration and if multi-line option formatting is acceptable
if [ -f "pyproject.toml" ]; then
  grep -A 20 "\[tool.ruff" pyproject.toml | head -40
fi
if [ -f ".ruff.toml" ]; then
  cat .ruff.toml | head -40
fi

Repository: jumpstarter-dev/jumpstarter

Length of output: 53


Restrict click.Path to files only for kubeconfig input validation.

On Line 60, click.Path(exists=True) accepts directories by default since dir_okay=True is the default parameter value. This allows invalid kubeconfig values (directories or unreadable paths) to pass CLI parsing and fail later when Kubernetes config is loaded. Restrict the option to readable files only.

Suggested patch
 opt_kubeconfig = click.option(
-    "--kubeconfig", "kubeconfig", type=click.Path(exists=True), default=None, help="path to the kubeconfig file"
+    "--kubeconfig",
+    "kubeconfig",
+    type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True),
+    default=None,
+    help="Path to the kubeconfig file",
 )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"--kubeconfig", "kubeconfig", type=click.Path(exists=True), default=None, help="path to the kubeconfig file"
opt_kubeconfig = click.option(
"--kubeconfig",
"kubeconfig",
type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True),
default=None,
help="Path to the kubeconfig file",
)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py` at line
60, The "--kubeconfig" option currently uses click.Path(exists=True) which
allows directories; update the click.Path call for the "--kubeconfig" option in
jumpstarter_cli_common.opt to restrict to readable files only by setting
dir_okay=False and readable=True (e.g., click.Path(exists=True, dir_okay=False,
readable=True)) so only existing, readable files are accepted during CLI
parsing.

@mangelajo mangelajo merged commit 920b517 into jumpstarter-dev:main Mar 23, 2026
31 checks passed
@bennyz bennyz deleted the fix-kubeconfig branch March 26, 2026 18:55
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