Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

client: compare lease selectors#620

Merged
mangelajo merged 3 commits intojumpstarter-dev:mainfrom
bennyz:lease-match-selector
Sep 17, 2025
Merged

client: compare lease selectors#620
mangelajo merged 3 commits intojumpstarter-dev:mainfrom
bennyz:lease-match-selector

Conversation

@bennyz
Copy link
Copy Markdown
Member

@bennyz bennyz commented Sep 17, 2025

when a lease is already is set in the env (JMP_LEASE), the requested selector will be ignored, even if it does not match the existing lease.

Instead of silently using the env lease, warn and create a new lease

Summary by CodeRabbit

  • Bug Fixes

    • Ensures an existing lease is only reused when its selector matches the requested selector.
    • Automatically clears and recreates the lease when a mismatch is detected to prevent unintended reuse.
    • Preserves expected behavior when no lease name is provided.
  • Chores

    • Improved log messages to clarify when an existing lease is used via environment or flag.
    • Added explicit warnings on selector mismatches to aid troubleshooting.

when a lease is already is set in the env (JMP_LEASE), the requested selector will be ignored,
even if it does not match the existing lease.

Instead of silently using the env lease, warn and create a new lease

Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
@bennyz bennyz requested a review from mangelajo September 17, 2025 13:12
@netlify
Copy link
Copy Markdown

netlify Bot commented Sep 17, 2025

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit 7e66e9e
🔍 Latest deploy log https://app.netlify.com/projects/jumpstarter-docs/deploys/68cb24acb1bb9900083a7fab
😎 Deploy Preview https://deploy-preview-620--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 Sep 17, 2025

Walkthrough

Updates lease acquisition in request_async: if a lease name is provided, it fetches the current lease, compares selectors, logs a warning and clears the name if selectors differ, then creates a new lease; otherwise uses the existing lease. If no name is provided, it creates a new lease. Finally, it acquires the lease.

Changes

Cohort / File(s) Summary
Lease request flow and selector validation
packages/jumpstarter/jumpstarter/client/lease.py
Added selector comparison when a lease name exists; logs warning and resets name on mismatch, then creates a new lease. Retains existing lease when selectors match. Adjusted log message text. Unchanged: create on missing name and final call to await self._acquire().

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Caller
    participant LeaseClient as LeaseClient.request_async
    participant LeaseAPI as Lease API

    Caller->>LeaseClient: request_async(selector, name?)
    alt name provided
        LeaseClient->>LeaseAPI: fetch existing lease by name
        LeaseAPI-->>LeaseClient: existing lease (selector_existing)
        alt selector_existing != selector_requested
            Note over LeaseClient: Log warning: selector mismatch
            LeaseClient->>LeaseClient: clear name
            LeaseClient->>LeaseAPI: _create(selector_requested)
            LeaseAPI-->>LeaseClient: new lease
        else selectors match
            Note over LeaseClient: Use existing lease (no create)
        end
    else no name provided
        LeaseClient->>LeaseAPI: _create(selector_requested)
        LeaseAPI-->>LeaseClient: new lease
    end
    LeaseClient->>LeaseAPI: _acquire()
    LeaseAPI-->>LeaseClient: acquired lease
    LeaseClient-->>Caller: lease handle
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nudge the levers, softly precise,
Comparing selectors—twice, thrice.
If names mislead, I hop anew,
Clear the path, create on cue.
With a twitch of ears and logging cheer,
I acquire the lease and burrow near. 🐇🔐

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "client: compare lease selectors" is concise, follows the conventional ": " format, and accurately reflects the PR’s primary change — making the client compare requested lease selectors against an existing lease and warn/create a new lease on mismatch. It is specific enough for a quick scan and avoids noisy details while indicating the affected area. This gives reviewers clear context about the main behavioral change.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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: 0

🧹 Nitpick comments (3)
packages/jumpstarter/jumpstarter/client/lease.py (3)

88-90: Avoid misleading log: log “using existing lease …” only after selectors match.

Right now we log that we’re using the existing lease before we know if we’ll discard it. Move the debug log into the match branch.

-            logger.debug("using existing lease via env or flag %s", self.name)
-            existing_lease = await self.get()
-            if existing_lease.selector != self.selector:
+            existing_lease = await self.get()
+            if existing_lease.selector != self.selector:
                 logger.warning(
                     "Existing lease from env or flag %s has selector '%s' but requested selector is '%s'. "
                     "Creating a new lease instead",
                     self.name,
                     existing_lease.selector,
                     self.selector,
                 )
-                self.name = None
-                await self._create()
+                await self._create()
+            else:
+                logger.debug("Using existing lease via env or flag %s", self.name)

98-99: Don’t null the name before creating the new lease.

_create() overwrites self.name. Dropping the intermediate None avoids a transient inconsistent state and preserves the old name if creation fails.


90-97: Selector comparison may be order/format sensitive.

If selectors are logically equivalent but differ in textual order/spacing, != will falsely trigger a new lease. Consider normalizing/parsing selectors before comparison, or confirm the server returns a canonical form.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 58a133e and b076954.

📒 Files selected for processing (1)
  • packages/jumpstarter/jumpstarter/client/lease.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/jumpstarter/jumpstarter/client/lease.py (1)
packages/jumpstarter/jumpstarter/common/metadata.py (1)
  • name (13-14)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: e2e
  • GitHub Check: build
  • GitHub Check: pytest-matrix (macos-15, 3.12)
  • GitHub Check: pytest-matrix (macos-15, 3.13)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.12)
  • GitHub Check: pytest-matrix (macos-15, 3.11)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.11)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.13)

@mangelajo mangelajo enabled auto-merge September 17, 2025 21:11
@mangelajo mangelajo merged commit 6b00b29 into jumpstarter-dev:main Sep 17, 2025
18 checks passed
@bennyz bennyz deleted the lease-match-selector branch September 18, 2025 06:30
@jumpstarter-backport-bot
Copy link
Copy Markdown

Successfully created backport PR for release-0.7:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants