Skip to content

Commit

Permalink
safe evict to communicate with volcano
Browse files Browse the repository at this point in the history
Signed-off-by: gj199575 <409237405@qq.com>
  • Loading branch information
gj409237405 committed Jul 19, 2023
1 parent d9b763a commit 7966c11
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pkg/descheduler/evictions/evictions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package evictions
import (
"context"
"fmt"
"time"

v1 "k8s.io/api/core/v1"
policy "k8s.io/api/policy/v1"
Expand Down Expand Up @@ -173,6 +174,26 @@ func (pe *PodEvictor) EvictPod(ctx context.Context, pod *v1.Pod, opts EvictOptio
}

func evictPod(ctx context.Context, client clientset.Interface, pod *v1.Pod, policyGroupVersion string) error {
fakePod := NewFakePod(pod)
createOptions := metav1.CreateOptions{}
create, err2 := client.CoreV1().Pods(pod.Namespace).Create(ctx, fakePod, createOptions)
klog.Info(create, err2)

getOptions := metav1.GetOptions{}
for {
getPod, getError := client.CoreV1().Pods(fakePod.Namespace).Get(ctx, fakePod.Name, getOptions)
klog.Info(getPod, getError)
time.Sleep(time.Second)
if getPod.Annotations[FakePod] != "" {
deleteError := client.CoreV1().Pods(fakePod.Namespace).Delete(ctx, fakePod.Name, metav1.DeleteOptions{})
klog.Info(deleteError)
break
}
}
pod.Annotations["scheduling.k8s.io/group-name"] = "job1-e7f18111-1cec-11ea-b688-fa163ec79500"
update, err2 := client.CoreV1().Pods(pod.Namespace).Update(context.TODO(), pod, metav1.UpdateOptions{})
fmt.Println(update, err2)

deleteOptions := &metav1.DeleteOptions{}
// GracePeriodSeconds ?
eviction := &policy.Eviction{
Expand All @@ -196,3 +217,22 @@ func evictPod(ctx context.Context, client clientset.Interface, pod *v1.Pod, poli
}
return err
}

const IsFake = "is-fake"
const FakePod = "fake-pod"

func NewFakePod(pod1 *v1.Pod) *v1.Pod {
pod := pod1.DeepCopy()
pod.Labels = nil
pod.Spec.NodeName = ""
pod.Spec.SchedulerName = "volcano"
pod.OwnerReferences = nil
pod.ResourceVersion = ""
pod.Name = pod.Name + "-fake"
pod.Annotations[IsFake] = "true"
return pod
}

func EvictPod(ctx context.Context, client clientset.Interface, pod *v1.Pod, policyGroupVersion string) {
evictPod(ctx, client, pod, policyGroupVersion)
}

0 comments on commit 7966c11

Please sign in to comment.