Skip to content

Commit

Permalink
copy the migration config to vmi migration status
Browse files Browse the repository at this point in the history
Signed-off-by: Vladik Romanovsky <[email protected]>
  • Loading branch information
vladikr committed Mar 1, 2019
1 parent fd5fe85 commit da12ac3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/virt-controller/watch/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@ func (c *MigrationController) sync(migration *virtv1.VirtualMachineInstanceMigra
SourceNode: vmi.Status.NodeName,
TargetPod: pod.Name,
}
if migration.Spec.Config != nil {
completionTimeout := migration.Spec.Config.CompletionTimeoutPerGiB
progressTimeout := migration.Spec.Config.ProgressTimeout
if completionTimeout != 0 {
vmiCopy.Status.MigrationState.CompletionTimeoutPerGiB = completionTimeout
}
if progressTimeout != 0 {
vmiCopy.Status.MigrationState.ProgressTimeout = progressTimeout
}
}

// By setting this label, virt-handler on the target node will receive
// the vmi and prepare the local environment for the migration
Expand Down
34 changes: 34 additions & 0 deletions pkg/virt-controller/watch/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ var _ = Describe("Migration watcher", func() {

}).Return(vmi, nil)
}
shouldExpectVirtualMachineHandoffWithConfig := func(vmi *v1.VirtualMachineInstance, migrationUid types.UID, targetNode string, conf *v1.MigrationConfig) {
vmiInterface.EXPECT().Update(gomock.Any()).Do(func(arg interface{}) {
Expect(arg.(*v1.VirtualMachineInstance).Status.MigrationState).ToNot(BeNil())
Expect(arg.(*v1.VirtualMachineInstance).Status.MigrationState.MigrationUID).To(Equal(migrationUid))

Expect(arg.(*v1.VirtualMachineInstance).Status.MigrationState.SourceNode).To(Equal(vmi.Status.NodeName))
Expect(arg.(*v1.VirtualMachineInstance).Status.MigrationState.TargetNode).To(Equal(targetNode))
Expect(arg.(*v1.VirtualMachineInstance).Labels[v1.MigrationTargetNodeNameLabel]).To(Equal(targetNode))
Expect(arg.(*v1.VirtualMachineInstance).Status.MigrationState.CompletionTimeoutPerGiB).To(Equal(conf.CompletionTimeoutPerGiB))
Expect(arg.(*v1.VirtualMachineInstance).Status.MigrationState.ProgressTimeout).To(Equal(conf.ProgressTimeout))
}).Return(vmi, nil)
}

syncCaches := func(stop chan struct{}) {
go vmiInformer.Run(stop)
Expand Down Expand Up @@ -398,6 +410,28 @@ var _ = Describe("Migration watcher", func() {
controller.Execute()
testutils.ExpectEvent(recorder, SuccessfulHandOverPodReason)
})
It("should hand pod over to target virt-handler with migration config", func() {
vmi := newVirtualMachine("testvmi", v1.Running)
vmi.Status.NodeName = "node02"
migration := newMigration("testmigration", vmi.Name, v1.MigrationScheduled)
migrationConfig := &v1.MigrationConfig{
CompletionTimeoutPerGiB: 300,
ProgressTimeout: 100,
}
migration.Spec.Config = migrationConfig

pod := newTargetPodForVirtualMachine(vmi, migration, k8sv1.PodPending)
pod.Spec.NodeName = "node01"

addMigration(migration)
addVirtualMachine(vmi)
podFeeder.Add(pod)

shouldExpectVirtualMachineHandoffWithConfig(vmi, migration.UID, "node01", migrationConfig)

controller.Execute()
testutils.ExpectEvent(recorder, SuccessfulHandOverPodReason)
})

It("should hand pod over to target virt-handler overriding previous state", func() {
vmi := newVirtualMachine("testvmi", v1.Running)
Expand Down

0 comments on commit da12ac3

Please sign in to comment.