-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: restore lease request #233
Conversation
WalkthroughThe pull request introduces a new Changes
Sequence DiagramsequenceDiagram
participant User
participant CLI
participant ClientConfig
participant Controller
User->>CLI: Execute lease request
CLI->>ClientConfig: Load configuration
alt Named configuration
ClientConfig-->>CLI: Load specific config
else Default configuration
ClientConfig-->>CLI: Load current config
end
CLI->>Controller: Request lease with labels
Controller-->>CLI: Return lease details
CLI->>User: Display lease name
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Signed-off-by: Benny Zlotnik <[email protected]>
60483f7
to
f06ac66
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (1)
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py (1)
87-88
: Simplify error handling.The general exception handling block is redundant as it just re-raises the exception.
except ValueError as e: raise click.ClickException(str(e)) from e - except Exception as e: - raise e
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py
(2 hunks)
🧰 Additional context used
🪛 GitHub Actions: Lint
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py
[error] 1-1: Import block is un-sorted or un-formatted
🔇 Additional comments (1)
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py (1)
51-85
: LGTM! The implementation looks solid.The command implementation follows the existing patterns in the codebase and provides a good user experience with:
- Flexible label filtering
- Consistent configuration loading
- Clear error messages
- Proper output format (just the lease name for easy scripting)
$ jmp shell | ||
$$ j --help | ||
$$ exit | ||
$ jmp lease release -l "${JMP_LEASE}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect flag in example.
The example uses -l
flag for release command but the actual flag is --lease
.
- $ jmp lease release -l "${JMP_LEASE}"
+ $ jmp lease release --lease "${JMP_LEASE}"
📝 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.
$ jmp lease release -l "${JMP_LEASE}" | |
$ jmp lease release --lease "${JMP_LEASE}" |
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py
Outdated
Show resolved
Hide resolved
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py (1)
86-87
: Improve exception handling.The general exception handler simply re-raises the exception without providing any context. Consider wrapping it in a ClickException with a more user-friendly message.
except ValueError as e: raise click.ClickException(str(e)) from e except Exception as e: - raise e + raise click.ClickException(f"Failed to request lease: {str(e)}") from e
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: pytest-matrix (3.13)
- GitHub Check: pytest-matrix (3.12)
- GitHub Check: pytest-matrix (3.11)
🔇 Additional comments (4)
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py (4)
Line range hint
1-7
: LGTM! Import ordering is now correct.The imports are properly sorted according to the style guide, resolving the previous lint error.
68-68
: Fix incorrect command in example.The example shows
jmp client lease request
but the actual command should bejmp lease request
.- $ JMP_LEASE=$(jmp client lease request -l label match) + $ JMP_LEASE=$(jmp lease request -l label match)
72-72
: Fix incorrect flag in example.The example uses
-l
flag for release command but the actual flag is--lease
.- $ jmp lease release -l "${JMP_LEASE}" + $ jmp lease release --lease "${JMP_LEASE}"
50-83
: LGTM! Well-structured command implementation.The lease request command is well-implemented with:
- Clear parameter definitions using Click decorators
- Comprehensive docstring explaining usage
- Consistent error handling pattern
- Proper integration with the configuration system
- Clean implementation of label-based filtering
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this 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
🧹 Nitpick comments (1)
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py (1)
51-51
: Add validation for label format.The command accepts labels without validating their format. Consider adding validation to ensure labels follow Kubernetes label syntax (alphanumeric, '-', '_', or '.' characters).
+def validate_label(ctx, param, value): + import re + for k, v in value: + if not re.match(r'^[a-z0-9A-Z]([a-z0-9A-Z\-_\.]*[a-z0-9A-Z])?$', k): + raise click.BadParameter(f'Invalid label key format: {k}') + if not re.match(r'^[a-z0-9A-Z]([a-z0-9A-Z\-_\.]*[a-z0-9A-Z])?$', v): + raise click.BadParameter(f'Invalid label value format: {v}') + return value @lease.command("request") -@click.option("-l", "--label", "labels", type=(str, str), multiple=True) +@click.option("-l", "--label", "labels", type=(str, str), multiple=True, callback=validate_label)Also applies to: 82-82
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: pytest-matrix (3.13)
- GitHub Check: pytest-matrix (3.12)
- GitHub Check: pytest-matrix (3.11)
🔇 Additional comments (3)
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py (3)
Line range hint
1-7
: LGTM! Import organization looks good.The imports are now properly sorted according to the style guide, resolving the previous lint error.
72-72
: Fix incorrect flag in example.The example uses
-l
flag for release command but the actual flag is--lease
.- $ jmp lease release -l "${JMP_LEASE}" + $ jmp lease release --lease "${JMP_LEASE}"
75-83
: LGTM! Core implementation looks good.The implementation follows the established pattern of other commands in the file, with proper configuration loading and error handling. The use of MetadataFilter for labels is appropriate.
except Exception as e: | ||
raise e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve exception handling.
The bare raise e
is not a good practice as it loses the traceback information. Consider either letting the exception propagate naturally by removing the general exception handler or wrapping it in a click exception for consistent error handling.
- except Exception as e:
- raise e
+ except Exception as e:
+ raise click.ClickException(f"Unexpected error: {str(e)}") from e
📝 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.
except Exception as e: | |
raise e | |
except Exception as e: | |
raise click.ClickException(f"Unexpected error: {str(e)}") from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!!!
Summary by CodeRabbit
request
command to the lease functionality.