diff --git a/sources/kube_nodes.go b/sources/kube_nodes.go index 1a9100fef3..f967b5d1e4 100644 --- a/sources/kube_nodes.go +++ b/sources/kube_nodes.go @@ -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 } diff --git a/sources/nodes/coreos_test.go b/sources/nodes/coreos_test.go index 013bd89bf8..6ca5d51f1d 100644 --- a/sources/nodes/coreos_test.go +++ b/sources/nodes/coreos_test.go @@ -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) { diff --git a/sources/nodes/kube.go b/sources/nodes/kube.go index 7ba85647f9..f76f2e9390 100644 --- a/sources/nodes/kube.go +++ b/sources/nodes/kube.go @@ -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 } diff --git a/sources/nodes/types.go b/sources/nodes/types.go index 49909f96e1..e1d5b954ed 100644 --- a/sources/nodes/types.go +++ b/sources/nodes/types.go @@ -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