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 3a9fa1cc [horus] Add a module to prohibit node scheduling (#335)
3a9fa1cc is described below
commit 3a9fa1cc8c55a63ed66f08c78cf094c3ee1d3e55
Author: mfordjody <[email protected]>
AuthorDate: Thu Sep 12 09:32:21 2024 +0800
[horus] Add a module to prohibit node scheduling (#335)
fix typo
fix typo
fix typo
---
app/horus/core/horuser/action.go | 58 +++++++++++++++++++++++++++++++++++++++
app/horus/core/horuser/horuser.go | 2 +-
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/app/horus/core/horuser/action.go b/app/horus/core/horuser/action.go
new file mode 100644
index 00000000..c02876ac
--- /dev/null
+++ b/app/horus/core/horuser/action.go
@@ -0,0 +1,58 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package horuser
+
+import (
+ v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+)
+
+func (h *Horuser) Cordon(nodeName, clusterName, modelName string) (err error) {
+ kubeClient := h.kubeClientMap[clusterName]
+ if kubeClient == nil {
+ klog.Errorf("node Cordon kubeClient by clusterName empty.")
+ klog.Infof("nodeName:%v,clusterName:%v,modelName:%v", nodeName,
clusterName, modelName)
+ return err
+ }
+
+ ctxFirst, cancelFirst := h.GetK8sContext()
+ defer cancelFirst()
+ node, err := kubeClient.CoreV1().Nodes().Get(ctxFirst, nodeName,
v1.GetOptions{})
+ if err != nil {
+ klog.Errorf("node Cordon get err nodeName:%v clusterName:%v
modelName:%v", nodeName, clusterName, modelName)
+ return err
+ }
+
+ node.Spec.Unschedulable = true
+
+ ctxSecond, cancelSecond := h.GetK8sContext()
+ defer cancelSecond()
+ node, err = kubeClient.CoreV1().Nodes().Update(ctxSecond, node,
v1.UpdateOptions{})
+ if err != nil {
+ klog.Errorf("node Cordon update err nodeName:%v clusterName:%v
modelName:%v", nodeName, clusterName, modelName)
+ return err
+ }
+ klog.Infof("node Cordon success nodeName:%v clusterName:%v
modelName:%v", nodeName, clusterName, modelName)
+ return nil
+}
+
+func (h *Horuser) Drain() error {
+ return nil
+}
+
+func (h *Horuser) Evict() error {
+ return nil
+}
diff --git a/app/horus/core/horuser/horuser.go
b/app/horus/core/horuser/horuser.go
index a5afff12..38fcdcb9 100644
--- a/app/horus/core/horuser/horuser.go
+++ b/app/horus/core/horuser/horuser.go
@@ -18,7 +18,7 @@ package horuser
import (
"context"
"github.com/apache/dubbo-kubernetes/app/horus/basic/config"
- "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
+ clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"