[FIX] resolve pod select bug

This commit is contained in:
goodrain 2018-02-09 12:10:35 +08:00
parent 20eaa170c4
commit 464d6847eb
3 changed files with 42 additions and 14 deletions

View File

@ -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)

View File

@ -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 <http://www.gnu.org/licenses/>.
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)
}

View File

@ -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("初始化失<E58C96><E5A4B1>,%s", val.Message)
status.StatusCN = fmt.Sprintf("初始化失<E58C96><E5A4B1><EFBFBD><EFBFBD><EFBFBD>,%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()