diff --git a/pkg/virt-api/webhooks/validating-webhook/validating-webhook.go b/pkg/virt-api/webhooks/validating-webhook/validating-webhook.go index 79fef3a2db78..eb4c489faf2a 100644 --- a/pkg/virt-api/webhooks/validating-webhook/validating-webhook.go +++ b/pkg/virt-api/webhooks/validating-webhook/validating-webhook.go @@ -1729,11 +1729,13 @@ func admitMigrationCreate(ar *v1beta1.AdmissionReview) *v1beta1.AdmissionRespons } // Reject migration jobs for non-migratable VMIs - cond := getVMIMigrationCondition(vmi) - if cond != nil && cond.Status == k8sv1.ConditionFalse { - errMsg := fmt.Errorf("Cannot migrate VMI, Reason: %s, Message: %s", - cond.Reason, cond.Message) - return webhooks.ToAdmissionResponseError(errMsg) + for _, c := range vmi.Status.Conditions { + if c.Type == v1.VirtualMachineInstanceIsMigratable && + c.Status == k8sv1.ConditionFalse { + errMsg := fmt.Errorf("Cannot migrate VMI, Reason: %s, Message: %s", + c.Reason, c.Message) + return webhooks.ToAdmissionResponseError(errMsg) + } } // Don't allow new migration jobs to be introduced when previous migration jobs @@ -1751,15 +1753,6 @@ func admitMigrationCreate(ar *v1beta1.AdmissionReview) *v1beta1.AdmissionRespons return &reviewResponse } -func getVMIMigrationCondition(vmi *v1.VirtualMachineInstance) (cond *v1.VirtualMachineInstanceCondition) { - for _, c := range vmi.Status.Conditions { - if c.Type == v1.VirtualMachineInstanceIsMigratable { - cond = &c - } - } - return cond -} - func ServeMigrationCreate(resp http.ResponseWriter, req *http.Request) { serve(resp, req, admitMigrationCreate) } diff --git a/pkg/virt-api/webhooks/validating-webhook/validating-webhook_test.go b/pkg/virt-api/webhooks/validating-webhook/validating-webhook_test.go index d92eb9eb1147..1d8d5372929b 100644 --- a/pkg/virt-api/webhooks/validating-webhook/validating-webhook_test.go +++ b/pkg/virt-api/webhooks/validating-webhook/validating-webhook_test.go @@ -864,7 +864,7 @@ var _ = Describe("Validating Webhook", func() { It("should reject Migration spec for non-migratable VMIs", func() { vmi := v1.NewMinimalVMI("testmigratevmi3") - vmi.Status.Phase = v1.Succeeded + vmi.Status.Phase = v1.Running vmi.Status.Conditions = []v1.VirtualMachineInstanceCondition{ { Type: v1.VirtualMachineInstanceIsMigratable, @@ -872,6 +872,10 @@ var _ = Describe("Validating Webhook", func() { Reason: v1.VirtualMachineInstanceReasonDisksNotMigratable, Message: "cannot migrate VMI with mixes shared and non-shared volumes", }, + { + Type: v1.VirtualMachineInstanceReady, + Status: k8sv1.ConditionTrue, + }, } informers := webhooks.GetInformers() @@ -900,6 +904,7 @@ var _ = Describe("Validating Webhook", func() { resp := admitMigrationCreate(ar) Expect(resp.Allowed).To(Equal(false)) + Expect(resp.Result.Message).To(ContainSubstring("DisksNotLiveMigratable")) }) It("should reject Migration on update if spec changes", func() {