Skip to content

Commit

Permalink
update scheduler fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kelseyhightower committed Apr 11, 2018
1 parent f5b0348 commit a8b8969
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
3 changes: 1 addition & 2 deletions deployments/nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 16 additions & 5 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a8b8969

Please sign in to comment.