Skip to content

rename --lease to --lease-duration#171

Merged
bennyz merged 2 commits into
centos-automotive-suite:mainfrom
bennyz:lease-duration
Mar 15, 2026
Merged

rename --lease to --lease-duration#171
bennyz merged 2 commits into
centos-automotive-suite:mainfrom
bennyz:lease-duration

Conversation

@bennyz

@bennyz bennyz commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

and have --lease allow users to provide their own lease

Summary by CodeRabbit

  • New Features

    • Support for referencing existing Jumpstarter leases via the --lease flag across build, disk, flash, and build-dev commands.
    • Added explicit --lease-duration flag for creating new leases.
  • Bug Fixes

    • Existing leases use an extended wait timeout; new-lease timeouts are computed from --lease-duration.
  • Improvements

    • Enforced mutual exclusivity between --lease and --lease-duration.
    • Flash flows propagate provided lease names and avoid releasing user-provided leases.

and have --lease allow users to provide their own lease

Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
Assisted-by: claude-sonnet-4.6
@coderabbitai

coderabbitai Bot commented Mar 15, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@bennyz has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 86da4527-9d77-4c50-bcfd-7077f819beb0

📥 Commits

Reviewing files that changed from the base of the PR and between 449f228 and f7550c1.

📒 Files selected for processing (2)
  • cmd/caib/buildcmd/build.go
  • cmd/caib/buildcmd/build_disk_test.go
📝 Walkthrough

Walkthrough

Adds support for using an existing Jumpstarter lease by introducing LeaseName across API types, CLI options, server handlers, Tekton pipeline parameters, and flash scripts, with mutual-exclusivity checks against lease-duration and propagation of the lease name through build/flash flows.

Changes

Cohort / File(s) Summary
API Types
api/v1alpha1/imagebuild_types.go
Added LeaseName to FlashSpec and GetFlashLeaseName() accessor on ImageBuildSpec.
CLI: build/flash/image
cmd/caib/buildcmd/build.go, cmd/caib/flashcmd/flash.go, cmd/caib/image/image.go, cmd/caib/main.go
Added LeaseName *string option and flags, enforced mutual exclusivity with lease-duration, propagated LeaseName into flash requests, and adjusted flash timeout behavior when using an existing lease.
CLI Tests & Wiring
cmd/caib/buildcmd/build_disk_test.go, cmd/caib/runtime_wiring.go
Updated tests and runtime wiring to initialize and propagate LeaseName through runtime state, image options, and handler construction.
Build API Server & Types
internal/buildapi/server.go, internal/buildapi/types.go
Added LeaseName/FlashLeaseName fields, server-side mutual-exclusivity validation, conditional lease-duration resolution only when no LeaseName provided, and included lease-name in TaskRun parameters and build responses.
Tekton pipeline & tasks
internal/common/tasks/tasks.go, internal/controller/imagebuild/controller.go
Added flash-lease-name / lease-name Tekton params, wired them into build-image and flash-image tasks, and set TaskRun params from GetFlashLeaseName().
Flash script
internal/common/tasks/scripts/flash_image.sh
Added handling for EXISTING_LEASE / user-provided lease: skip creation when provided, adjust output and cleanup (do not release user-provided lease).

Sequence Diagram

sequenceDiagram
    participant CLI as CLI / User
    participant API as Build API Server
    participant Tekton as Tekton Pipeline
    participant Task as Flash Task / Script
    participant JS as Jumpstarter Service

    CLI->>API: Submit BuildRequest (LeaseName or LeaseDuration)
    API->>API: Validate mutual exclusivity (LeaseName XOR LeaseDuration)
    alt LeaseName provided
        API->>Tekton: Start pipeline with param lease-name
        Tekton->>Task: Pass EXISTING_LEASE from param
        Task->>JS: Use existing lease (no create)
        JS-->>Task: Lease confirmed
    else LeaseDuration provided
        API->>Tekton: Start pipeline with flash-lease-name duration
        Tekton->>Task: Create new lease
        Task->>JS: Create lease with duration
        JS-->>Task: Lease created
    end
    Task->>Task: Perform flash/build operations
    alt existing lease used
        Task->>JS: Leave lease active (no release)
    else new lease created
        Task->>JS: Release lease on completion
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • bkhizgiy

Poem

