Cpu% and Memory% based on requests rather than limits
parent
acd7702cdf
commit
82b5a9cee7
|
|
@ -324,8 +324,6 @@ func (r *Pod) gatherPodMX(po *v1.Pod) (c, p metric) {
|
||||||
func containerResources(co v1.Container) (cpu, mem *resource.Quantity) {
|
func containerResources(co v1.Container) (cpu, mem *resource.Quantity) {
|
||||||
req, limit := co.Resources.Requests, co.Resources.Limits
|
req, limit := co.Resources.Requests, co.Resources.Limits
|
||||||
switch {
|
switch {
|
||||||
case len(req) != 0 && len(limit) != 0:
|
|
||||||
cpu, mem = limit.Cpu(), limit.Memory()
|
|
||||||
case len(req) != 0:
|
case len(req) != 0:
|
||||||
cpu, mem = req.Cpu(), req.Memory()
|
cpu, mem = req.Cpu(), req.Memory()
|
||||||
case len(limit) != 0:
|
case len(limit) != 0:
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,28 @@ func TestPodFields(t *testing.T) {
|
||||||
assert.Equal(t, "fred", r[0])
|
assert.Equal(t, "fred", r[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPodFieldsPercentageCpuAndMemRelatedToContainerRequestSpec(t *testing.T) {
|
||||||
|
metrics := makeMxPod("fred", "250m", "256Mi")
|
||||||
|
|
||||||
|
r := NewPodWithMetrics(metrics, v1.ResourceRequirements{
|
||||||
|
Requests: makeRes("500m", "512Mi"),
|
||||||
|
}).Fields("blee")
|
||||||
|
|
||||||
|
assert.Equal(t, "150", r[6])
|
||||||
|
assert.Equal(t, "150", r[7])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPodFieldsPercentageCpuAndMemFallbackToContainerLimitSpecWhenRequestNotDefined(t *testing.T) {
|
||||||
|
metrics := makeMxPod("fred", "250m", "256Mi")
|
||||||
|
|
||||||
|
r := NewPodWithMetrics(metrics, v1.ResourceRequirements{
|
||||||
|
Limits: makeRes("1000m", "1024Mi"),
|
||||||
|
}).Fields("blee")
|
||||||
|
|
||||||
|
assert.Equal(t, "75", r[6])
|
||||||
|
assert.Equal(t, "75", r[7])
|
||||||
|
}
|
||||||
|
|
||||||
func TestPodMarshal(t *testing.T) {
|
func TestPodMarshal(t *testing.T) {
|
||||||
mc := NewMockConnection()
|
mc := NewMockConnection()
|
||||||
mr := NewMockCruder()
|
mr := NewMockCruder()
|
||||||
|
|
@ -100,6 +122,11 @@ func BenchmarkPodFields(b *testing.B) {
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Helpers...
|
// Helpers...
|
||||||
|
func makePodWithContainerSpec(resources v1.ResourceRequirements) *v1.Pod {
|
||||||
|
pod := makePod()
|
||||||
|
pod.Spec.Containers[0].Resources = resources
|
||||||
|
return pod
|
||||||
|
}
|
||||||
|
|
||||||
func makePod() *v1.Pod {
|
func makePod() *v1.Pod {
|
||||||
var i int32 = 1
|
var i int32 = 1
|
||||||
|
|
@ -159,6 +186,13 @@ func newPod() resource.Columnar {
|
||||||
return resource.NewPod(mc).New(makePod())
|
return resource.NewPod(mc).New(makePod())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewPodWithMetrics(metrics mv1beta1.PodMetrics, resources v1.ResourceRequirements) resource.Columnar {
|
||||||
|
mc := NewMockConnection()
|
||||||
|
r := resource.NewPod(mc).New(makePodWithContainerSpec(resources))
|
||||||
|
r.SetPodMetrics(&metrics)
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
func poYaml() string {
|
func poYaml() string {
|
||||||
return `apiVersion: v1
|
return `apiVersion: v1
|
||||||
kind: Pod
|
kind: Pod
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue