Skip to content

Commit

Permalink
fix migration api validation for non-migratable vmis
Browse files Browse the repository at this point in the history
Signed-off-by: Vladik Romanovsky <[email protected]>
  • Loading branch information
vladikr committed Mar 4, 2019
1 parent 629e7a6 commit 7999b8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
21 changes: 7 additions & 14 deletions pkg/virt-api/webhooks/validating-webhook/validating-webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,14 +864,18 @@ 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,
Status: k8sv1.ConditionFalse,
Reason: v1.VirtualMachineInstanceReasonDisksNotMigratable,
Message: "cannot migrate VMI with mixes shared and non-shared volumes",
},
{
Type: v1.VirtualMachineInstanceReady,
Status: k8sv1.ConditionTrue,
},
}

informers := webhooks.GetInformers()
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 7999b8d

Please sign in to comment.