diff --git a/pkg/node/api/controller/node_controller.go b/pkg/node/api/controller/node_controller.go index 3b49f6302..ed00ab801 100644 --- a/pkg/node/api/controller/node_controller.go +++ b/pkg/node/api/controller/node_controller.go @@ -344,18 +344,14 @@ func Instances(w http.ResponseWriter, r *http.Request) { capCPU := node.NodeStatus.Capacity.Cpu().Value() capMEM := node.NodeStatus.Capacity.Memory().Value() for _, v := range ps { - logrus.Infof("pos 's node name is %s and node is %s", v.Spec.NodeName, node.HostName) - if v.Spec.NodeName != node.InternalIP { - continue - } pod := &model.Pods{} pod.Namespace = v.Namespace - serviceId := v.Labels["name"] - if serviceId == "" { + serviceID := v.Labels["name"] + if serviceID == "" { continue } pod.Name = v.Name - pod.Id = serviceId + pod.Id = serviceID lc := v.Spec.Containers[0].Resources.Limits.Cpu().MilliValue() cpuL += lc @@ -368,9 +364,6 @@ func Instances(w http.ResponseWriter, r *http.Request) { rm := v.Spec.Containers[0].Resources.Requests.Memory().Value() memR += rm - - logrus.Infof("namespace %s,podid %s :limit cpu %v,requests cpu %v,limit mem %v,request mem %v,cap cpu is %v,cap mem is %v", pod.Namespace, pod.Name, lc, rc, lm, rm, capCPU, capMEM) - pod.CPURequests = strconv.FormatFloat(float64(rc)/float64(1000), 'f', 2, 64) pod.CPURequestsR = strconv.FormatFloat(float64(rc/10)/float64(capCPU), 'f', 1, 64) diff --git a/pkg/node/core/k8s/k8s_test.go b/pkg/node/core/k8s/k8s_test.go new file mode 100644 index 000000000..de9fa09a3 --- /dev/null +++ b/pkg/node/core/k8s/k8s_test.go @@ -0,0 +1,38 @@ +// RAINBOND, Application Management Platform +// Copyright (C) 2014-2017 Goodrain Co., Ltd. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. For any non-GPL usage of Rainbond, +// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd. +// must be obtained first. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package k8s + +import ( + "testing" + + "github.com/goodrain/rainbond/cmd/node/option" +) + +func init() { + NewK8sClient(&option.Conf{ + K8SConfPath: "/Users/qingguo/gopath/src/github.com/goodrain/rainbond/test/admin.kubeconfig", + }) +} +func TestGetPodsByNodeName(t *testing.T) { + pods, err := GetPodsByNodeName("ae1c9751-a631-4b72-9310-da752b8e6dee") + if err != nil { + t.Fatal(err) + } + t.Log(pods) +} diff --git a/pkg/node/core/service/node_service.go b/pkg/node/core/service/node_service.go index 300ed324a..a1ce52ec9 100644 --- a/pkg/node/core/service/node_service.go +++ b/pkg/node/core/service/node_service.go @@ -272,7 +272,7 @@ func (n *NodeService) InitStatus(nodeIP string) (*model.InitStatus, *utils.APIHa status.HostID = node.ID } else if val.Type == model.NodeInit && val.Status == model.ConditionFalse { status.Status = 1 - status.StatusCN = fmt.Sprintf("初始化失��,%s", val.Message) + status.StatusCN = fmt.Sprintf("初始化失�����,%s", val.Message) } else { status.Status = 2 status.StatusCN = "初始化中" @@ -305,9 +305,6 @@ func (n *NodeService) GetNodeResource(nodeUID string) (*model.NodePodResource, * var memLimit int64 var memRequest int64 for _, v := range ps { - if v.Spec.NodeName != node.InternalIP { - continue - } lc := v.Spec.Containers[0].Resources.Limits.Cpu().MilliValue() cpuLimit += lc lm := v.Spec.Containers[0].Resources.Limits.Memory().Value()