Skip to content

Commit

Permalink
Added exporting cpu/mem limits based on Kubernetes rather than cadvisor
Browse files Browse the repository at this point in the history
  • Loading branch information
piosz committed Jul 13, 2015
1 parent 5b4ebe2 commit a5c8ca4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions sources/kube_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func (self *kubeNodeMetrics) updateStats(host nodes.Host, info nodes.Info, start
hostContainer = &hostCopy
containers = append(containers[:hostIndex], containers[hostIndex+1:]...)
}
// This is temporary workaround for #399.
hostContainer.Spec.Cpu.Limit = info.CpuCapacity
hostContainer.Spec.Memory.Limit = info.MemCapacity
return hostContainer, containers, nil
}

Expand Down
4 changes: 2 additions & 2 deletions sources/nodes/coreos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func TestSuccessCase(t *testing.T) {
nodeList, err := nodesApi.List()
require.NoError(t, err)
assert.Len(t, nodeList.Items, 2)
assert.Equal(t, nodeList.Items["a"], Info{"1.2.3.4", "1.2.3.4", ""})
assert.Equal(t, nodeList.Items["b"], Info{"1.2.3.5", "1.2.3.5", ""})
assert.Equal(t, nodeList.Items["a"], Info{"1.2.3.4", "1.2.3.4", "", 0, 0})
assert.Equal(t, nodeList.Items["b"], Info{"1.2.3.5", "1.2.3.5", "", 0, 0})
}

func TestFailureCase(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions sources/nodes/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func (self *kubeNodes) getNodeInfoAndHostname(node api.Node) (Info, string, erro
if node.Spec.ExternalID != "" {
nodeInfo.ExternalID = node.Spec.ExternalID
}
cpu := node.Status.Capacity[api.ResourceCPU]
mem := node.Status.Capacity[api.ResourceMemory]
// To be consistent with cgroups the value is normalized.
nodeInfo.CpuCapacity = uint64(cpu.MilliValue() * 1024 / 1000)
nodeInfo.MemCapacity = uint64(mem.Value())
return nodeInfo, hostname, nodeErr
}

Expand Down
4 changes: 4 additions & 0 deletions sources/nodes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type Info struct {
InternalIP string
// An optional ID assigned to nodes by either the cloud provider or user.
ExternalID string
// Cpu capacity of node as number of 1/1024 share of core.
CpuCapacity uint64
// Memory capacity of node in bytes.
MemCapacity uint64
}

// NodeList contains the nodes that an instance of heapster is required to
Expand Down

0 comments on commit a5c8ca4

Please sign in to comment.