🐰 A lease by name, no need to measure,
Reuse old leases—what a treasure!
Flags flow down to Tekton's song,
The rabbit hops the lease along.
Mutual rules now keep things clear—hip-hop hooray!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'rename --lease to --lease-duration' accurately describes the primary change, but incompletely represents the PR's full scope of introducing --lease as a new flag for user-provided leases.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/buildapi/server.go (1)

1560-1578: ⚠️ Potential issue | 🟠 Major

Enforce lease-name/lease-duration exclusivity in the build path too.

Line 1575 adds FlashLeaseName propagation, but createBuild still accepts both FlashLeaseName and FlashLeaseDuration simultaneously. This creates ambiguous build input behavior and diverges from the flash endpoint validation.

🛠️ Suggested fix
 	if req.FlashEnabled {
 		if req.FlashClientConfig == "" {
 			c.JSON(http.StatusBadRequest, gin.H{"error": "flash enabled but client config is required"})
 			return
 		}
+		req.FlashLeaseName = strings.TrimSpace(req.FlashLeaseName)
+		req.FlashLeaseDuration = strings.TrimSpace(req.FlashLeaseDuration)
+		if req.FlashLeaseName != "" && req.FlashLeaseDuration != "" {
+			c.JSON(http.StatusBadRequest, gin.H{"error": "flashLeaseName and flashLeaseDuration are mutually exclusive"})
+			return
+		}
+		if req.FlashLeaseName != "" {
+			req.FlashLeaseDuration = ""
+		}
 		flashSecretName = req.Name + "-jumpstarter-client"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/buildapi/server.go` around lines 1560 - 1578, The build path
currently allows both FlashLeaseName and FlashLeaseDuration to be set
simultaneously (introduced when propagating FlashLeaseName), leading to
ambiguous inputs; update the createBuild flow to validate exclusivity by
checking req.FlashEnabled and then returning HTTP 400 if both req.FlashLeaseName
and req.FlashLeaseDuration are non-zero/ non-empty, mirroring the flash endpoint
validation—locate the createBuild handler (or the function that prepares
flashSpec) and add a guard that rejects requests with both fields set and
returns a clear error message like "flash lease-name and lease-duration are
mutually exclusive".
🧹 Nitpick comments (1)
cmd/caib/image/image.go (1)

144-146: Consider deduplicating lease flag registration across commands.

The same --lease-duration/--lease flag setup is repeated four times. Extracting a small helper will reduce drift risk and keep help text/behavior aligned.

♻️ Suggested refactor
+func addLeaseFlags(cmd *cobra.Command, leaseDuration, leaseName *string) {
+	cmd.Flags().StringVar(leaseDuration, "lease-duration", "03:00:00", "device lease duration for flash (HH:MM:SS)")
+	cmd.Flags().StringVar(leaseName, "lease", "", "existing Jumpstarter lease name (mutually exclusive with --lease-duration)")
+}

-	buildCmd.Flags().StringVar(opts.LeaseDuration, "lease-duration", "03:00:00", "device lease duration for flash (HH:MM:SS)")
-	buildCmd.Flags().StringVar(opts.LeaseName, "lease", "", "existing Jumpstarter lease name (mutually exclusive with --lease-duration)")
+	addLeaseFlags(buildCmd, opts.LeaseDuration, opts.LeaseName)

-	diskCmd.Flags().StringVar(opts.LeaseDuration, "lease-duration", "03:00:00", "device lease duration for flash (HH:MM:SS)")
-	diskCmd.Flags().StringVar(opts.LeaseName, "lease", "", "existing Jumpstarter lease name (mutually exclusive with --lease-duration)")
+	addLeaseFlags(diskCmd, opts.LeaseDuration, opts.LeaseName)

-	buildDevCmd.Flags().StringVar(opts.LeaseDuration, "lease-duration", "03:00:00", "device lease duration for flash (HH:MM:SS)")
-	buildDevCmd.Flags().StringVar(opts.LeaseName, "lease", "", "existing Jumpstarter lease name (mutually exclusive with --lease-duration)")
+	addLeaseFlags(buildDevCmd, opts.LeaseDuration, opts.LeaseName)

-	flashCmd.Flags().StringVar(opts.LeaseDuration, "lease-duration", "03:00:00", "device lease duration (HH:MM:SS)")
-	flashCmd.Flags().StringVar(opts.LeaseName, "lease", "", "existing Jumpstarter lease name (mutually exclusive with --lease-duration)")
+	addLeaseFlags(flashCmd, opts.LeaseDuration, opts.LeaseName)

Also applies to: 202-204, 242-244, 268-270

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/caib/image/image.go` around lines 144 - 146, Extract the repeated lease
flag registration into a single helper (e.g., add a function
registerLeaseFlags(cmd *cobra.Command, leaseDuration *string, leaseName
*string)) and replace each duplicated block that calls
buildCmd.Flags().StringVar(opts.LeaseDuration, "lease-duration", ...),
buildCmd.Flags().StringVar(opts.LeaseName, "lease", ...) with a call to that
helper; ensure the helper sets the same defaults and help text (including
mutual-exclusion semantics) and update the four locations that currently
register --lease-duration/--lease so they pass the appropriate command and opts
fields (LeaseDuration, LeaseName).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/caib/buildcmd/build.go`:
- Around line 414-416: Add a mutual-exclusivity check before assigning
FlashLeaseDuration and FlashLeaseName: detect when both h.opts.LeaseDuration and
h.opts.LeaseName are non-nil (or set) and return an error, rejecting the request
(same logic as the validation in cmd/caib/flashcmd/flash.go around lines
103-105); only set req.FlashLeaseDuration = *h.opts.LeaseDuration or
req.FlashLeaseName = *h.opts.LeaseName when the other is not provided to ensure
they cannot both be included in the request.

In `@internal/buildapi/server.go`:
- Around line 2830-2834: Trim and normalize lease inputs before any validation
or use: call strings.TrimSpace on req.LeaseName and req.LeaseDuration
immediately after parsing the request (before the mutual-exclusivity check that
references req.LeaseName/req.LeaseDuration) and use those trimmed values when
you build the TaskRun parameters (the code path that constructs the TaskRun
param at/around the TaskRun creation). Ensure all checks and the value passed to
the TaskRun creation logic reference the trimmed variables so whitespace-only
strings are treated as empty.

---

Outside diff comments:
In `@internal/buildapi/server.go`:
- Around line 1560-1578: The build path currently allows both FlashLeaseName and
FlashLeaseDuration to be set simultaneously (introduced when propagating
FlashLeaseName), leading to ambiguous inputs; update the createBuild flow to
validate exclusivity by checking req.FlashEnabled and then returning HTTP 400 if
both req.FlashLeaseName and req.FlashLeaseDuration are non-zero/ non-empty,
mirroring the flash endpoint validation—locate the createBuild handler (or the
function that prepares flashSpec) and add a guard that rejects requests with
both fields set and returns a clear error message like "flash lease-name and
lease-duration are mutually exclusive".

---

Nitpick comments:
In `@cmd/caib/image/image.go`:
- Around line 144-146: Extract the repeated lease flag registration into a
single helper (e.g., add a function registerLeaseFlags(cmd *cobra.Command,
leaseDuration *string, leaseName *string)) and replace each duplicated block
that calls buildCmd.Flags().StringVar(opts.LeaseDuration, "lease-duration",
...), buildCmd.Flags().StringVar(opts.LeaseName, "lease", ...) with a call to
that helper; ensure the helper sets the same defaults and help text (including
mutual-exclusion semantics) and update the four locations that currently
register --lease-duration/--lease so they pass the appropriate command and opts
fields (LeaseDuration, LeaseName).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 529d15da-62c8-4895-b960-71c314d0f479

📥 Commits

Reviewing files that changed from the base of the PR and between abecc4c and 121e5d8.

⛔ Files ignored due to path filters (1)
  • config/crd/bases/automotive.sdv.cloud.redhat.com_imagebuilds.yaml is excluded by !config/crd/bases/**
📒 Files selected for processing (12)
  • api/v1alpha1/imagebuild_types.go
  • cmd/caib/buildcmd/build.go
  • cmd/caib/buildcmd/build_disk_test.go
  • cmd/caib/flashcmd/flash.go
  • cmd/caib/image/image.go
  • cmd/caib/main.go
  • cmd/caib/runtime_wiring.go
  • internal/buildapi/server.go
  • internal/buildapi/types.go
  • internal/common/tasks/scripts/flash_image.sh
  • internal/common/tasks/tasks.go
  • internal/controller/imagebuild/controller.go

Comment thread cmd/caib/buildcmd/build.go Outdated
Comment thread internal/buildapi/server.go
@bennyz bennyz requested a review from bkhizgiy March 15, 2026 10:53

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
cmd/caib/buildcmd/build.go (1)

425-426: ⚠️ Potential issue | 🔴 Critical

Only one flash lease field should be sent in requests.

At Line 425/549/691 and Line 426/550/692, both FlashLeaseDuration and FlashLeaseName are always populated. This can still fail valid lease-name flows at downstream validation and breaks the new --lease behavior.

Proposed fix
-		req.FlashLeaseDuration = *h.opts.LeaseDuration
-		req.FlashLeaseName = *h.opts.LeaseName
+		if *h.opts.LeaseName != "" {
+			req.FlashLeaseName = *h.opts.LeaseName
+		} else {
+			req.FlashLeaseDuration = *h.opts.LeaseDuration
+		}

Apply this same conditional in all three flash-enabled blocks (RunBuild, RunDisk, RunBuildDev).

Also applies to: 549-550, 691-692

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/caib/buildcmd/build.go` around lines 425 - 426, Both FlashLeaseDuration
and FlashLeaseName are always being set on req which breaks downstream
validation; change the three flash-enabled locations (inside RunBuild, RunDisk,
RunBuildDev where req is populated) to set only one flash lease field: if
opts.LeaseName is provided (non-nil/non-empty) set req.FlashLeaseName and do not
set req.FlashLeaseDuration, otherwise if opts.LeaseDuration is provided set
req.FlashLeaseDuration and do not set req.FlashLeaseName. Update the blocks that
currently assign req.FlashLeaseDuration = *h.opts.LeaseDuration and
req.FlashLeaseName = *h.opts.LeaseName to use this conditional logic so only one
field is populated per request.
🧹 Nitpick comments (1)
cmd/caib/buildcmd/build_disk_test.go (1)

87-110: Add a success-path test for lease-only usage.

This test covers the conflict path, but it does not assert the intended new behavior where only --lease is provided and execution proceeds. Please add a companion test to guard the PR objective and prevent regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/caib/buildcmd/build_disk_test.go` around lines 87 - 110, Add a new unit
test that verifies the success path when only --lease is provided (complementing
TestRunDiskRejectsLeaseAndLeaseDuration). Create e.g.
TestRunDiskAcceptsLeaseOnly that uses newTestDiskOpts(), sets *opts.LeaseName =
"my-lease" and ensures you do NOT set the lease-duration flag, capture errors
via opts.HandleError (like in the existing test), construct h :=
NewHandler(opts) and cmd := &cobra.Command{}, call h.RunDisk(cmd,
[]string{"quay.io/test/image:latest"}), and assert capturedErr == nil (fail the
test if an error is returned) to ensure RunDisk accepts the lease-only case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@cmd/caib/buildcmd/build.go`:
- Around line 425-426: Both FlashLeaseDuration and FlashLeaseName are always
being set on req which breaks downstream validation; change the three
flash-enabled locations (inside RunBuild, RunDisk, RunBuildDev where req is
populated) to set only one flash lease field: if opts.LeaseName is provided
(non-nil/non-empty) set req.FlashLeaseName and do not set
req.FlashLeaseDuration, otherwise if opts.LeaseDuration is provided set
req.FlashLeaseDuration and do not set req.FlashLeaseName. Update the blocks that
currently assign req.FlashLeaseDuration = *h.opts.LeaseDuration and
req.FlashLeaseName = *h.opts.LeaseName to use this conditional logic so only one
field is populated per request.

---

Nitpick comments:
In `@cmd/caib/buildcmd/build_disk_test.go`:
- Around line 87-110: Add a new unit test that verifies the success path when
only --lease is provided (complementing
TestRunDiskRejectsLeaseAndLeaseDuration). Create e.g.
TestRunDiskAcceptsLeaseOnly that uses newTestDiskOpts(), sets *opts.LeaseName =
"my-lease" and ensures you do NOT set the lease-duration flag, capture errors
via opts.HandleError (like in the existing test), construct h :=
NewHandler(opts) and cmd := &cobra.Command{}, call h.RunDisk(cmd,
[]string{"quay.io/test/image:latest"}), and assert capturedErr == nil (fail the
test if an error is returned) to ensure RunDisk accepts the lease-only case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: decb35ed-f1f5-43f6-8735-93c2196e0cd3

📥 Commits

Reviewing files that changed from the base of the PR and between 6e44820 and 449f228.

📒 Files selected for processing (2)
  • cmd/caib/buildcmd/build.go
  • cmd/caib/buildcmd/build_disk_test.go

Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
@bennyz bennyz merged commit 6aa543d into centos-automotive-suite:main Mar 15, 2026
4 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Mar 23, 2026
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