feat(migration): optional power-off of target VM after migration (#1867)#1950
Open
valentin-pf9 wants to merge 1 commit into
Open
feat(migration): optional power-off of target VM after migration (#1867)#1950valentin-pf9 wants to merge 1 commit into
valentin-pf9 wants to merge 1 commit into
Conversation
…ation Implements platform9#1867. By default the migrated VM boots powered-on in the target cloud (Nova starts it on creation). Operators who need to run post-migration tasks before first boot -- e.g. assigning security groups via script -- had no way to keep it off. Adds a powerOffTargetVm option that, when set, stops the target VM immediately after it is created and verified, and skips post-migration health checks (which require a running VM). The flag mirrors the existing disconnectSourceNetwork plumbing: - migrationplan_types.go: add PowerOffTargetVM to MigrationStrategy. - migration_types.go: add PowerOffTargetVM to MigrationSpec. - config/crd/bases: regenerated via 'make manifests'. - migrationplan_controller.go: copy the strategy flag onto each Migration spec and write POWER_OFF_TARGET_VM into the v2v-helper configmap. - v2v-helper/pkg/utils/vcenterutils.go: read POWER_OFF_TARGET_VM into MigrationParams. - v2v-helper/main.go: populate Migrate.PowerOffTargetVM and log it. - v2v-helper/migrate/migrate.go: new PowerOffTargetVM field; in CreateTargetInstance, after the VM is ACTIVE, stop it and skip health checks when the flag is set. New OpenStack operation: - openstack.OpenstackOperations gains StopServer, which issues servers.Stop and polls until the server reaches SHUTOFF (reusing the VMActiveWait retry settings). Impl in openstackopsutils.go, mock in openstackops_mock.go. Tests: - TestCreateTargetInstance_PowerOffTargetVM asserts StopServer is called exactly once when PowerOffTargetVM is set. deploy/installer.yaml + deploy/00crds.yaml regenerated by the pre-commit make build-installer hook. Backend only -- a UI checkbox ('Keep Target VM Powered Off') will follow in a separate PR. The capability is usable now via the MigrationPlan CRD. Test plan: - go build ./... (k8s/migration): OK. - go test ./pkg/utils/... (k8s/migration): OK. - CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build ./... (v2v-helper): OK. - v2v-helper migrate tests not runnable locally (blocked by the pre-existing CreateVM mock build break on main, addressed by platform9#1945); TestCreateTargetInstance_PowerOffTargetVM runs in CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #1867.
By default the migrated VM boots powered-on in the target cloud — Nova starts it on creation. Operators who need to run post-migration tasks before first boot (the issue's example: assigning security groups via script) had no way to keep it off.
This adds a
powerOffTargetVmoption. When set, the target VM is stopped immediately after it's created and verified ACTIVE, and post-migration health checks are skipped (they require a running VM).Design
The flag mirrors the existing
disconnectSourceNetworkplumbing end-to-end — an established pattern:migrationplan_types.go—PowerOffTargetVMadded toMigrationStrategy.migration_types.go—PowerOffTargetVMadded toMigrationSpec.config/crd/bases/*— regenerated viamake manifests.migrationplan_controller.go— copies the strategy flag onto each Migration's spec, and writesPOWER_OFF_TARGET_VMinto the v2v-helper configmap.vcenterutils.go— readsPOWER_OFF_TARGET_VMintoMigrationParams.main.go— populatesMigrate.PowerOffTargetVMand logs it.migrate.go— newPowerOffTargetVMfield; inCreateTargetInstance, after the VM is ACTIVE, stops it and skips health checks when the flag is set.New OpenStack operation
OpenstackOperationsgainsStopServer, which issuesservers.Stopand polls until the server reachesSHUTOFF(reusing the existingVMActiveWaitretry settings). Implementation inopenstackopsutils.go, mock inopenstackops_mock.go.Tests
TestCreateTargetInstance_PowerOffTargetVMassertsStopServeris called exactly once whenPowerOffTargetVMis set.Verified locally:
go build ./...(k8s/migration) — OKgo test ./pkg/utils/...(k8s/migration) — OKCGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build ./...(v2v-helper) — OKThe v2v-helper
migratepackage test suite can't be built locally because of a pre-existingCreateVMmock mismatch onmain(addressed by #1945).TestCreateTargetInstance_PowerOffTargetVMwill run in CI.Scope
Backend only. A UI checkbox ("Keep Target VM Powered Off", as the issue suggests) will follow in a separate PR. The capability is usable now via the MigrationPlan CRD / CLI: