Skip to content
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

Merged
merged 3 commits into from
Jan 25, 2025

Conversation

bennyz
Copy link
Member

@bennyz bennyz commented Jan 25, 2025

Summary by CodeRabbit

  • New Features
    • Added a new request command to the lease functionality.
    • Enables users to request an exporter lease with optional name and label filters.
    • Provides flexible lease configuration options through command-line interface.

Copy link
Contributor

coderabbitai bot commented Jan 25, 2025

Walkthrough

The pull request introduces a new request command to the lease command group in the Jumpstarter CLI client. This command allows users to request an exporter lease from the Jumpstarter controller by specifying a client configuration and optional label filters. The implementation includes error handling and enhances the functionality of the lease command group by enabling lease requests with specific metadata labels.

Changes

File Change Summary
packages/jumpstarter-cli-client/jumpstarter_cli_client/lease.py Added lease_request function to support requesting leases with optional name and label filters

Sequence Diagram

sequenceDiagram
    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
Loading

Poem

🐰 A Lease Request Hop! 🐰
With labels crisp and config bright,
Our CLI takes a rabbit's flight,
Requesting leases with such grace,
A metadata-filtered embrace,
Jumpstarter's magic takes its might!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Signed-off-by: Benny Zlotnik <[email protected]>
@bennyz bennyz force-pushed the restore-lease-request branch from 60483f7 to f06ac66 Compare January 25, 2025 18:50
@kirkbrauer kirkbrauer marked this pull request as ready for review January 25, 2025 21:19
Copy link
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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 173b6e5 and f06ac66.

📒 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}"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
$ jmp lease release -l "${JMP_LEASE}"
$ jmp lease release --lease "${JMP_LEASE}"

Copy link
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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between f06ac66 and 335aa6a.

📒 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 be jmp 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>
Copy link
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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 335aa6a and 6206f94.

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

Comment on lines +86 to +87
except Exception as e:
raise e
Copy link
Contributor

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.

Suggested change
except Exception as e:
raise e
except Exception as e:
raise click.ClickException(f"Unexpected error: {str(e)}") from e

Copy link
Member

@mangelajo mangelajo left a comment

Choose a reason for hiding this comment

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

Thank you!!!

@mangelajo mangelajo merged commit f9a921d into jumpstarter-dev:main Jan 25, 2025
9 of 10 checks passed
@bennyz bennyz deleted the restore-lease-request branch January 26, 2025 07:34
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