From a8b8969475cbddcfd9ccd47289498b46fee09443 Mon Sep 17 00:00:00 2001 From: Kelsey Hightower Date: Wed, 11 Apr 2018 13:11:59 +0000 Subject: [PATCH] update scheduler fields --- deployments/nginx.yaml | 3 +-- kubernetes.go | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/deployments/nginx.yaml b/deployments/nginx.yaml index bcf1611..c9d33fd 100644 --- a/deployments/nginx.yaml +++ b/deployments/nginx.yaml @@ -8,12 +8,11 @@ spec: replicas: 1 template: metadata: - annotations: - "scheduler.alpha.kubernetes.io/name": hightower labels: app: nginx name: nginx spec: + schedulerName: hightower containers: - name: nginx image: "nginx:1.11.1-alpine" diff --git a/kubernetes.go b/kubernetes.go index dba5a1b..fc1c675 100644 --- a/kubernetes.go +++ b/kubernetes.go @@ -267,13 +267,24 @@ func fit(pod *Pod) ([]Node, error) { } for _, node := range nodeList.Items { - cpu := node.Status.Allocatable["cpu"] - cpuFloat, err := strconv.ParseFloat(cpu, 32) - if err != nil { - return nil, err + var allocatableCores int + var err error + if strings.HasSuffix(node.Status.Allocatable["cpu"], "m") { + milliCores := strings.TrimSuffix(node.Status.Allocatable["cpu"], "m") + allocatableCores, err = strconv.Atoi(milliCores) + if err != nil { + return nil, err + } + } else { + cpu := node.Status.Allocatable["cpu"] + cpuFloat, err := strconv.ParseFloat(cpu, 32) + if err != nil { + return nil, err + } + allocatableCores = int(cpuFloat * 1000) } - freeSpace := (int(cpuFloat*1000) - resourceUsage[node.Metadata.Name].CPU) + freeSpace := (allocatableCores - resourceUsage[node.Metadata.Name].CPU) if freeSpace < spaceRequired { m := fmt.Sprintf("fit failure on node (%s): Insufficient CPU", node.Metadata.Name) fitFailures = append(fitFailures, m)