This is an automated email from the ASF dual-hosted git repository.

zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git


The following commit(s) were added to refs/heads/master by this push:
     new e8cb7025 [horus] Add the feature of evict pods (#338)
e8cb7025 is described below

commit e8cb70259ccf7e9a7ca13e536f6aeb980ca2bfc0
Author: mfordjody <[email protected]>
AuthorDate: Fri Sep 13 09:29:22 2024 +0800

    [horus] Add the feature of evict pods (#338)
---
 app/horus/core/horuser/action.go | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/app/horus/core/horuser/action.go b/app/horus/core/horuser/action.go
index 4dc040df..1bd252b8 100644
--- a/app/horus/core/horuser/action.go
+++ b/app/horus/core/horuser/action.go
@@ -53,6 +53,28 @@ func (h *Horuser) Drain() error {
        return nil
 }
 
-func (h *Horuser) Evict() error {
+func (h *Horuser) Evict(podName, podNamespace, clusterName string) (err error) 
{
+       kubeClient := h.kubeClientMap[clusterName]
+       if kubeClient == nil {
+               klog.Errorf("pod Evict kubeClient by clusterName empty.")
+               klog.Infof("podName:%v clusterName:%v", podName, clusterName)
+               return err
+       }
+
+       ctxFirst, cancelFirst := h.GetK8sContext()
+       defer cancelFirst()
+       _, err = kubeClient.CoreV1().Pods(podNamespace).Get(ctxFirst, podName, 
v1.GetOptions{})
+       if err != nil {
+               klog.Errorf("pod Evict get err clusterName:%v podName:%v", 
clusterName, podName)
+               return err
+       }
+
+       ctxSecond, cancelSecond := h.GetK8sContext()
+       defer cancelSecond()
+       err = kubeClient.CoreV1().Pods(podNamespace).Delete(ctxSecond, podName, 
v1.DeleteOptions{})
+       if err != nil {
+               klog.Errorf("pod Evict delete err clusterName:%v podName:%v", 
clusterName, podName)
+               return err
+       }
        return nil
 }

Reply via email to