Skip to content

Add recreate-vms-created-before option to recreate and deploy commands#710

Open
Alphasite wants to merge 3 commits intomainfrom
recreate-vms-timestamp
Open

Add recreate-vms-created-before option to recreate and deploy commands#710
Alphasite wants to merge 3 commits intomainfrom
recreate-vms-timestamp

Conversation

@Alphasite
Copy link

@Alphasite Alphasite commented Jan 28, 2026

CLI counterpart to cloudfoundry/bosh#2656

The goal is to allow resumption of failed bosh repave (recreate) from where it failed, speeding up repave operations.

CLI counterpart to !2656

The goal is to allow resumption of failed bosh repave (recreate) from where it failed, speeding up repave operations.
@Alphasite Alphasite requested a review from aramprice January 29, 2026 19:56
@Alphasite
Copy link
Author

See other pr for manual testing

@Alphasite Alphasite marked this pull request as ready for review January 30, 2026 04:03
Replace opaque string types with proper time.Time for the
recreate-vms-created-before and vms-created-before flags. This provides
type safety, validation at parse time, and clearer error messages for
invalid RFC 3339 timestamps.

- Add TimeArg type with UnmarshalFlag for parsing RFC 3339 timestamps
- Update DeployOpts and RecreateOpts to use TimeArg
- Update director UpdateOpts and RecreateOpts to use time.Time
- Add comprehensive tests for TimeArg parsing and formatting
@Alphasite Alphasite force-pushed the recreate-vms-timestamp branch from df07972 to 8cd5366 Compare January 30, 2026 04:23
aramprice
aramprice previously approved these changes Feb 2, 2026
@github-project-automation github-project-automation bot moved this from Inbox to Pending Merge | Prioritized in Foundational Infrastructure Working Group Feb 2, 2026
SkipUploadReleases bool `long:"skip-upload-releases" description:"Skips the upload procedure for releases"`
Recreate bool `long:"recreate" description:"Recreate all VMs in deployment"`
RecreatePersistentDisks bool `long:"recreate-persistent-disks" description:"Recreate all persistent disks in deployment"`
RecreateVMsCreatedBefore TimeArg `long:"recreate-vms-created-before" description:"Only recreate VMs created before the given RFC 3339 timestamp (requires --recreate)"`
Copy link
Member

Choose a reason for hiding this comment

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

What time zone are we enforcing here?

Copy link
Author

@Alphasite Alphasite Feb 3, 2026

Choose a reason for hiding this comment

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

I believe RFC3339 requires a timezone be specified in the timezone string: https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 and UTC is the preferred format. I dont feel strongly, but i was inclined to just allow what ever timezones the spec allows (Z +/- an offset from UTC)

Copy link
Author

Choose a reason for hiding this comment

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

ill add tests to make sure it behaves the way we expect; based on yours an arams feedback.

  • make sure it handles dates without a +00:00
  • make sure all timestamps are UTC timezone internally

Copilot AI review requested due to automatic review settings February 3, 2026 23:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a timestamp-based filter to recreate and deploy --recreate so operators can resume a failed repave by only recreating VMs created before a given point in time.

Changes:

  • Extend director RecreateOpts/UpdateOpts to carry a VMsCreatedBefore/RecreateVMsCreatedBefore timestamp and send it as recreate_vm_created_before in requests.
  • Add CLI flags for deploy (--recreate-vms-created-before) and recreate (--vms-created-before) and wire them through to director calls.
  • Introduce TimeArg flag type with parsing + tests, and add request/CLI tests covering the new query parameter.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
director/interfaces.go Adds timestamp fields to recreate/update option structs.
director/deployment.go Plumbs timestamp into ChangeJobState/UpdateDeployment query params.
director/deployment_test.go Adds tests asserting the new query param is sent.
cmd/recreate.go Wires new recreate timestamp option into director recreate opts.
cmd/recreate_test.go Tests that recreate passes the timestamp through.
cmd/deploy.go Wires new deploy recreate timestamp option into director update opts.
cmd/deploy_test.go Tests that deploy passes the timestamp through.
cmd/opts/time_arg.go New flag type for parsing RFC3339(-like) timestamps.
cmd/opts/time_arg_test.go Unit tests for TimeArg parsing/formatting behavior.
cmd/opts/opts.go Adds CLI flags for the new timestamp filters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 104 to +108
updateOpts := boshdir.UpdateOpts{
RecreatePersistentDisks: opts.RecreatePersistentDisks,
Recreate: opts.Recreate,
Fix: opts.Fix,
SkipDrain: opts.SkipDrain,
DryRun: opts.DryRun,
Canaries: opts.Canaries,
MaxInFlight: opts.MaxInFlight,
Diff: deploymentDiff,
ForceLatestVariables: opts.ForceLatestVariables,
RecreatePersistentDisks: opts.RecreatePersistentDisks,
Recreate: opts.Recreate,
RecreateVMsCreatedBefore: opts.RecreateVMsCreatedBefore.Time,
Fix: opts.Fix,
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

DeployCmd always passes RecreateVMsCreatedBefore through to the director when the flag is set, but there’s no validation that --recreate was also provided (even though the flag description says it’s required). Add a check to error (or automatically imply Recreate=true) when a timestamp is provided without opts.Recreate, otherwise the director may reject/ignore the parameter.

Copilot uses AI. Check for mistakes.
Comment on lines +39 to 43
Canaries: opts.Canaries,
MaxInFlight: opts.MaxInFlight,
Converge: true,
VMsCreatedBefore: opts.VMsCreatedBefore.Time,
}
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

--vms-created-before is only applied in the converge branch. If a user runs recreate with --no-converge and provides this flag, it will be silently ignored. Consider validating and returning an error when VMsCreatedBefore is set together with --no-converge (or otherwise document/handle the behavior explicitly).

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +19
t, err := time.Parse(time.RFC3339, data)
if err != nil {
// Try RFC3339 without timezone suffix, assume UTC
// Format: "2006-01-02T15:04:05"
t, err = time.Parse("2006-01-02T15:04:05", data)
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

UnmarshalFlag uses time.Parse(time.RFC3339, ...), which rejects valid RFC 3339 timestamps that include fractional seconds (e.g. 2026-01-01T00:00:00.123Z). If the flag is documented as “RFC 3339”, consider trying time.RFC3339Nano (or accepting both) so users can paste timestamps produced by common tooling.

Copilot uses AI. Check for mistakes.
func (a TimeArg) AsString() string {
if a.IsSet() {
// Always output in UTC with Z suffix for consistency
return a.Format(time.RFC3339)
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

AsString’s comment says it always outputs UTC with a Z suffix, but it calls a.Format(time.RFC3339) directly. If TimeArg is constructed programmatically with a non-UTC location, this will output an offset instead of Z. Consider formatting a.UTC() (or enforcing UTC on assignment) to match the documented behavior.

Suggested change
return a.Format(time.RFC3339)
return a.UTC().Format(time.RFC3339)

Copilot uses AI. Check for mistakes.
@beyhan beyhan moved this from Pending Merge | Prioritized to Waiting for Changes | Open for Contribution in Foundational Infrastructure Working Group Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Waiting for Changes | Open for Contribution

Development

Successfully merging this pull request may close these issues.

3 participants