Skip to content

Commit

Permalink
Block pausing of VMIs with LivenessProbe
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Sluiter <[email protected]>
  • Loading branch information
slintes committed Nov 5, 2019
1 parent bad7772 commit 53177fa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/virt-api/rest/subresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ func (app *SubresourceAPIApp) PauseVMIRequestHandler(request *restful.Request, r
if vmi == nil || vmi.Status.Phase != v1.Running {
return fmt.Errorf("VMI is not running"), http.StatusForbidden
}
if vmi.Spec.LivenessProbe != nil {
return fmt.Errorf("Pausing VMIs with LivenessProbe is currently not supported"), http.StatusForbidden
}
condManager := controller.NewVirtualMachineInstanceConditionManager()
if condManager.HasCondition(vmi, v1.VirtualMachineInstancePaused) {
return fmt.Errorf("VMI is already paused"), http.StatusForbidden
Expand Down
31 changes: 31 additions & 0 deletions tests/pausing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"strings"
"time"

"k8s.io/apimachinery/pkg/util/intstr"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -90,6 +92,35 @@ var _ = Describe("[rfe_id:3064][crit:medium][vendor:[email protected]][level:com
tests.WaitForVMIConditionRemovedOrFalse(virtClient, vmi, v1.VirtualMachineInstancePaused, 30)
})
})

Context("with a LivenessProbe configured", func() {
When("paused via virtctl", func() {
It("should not be paused", func() {
By("Launching a VMI with LivenessProbe")
vmi = tests.NewRandomVMIWithEphemeralDisk(tests.ContainerDiskFor(tests.ContainerDiskCirros))
// a random probe wich will not fail immediately
vmi.Spec.LivenessProbe = &v1.Probe{
Handler: v1.Handler{
HTTPGet: &k8sv1.HTTPGetAction{
Path: "/something",
Port: intstr.FromInt(8080),
},
},
InitialDelaySeconds: 120,
TimeoutSeconds: 120,
PeriodSeconds: 120,
SuccessThreshold: 1,
FailureThreshold: 1,
}
tests.RunVMIAndExpectLaunch(vmi, 90)

By("Pausing it")
command := tests.NewRepeatableVirtctlCommand("pause", "vmi", "--namespace", tests.NamespaceTestDefault, vmi.Name)
err := command()
Expect(err.Error()).To(ContainSubstring("Pausing VMIs with LivenessProbe is currently not supported"))
})
})
})
})

Context("A valid VM", func() {
Expand Down

0 comments on commit 53177fa

Please sign in to comment.