Skip to content

Commit

Permalink
Merge pull request kubevirt#3258 from rmohr/custom-scheduler
Browse files Browse the repository at this point in the history
Support setting custom schedulers on VMIs
  • Loading branch information
kubevirt-bot authored Apr 18, 2020
2 parents 75ac971 + 371b1f0 commit e424f09
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6933,6 +6933,10 @@
"description": "Periodic probe of VirtualMachineInstance service readiness.\nVirtualmachineInstances will be removed from service endpoints if the probe fails.\nCannot be updated.\nMore info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes\n+optional",
"$ref": "#/definitions/v1.Probe"
},
"schedulerName": {
"description": "If specified, the VMI will be dispatched by specified scheduler.\nIf not specified, the VMI will be dispatched by default scheduler.\n+optional",
"type": "string"
},
"subdomain": {
"description": "If specified, the fully qualified vmi hostname will be \"\u003chostname\u003e.\u003csubdomain\u003e.\u003cpod namespace\u003e.svc.\u003ccluster domain\u003e\".\nIf not specified, the vmi will not have a domainname at all. The DNS entry will resolve to the vmi,\nno matter if the vmi itself can pick up a hostname.\n+optional",
"type": "string"
Expand Down
2 changes: 2 additions & 0 deletions pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,8 @@ func (t *templateService) RenderLaunchManifest(vmi *v1.VirtualMachineInstance) (

pod.Spec.Tolerations = vmi.Spec.Tolerations

pod.Spec.SchedulerName = vmi.Spec.SchedulerName

if len(serviceAccountName) > 0 {
pod.Spec.ServiceAccountName = serviceAccountName
automount := true
Expand Down
13 changes: 13 additions & 0 deletions pkg/virt-controller/services/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,19 @@ var _ = Describe("Template", func() {
Expect(pod.Spec.Tolerations).To(BeEquivalentTo([]kubev1.Toleration{{Key: podToleration.Key, TolerationSeconds: &tolerationSeconds}}))
})

It("should add the scheduler name to the pod", func() {
vm := v1.VirtualMachineInstance{
ObjectMeta: metav1.ObjectMeta{Name: "testvm", Namespace: "default", UID: "1234"},
Spec: v1.VirtualMachineInstanceSpec{
SchedulerName: "test-scheduler",
Domain: v1.DomainSpec{},
},
}
pod, err := svc.RenderLaunchManifest(&vm)
Expect(err).ToNot(HaveOccurred())
Expect(pod.Spec.SchedulerName).To(Equal("test-scheduler"))
})

It("should use the hostname and subdomain if specified on the vm", func() {
vmi := v1.VirtualMachineInstance{
ObjectMeta: metav1.ObjectMeta{Name: "testvm",
Expand Down
12 changes: 12 additions & 0 deletions staging/src/kubevirt.io/client-go/api/v1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import (

var _ = Describe("Defaults", func() {

It("should leave the scheduler name unset by default", func() {
vmi := &VirtualMachineInstance{}
SetObjectDefaults_VirtualMachineInstance(vmi)
Expect(vmi.Spec.SchedulerName).To(BeEmpty())
})

It("should take a custom scheduler if specified", func() {
vmi := &VirtualMachineInstance{Spec: VirtualMachineInstanceSpec{SchedulerName: "custom-one"}}
SetObjectDefaults_VirtualMachineInstance(vmi)
Expect(vmi.Spec.SchedulerName).To(Equal("custom-one"))
})

It("should add ACPI feature if it is unspecified", func() {
vmi := &VirtualMachineInstance{}
SetObjectDefaults_VirtualMachineInstance(vmi)
Expand Down
7 changes: 7 additions & 0 deletions staging/src/kubevirt.io/client-go/api/v1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions staging/src/kubevirt.io/client-go/api/v1/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ var _ = Describe("Schema", func() {
},
},
}

policy := IOThreadsPolicyShared
exampleVMI.Spec.Domain.IOThreadsPolicy = &policy

Expand Down
4 changes: 4 additions & 0 deletions staging/src/kubevirt.io/client-go/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ type VirtualMachineInstanceSpec struct {
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// If affinity is specifies, obey all the affinity rules
Affinity *k8sv1.Affinity `json:"affinity,omitempty"`
// If specified, the VMI will be dispatched by specified scheduler.
// If not specified, the VMI will be dispatched by default scheduler.
// +optional
SchedulerName string `json:"schedulerName,omitempty"`
// If toleration is specified, obey all the toleration rules.
Tolerations []k8sv1.Toleration `json:"tolerations,omitempty"`

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/vmi_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,16 @@ var _ = Describe("Configurations", func() {
})
})

Context("with a custom scheduler", func() {
It("schould set the custom scheduler on the pod", func() {
vmi := tests.NewRandomVMI()
vmi.Spec.SchedulerName = "my-custom-scheduler"
runningVMI := tests.RunVMIAndExpectScheduling(vmi, 30)
launcherPod := tests.GetPodByVirtualMachineInstance(runningVMI, tests.NamespaceTestDefault)
Expect(launcherPod.Spec.SchedulerName).To(Equal("my-custom-scheduler"))
})
})

Context("[rfe_id:140][crit:medium][vendor:[email protected]][level:component]with CPU request settings", func() {
defaultCPURequestKey := "cpu-request"

Expand Down

0 comments on commit e424f09

Please sign in to comment.