Skip to content

Commit

Permalink
Merge pull request kubevirt#2794 from slintes/suspend
Browse files Browse the repository at this point in the history
Pause and Unpause
  • Loading branch information
kubevirt-bot authored Nov 12, 2019
2 parents e4d3c3c + 19aa577 commit 21c2f3e
Show file tree
Hide file tree
Showing 51 changed files with 2,107 additions and 222 deletions.
76 changes: 76 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3716,6 +3716,44 @@
}
}
},
"/apis/subresources.kubevirt.io/v1alpha3/namespaces/{namespace}/virtualmachineinstances/{name}/pause": {
"put": {
"summary": "Pause a VirtualMachineInstance object.",
"operationId": "pause",
"parameters": [
{
"pattern": "[a-z0-9][a-z0-9\\-]*",
"type": "string",
"description": "Object name and auth scope, such as for teams and projects",
"name": "namespace",
"in": "path",
"required": true
},
{
"pattern": "[a-z0-9][a-z0-9\\-]*",
"type": "string",
"description": "Name of the resource",
"name": "name",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Bad Request"
},
"404": {
"description": "Not Found"
},
"default": {
"description": "OK"
}
}
}
},
"/apis/subresources.kubevirt.io/v1alpha3/namespaces/{namespace}/virtualmachineinstances/{name}/test": {
"get": {
"summary": "Test endpoint verifying apiserver connectivity.",
Expand Down Expand Up @@ -3745,6 +3783,44 @@
}
}
},
"/apis/subresources.kubevirt.io/v1alpha3/namespaces/{namespace}/virtualmachineinstances/{name}/unpause": {
"put": {
"summary": "Unpause a VirtualMachineInstance object.",
"operationId": "unpause",
"parameters": [
{
"pattern": "[a-z0-9][a-z0-9\\-]*",
"type": "string",
"description": "Object name and auth scope, such as for teams and projects",
"name": "namespace",
"in": "path",
"required": true
},
{
"pattern": "[a-z0-9][a-z0-9\\-]*",
"type": "string",
"description": "Name of the resource",
"name": "name",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Bad Request"
},
"404": {
"description": "Not Found"
},
"default": {
"description": "OK"
}
}
}
},
"/apis/subresources.kubevirt.io/v1alpha3/namespaces/{namespace}/virtualmachineinstances/{name}/vnc": {
"get": {
"summary": "Open a websocket connection to connect to VNC on the specified VirtualMachineInstance.",
Expand Down
11 changes: 9 additions & 2 deletions cmd/virt-handler/virt-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ func (app *virtHandlerApp) Run() {
vmiInformer,
)

lifecycleHandler := rest.NewLifecycleHandler(
vmiInformer,
app.VirtShareDir,
)

certsDirectory, err := ioutil.TempDir("", "certsdir")
if err != nil {
panic(err)
Expand All @@ -335,7 +340,7 @@ func (app *virtHandlerApp) Run() {

errCh := make(chan error)
go app.runPrometheusServer(errCh, certStore)
go app.runConsoleServer(errCh, consoleHandler)
go app.runServer(errCh, consoleHandler, lifecycleHandler)

// wait for one of the servers to exit
<-errCh
Expand All @@ -347,10 +352,12 @@ func (app *virtHandlerApp) runPrometheusServer(errCh chan error, certStore certi
errCh <- http.ListenAndServeTLS(app.ServiceListen.Address(), certStore.CurrentPath(), certStore.CurrentPath(), nil)
}

func (app *virtHandlerApp) runConsoleServer(errCh chan error, consoleHandler *rest.ConsoleHandler) {
func (app *virtHandlerApp) runServer(errCh chan error, consoleHandler *rest.ConsoleHandler, lifecycleHandler *rest.LifecycleHandler) {
ws := new(restful.WebService)
ws.Route(ws.GET("/v1/namespaces/{namespace}/virtualmachineinstances/{name}/console").To(consoleHandler.SerialHandler))
ws.Route(ws.GET("/v1/namespaces/{namespace}/virtualmachineinstances/{name}/vnc").To(consoleHandler.VNCHandler))
ws.Route(ws.PUT("/v1/namespaces/{namespace}/virtualmachineinstances/{name}/pause").To(lifecycleHandler.PauseHandler))
ws.Route(ws.PUT("/v1/namespaces/{namespace}/virtualmachineinstances/{name}/unpause").To(lifecycleHandler.UnpauseHandler))
restful.DefaultContainer.Add(ws)
server := &http.Server{
Addr: fmt.Sprintf("%s:%d", app.ServiceListen.BindAddress, app.consoleServerPort),
Expand Down
4 changes: 4 additions & 0 deletions manifests/generated/operator-csv.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ spec:
resources:
- virtualmachineinstances/console
- virtualmachineinstances/vnc
- virtualmachineinstances/pause
- virtualmachineinstances/unpause
verbs:
- get
- apiGroups:
Expand Down Expand Up @@ -578,6 +580,8 @@ spec:
resources:
- virtualmachineinstances/console
- virtualmachineinstances/vnc
- virtualmachineinstances/pause
- virtualmachineinstances/unpause
verbs:
- get
- apiGroups:
Expand Down
4 changes: 4 additions & 0 deletions manifests/generated/rbac-cluster.authorization.k8s.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ rules:
resources:
- virtualmachineinstances/console
- virtualmachineinstances/vnc
- virtualmachineinstances/pause
- virtualmachineinstances/unpause
verbs:
- get
- apiGroups:
Expand Down Expand Up @@ -91,6 +93,8 @@ rules:
resources:
- virtualmachineinstances/console
- virtualmachineinstances/vnc
- virtualmachineinstances/pause
- virtualmachineinstances/unpause
verbs:
- get
- apiGroups:
Expand Down
4 changes: 4 additions & 0 deletions manifests/generated/rbac-operator.authorization.k8s.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ rules:
resources:
- virtualmachineinstances/console
- virtualmachineinstances/vnc
- virtualmachineinstances/pause
- virtualmachineinstances/unpause
verbs:
- get
- apiGroups:
Expand Down Expand Up @@ -433,6 +435,8 @@ rules:
resources:
- virtualmachineinstances/console
- virtualmachineinstances/vnc
- virtualmachineinstances/pause
- virtualmachineinstances/unpause
verbs:
- get
- apiGroups:
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (d *VirtualMachineConditionManager) CheckFailure(vmi *v1.VirtualMachineInst
}

func (d *VirtualMachineConditionManager) HasCondition(vmi *v1.VirtualMachineInstance, cond v1.VirtualMachineInstanceConditionType) bool {
if vmi == nil {
return false
}
for _, c := range vmi.Status.Conditions {
if c.Type == cond {
return true
Expand Down
65 changes: 47 additions & 18 deletions pkg/controller/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,61 @@
package controller

import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

v12 "k8s.io/api/core/v1"

v1 "kubevirt.io/client-go/api/v1"
)

func TestAddPodCondition(t *testing.T) {
var _ = Describe("VirtualMachineInstance ConditionManager", func() {

vmi := v1.NewMinimalVMI("test")
var vmi *v1.VirtualMachineInstance
var cm *VirtualMachineConditionManager
var pc1 *v12.PodCondition
var pc2 *v12.PodCondition

pc1 := &v12.PodCondition{
Type: v12.PodScheduled,
Status: v12.ConditionFalse,
}
pc2 := &v12.PodCondition{
Type: v12.PodScheduled,
Status: v12.ConditionTrue,
}
BeforeEach(func() {
vmi = v1.NewMinimalVMI("test")

cm := NewVirtualMachineInstanceConditionManager()
pc1 = &v12.PodCondition{
Type: v12.PodScheduled,
Status: v12.ConditionFalse,
}
pc2 = &v12.PodCondition{
Type: v12.PodScheduled,
Status: v12.ConditionTrue,
}

cm.AddPodCondition(vmi, pc1)
cm.AddPodCondition(vmi, pc2)
cm = NewVirtualMachineInstanceConditionManager()
})

if len(vmi.Status.Conditions) != 1 {
t.Errorf("There should be exactly 1 condition when muliple conditions of the same type were added")
}
}
When("Adding a condition", func() {

It("should report condition available", func() {
cm.AddPodCondition(vmi, pc1)
Expect(cm.HasCondition(vmi, v1.VirtualMachineInstanceConditionType(pc1.Type))).To(BeTrue())
})

It("should report different condition not available", func() {
cm.AddPodCondition(vmi, pc1)
Expect(cm.HasCondition(vmi, v1.VirtualMachineInstanceConditionType(v12.PodInitialized))).To(BeFalse())
})

When("adding a 2nd condition of same type", func() {
It("should only have 1 condition", func() {
cm.AddPodCondition(vmi, pc1)
cm.AddPodCondition(vmi, pc2)
Expect(len(vmi.Status.Conditions)).To(Equal(1))
})
})
})

When("VMI is nil", func() {
It("should gracefully report condition not available", func() {
var vmi2 *v1.VirtualMachineInstance
Expect(cm.HasCondition(vmi2, v1.VirtualMachineInstanceConditionType(pc1.Type))).To(BeFalse())
})
})
})
Loading

0 comments on commit 21c2f3e

Please sign in to comment.