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

Fixes migration controller null pointer dereference #5694

Merged
merged 2 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/virt-controller/watch/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ func (c *MigrationController) sync(key string, migration *virtv1.VirtualMachineI
}
case virtv1.MigrationPreparingTarget, virtv1.MigrationTargetReady, virtv1.MigrationFailed:
if (!podExists || podIsDown(pod)) &&
vmi.Status.MigrationState != nil &&
len(vmi.Status.MigrationState.TargetDirectMigrationNodePorts) == 0 &&
vmi.Status.MigrationState.StartTimestamp == nil &&
!vmi.Status.MigrationState.Failed &&
Expand Down
31 changes: 20 additions & 11 deletions pkg/virt-controller/watch/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,18 @@ var _ = Describe("Migration watcher", func() {
controller.Execute()
testutils.ExpectEvent(recorder, SuccessfulAbortMigrationReason)
})
table.DescribeTable("should finalize migration on VMI if target pod fails before migration starts", func(phase v1.VirtualMachineInstanceMigrationPhase, hasPod bool, podPhase k8sv1.PodPhase) {
table.DescribeTable("should finalize migration on VMI if target pod fails before migration starts", func(phase v1.VirtualMachineInstanceMigrationPhase, hasPod bool, podPhase k8sv1.PodPhase, initializeMigrationState bool) {
vmi := newVirtualMachine("testvmi", v1.Running)
vmi.Status.NodeName = "node02"
migration := newMigration("testmigration", vmi.Name, phase)

vmi.Status.MigrationState = &v1.VirtualMachineInstanceMigrationState{
MigrationUID: migration.UID,
TargetNode: "node01",
SourceNode: "node02",
vmi.Status.MigrationState = nil
if initializeMigrationState {
vmi.Status.MigrationState = &v1.VirtualMachineInstanceMigrationState{
MigrationUID: migration.UID,
TargetNode: "node01",
SourceNode: "node02",
}
}
addMigration(migration)
addVirtualMachineInstance(vmi)
Expand All @@ -790,19 +793,25 @@ var _ = Describe("Migration watcher", func() {
shouldExpectMigrationFailedState(migration)
}

vmiInterface.EXPECT().Patch(vmi.Name, types.JSONPatchType, gomock.Any()).Return(vmi, nil)
if initializeMigrationState {
patch := `[{ "op": "test", "path": "/status/migrationState", "value": {"targetNode":"node01","sourceNode":"node02","migrationUid":"testmigration"} }, { "op": "replace", "path": "/status/migrationState", "value": {"startTimestamp":"2021-05-24T14:51:47Z","endTimestamp":"2021-05-24T14:51:47Z","targetNode":"node01","sourceNode":"node02","completed":true,"failed":true,"migrationUid":"testmigration"} }]`
shouldExpectVirtualMachineInstancePatch(vmi, patch)
}
controller.Execute()

// in this case, we have two failed events. one for the VMI and one on the Migration object.
testutils.ExpectEvent(recorder, FailedMigrationReason)
if initializeMigrationState {
testutils.ExpectEvent(recorder, FailedMigrationReason)
}
if phase != v1.MigrationFailed {
testutils.ExpectEvent(recorder, FailedMigrationReason)
}
},
table.Entry("in preparing target state", v1.MigrationPreparingTarget, true, k8sv1.PodFailed),
table.Entry("in target ready state", v1.MigrationTargetReady, true, k8sv1.PodFailed),
table.Entry("in failed state", v1.MigrationFailed, true, k8sv1.PodFailed),
table.Entry("in failed state and pod does not exist", v1.MigrationFailed, false, k8sv1.PodFailed),
table.Entry("in preparing target state", v1.MigrationPreparingTarget, true, k8sv1.PodFailed, true),
table.Entry("in target ready state", v1.MigrationTargetReady, true, k8sv1.PodFailed, true),
table.Entry("in failed state", v1.MigrationFailed, true, k8sv1.PodFailed, true),
table.Entry("in failed state before pod is created", v1.MigrationFailed, false, k8sv1.PodFailed, false),
table.Entry("in failed state and pod does not exist", v1.MigrationFailed, false, k8sv1.PodFailed, false),
)
})
})
Expand Down