Skip to content

Commit

Permalink
Add request-evict-only annotation to virt-launcher pods
Browse files Browse the repository at this point in the history
Add the `descheduler.alpha.kubernetes.io/request-evict-only` annotation
to virt-launcher pods.
This annotation should be added to already running pods too.
ref: kubevirt/community#258

Signed-off-by: fossedihelm <[email protected]>
  • Loading branch information
fossedihelm committed Jun 6, 2024
1 parent a1c1c67 commit 9f109a3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,8 @@ func generatePodAnnotations(vmi *v1.VirtualMachineInstance, config *virtconfig.C
// Set this annotation now to indicate that the newly created virt-launchers will use
// unix sockets as a transport for migration
annotationsSet[v1.MigrationTransportUnixAnnotation] = "true"
annotationsSet[v1.DeschedulerRequestEvictOnlyAnnotation] = ""

return annotationsSet, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/virt-controller/services/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ var _ = Describe("Template", func() {
"post.hook.backup.velero.io/command": "[\"/usr/bin/virt-freezer\", \"--unfreeze\", \"--name\", \"testvmi\", \"--namespace\", \"testns\"]",
"kubevirt.io/migrationTransportUnix": "true",
"kubectl.kubernetes.io/default-container": "compute",
v1.DeschedulerRequestEvictOnlyAnnotation: "",
}))
Expect(pod.ObjectMeta.OwnerReferences).To(Equal([]metav1.OwnerReference{{
APIVersion: v1.VirtualMachineInstanceGroupVersionKind.GroupVersion().String(),
Expand Down
15 changes: 8 additions & 7 deletions pkg/virt-controller/watch/vmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -1271,14 +1272,14 @@ func (c *VMIController) sync(vmi *virtv1.VirtualMachineInstance, pod *k8sv1.Pod,
}

if !isTempPod(pod) && isPodReady(pod) {
newAnnotations := network.GeneratePodAnnotations(vmi.Spec.Networks, vmi.Spec.Domain.Devices.Interfaces, pod.Annotations[networkv1.NetworkStatusAnnot], c.clusterConfig.GetNetworkBindings())
if len(newAnnotations) != 0 {
patchedPod, err := c.syncPodAnnotations(pod, newAnnotations)
if err != nil {
return &syncErrorImpl{err, FailedPodPatchReason}
}
*pod = *patchedPod
newAnnotations := map[string]string{virtv1.DeschedulerRequestEvictOnlyAnnotation: ""}
maps.Copy(newAnnotations, network.GeneratePodAnnotations(vmi.Spec.Networks, vmi.Spec.Domain.Devices.Interfaces, pod.Annotations[networkv1.NetworkStatusAnnot], c.clusterConfig.GetNetworkBindings()))

patchedPod, err := c.syncPodAnnotations(pod, newAnnotations)
if err != nil {
return &syncErrorImpl{err, FailedPodPatchReason}
}
*pod = *patchedPod

hotplugVolumes := getHotplugVolumes(vmi, pod)
hotplugAttachmentPods, err := controller.AttachmentPods(pod, c.podIndexer)
Expand Down
3 changes: 2 additions & 1 deletion pkg/virt-controller/watch/vmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3942,7 +3942,8 @@ func setDataVolumeCondition(dv *cdiv1.DataVolume, cond cdiv1.DataVolumeCondition

func NewPodForVirtualMachine(vmi *virtv1.VirtualMachineInstance, phase k8sv1.PodPhase) *k8sv1.Pod {
podAnnotations := map[string]string{
virtv1.DomainAnnotation: vmi.Name,
virtv1.DomainAnnotation: vmi.Name,
virtv1.DeschedulerRequestEvictOnlyAnnotation: "",
}
return &k8sv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand Down
5 changes: 5 additions & 0 deletions staging/src/kubevirt.io/api/core/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,11 @@ const (
// in which freePageReporting is always disabled.
FreePageReportingDisabledAnnotation string = "kubevirt.io/free-page-reporting-disabled"

// DeschedulerRequestEvictOnlyAnnotation indicates pods whose eviction is not expected to be completed right away.
// Instead, an eviction request is expected to be intercepted by an external component which will initiate the
// eviction process for the pod.
DeschedulerRequestEvictOnlyAnnotation string = "descheduler.alpha.kubernetes.io/request-evict-only"

// VirtualMachinePodCPULimitsLabel indicates VMI pod CPU resource limits
VirtualMachinePodCPULimitsLabel string = "kubevirt.io/vmi-pod-cpu-resource-limits"
// VirtualMachinePodMemoryRequestsLabel indicates VMI pod Memory resource requests
Expand Down

0 comments on commit 9f109a3

Please sign in to comment.