Skip to content

Commit cd96164

Browse files
Rename addEffectiveAllocationCapacity -> addEffectiveCapacity
1 parent 6586e8f commit cd96164

2 files changed

Lines changed: 27 additions & 27 deletions

File tree

internal/libvirt/libvirt.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (l *LibVirt) Process(hv v1.Hypervisor) (v1.Hypervisor, error) {
274274
l.addCapabilities,
275275
l.addDomainCapabilities,
276276
l.addAllocationCapacity,
277-
l.addEffectiveAllocationCapacity,
277+
l.addEffectiveCapacity,
278278
}
279279
var err error
280280
for _, processor := range processors {
@@ -555,12 +555,12 @@ func (l *LibVirt) addAllocationCapacity(old v1.Hypervisor) (v1.Hypervisor, error
555555
return newHv, nil
556556
}
557557

558-
// Add the effective allocation capacity to the hypervisor instance.
558+
// Add the effective capacity to the hypervisor instance.
559559
//
560-
// The effective allocation capacity is calculated as the physical capacity and
561-
// allocation times the applied overcommit ratio, or 1.0 by default. In case
562-
// the resulting values are fractional, they are floored.
563-
func (l *LibVirt) addEffectiveAllocationCapacity(old v1.Hypervisor) (v1.Hypervisor, error) {
560+
// The effective capacity is calculated as the physical capacity times the
561+
// applied overcommit ratio, or 1.0 by default. In case the resulting values
562+
// are fractional, they are floored.
563+
func (l *LibVirt) addEffectiveCapacity(old v1.Hypervisor) (v1.Hypervisor, error) {
564564
newHv := *old.DeepCopy()
565565
// Always recreate the EffectiveCapacity map to remove stale entries
566566
newHv.Status.EffectiveCapacity = make(map[v1.ResourceName]resource.Quantity)

internal/libvirt/libvirt_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ func TestRunEventLoop_ClosedEventChannel(t *testing.T) {
15531553
}
15541554
}
15551555

1556-
func TestAddEffectiveAllocationCapacity_NoOvercommit(t *testing.T) {
1556+
func TestAddEffectiveCapacity_NoOvercommit(t *testing.T) {
15571557
// Test that when no overcommit is specified, effective capacity equals capacity
15581558
l := &LibVirt{}
15591559

@@ -1577,10 +1577,10 @@ func TestAddEffectiveAllocationCapacity_NoOvercommit(t *testing.T) {
15771577
},
15781578
}
15791579

1580-
result, err := l.addEffectiveAllocationCapacity(hv)
1580+
result, err := l.addEffectiveCapacity(hv)
15811581

15821582
if err != nil {
1583-
t.Fatalf("addEffectiveAllocationCapacity() returned unexpected error: %v", err)
1583+
t.Fatalf("addEffectiveCapacity() returned unexpected error: %v", err)
15841584
}
15851585

15861586
// With no overcommit, effective capacity should equal physical capacity
@@ -1614,7 +1614,7 @@ func TestAddEffectiveAllocationCapacity_NoOvercommit(t *testing.T) {
16141614
}
16151615
}
16161616

1617-
func TestAddEffectiveAllocationCapacity_WithMemoryOvercommit(t *testing.T) {
1617+
func TestAddEffectiveCapacity_WithMemoryOvercommit(t *testing.T) {
16181618
// Test memory overcommit ratio of 1.5
16191619
l := &LibVirt{}
16201620

@@ -1634,10 +1634,10 @@ func TestAddEffectiveAllocationCapacity_WithMemoryOvercommit(t *testing.T) {
16341634
},
16351635
}
16361636

1637-
result, err := l.addEffectiveAllocationCapacity(hv)
1637+
result, err := l.addEffectiveCapacity(hv)
16381638

16391639
if err != nil {
1640-
t.Fatalf("addEffectiveAllocationCapacity() returned unexpected error: %v", err)
1640+
t.Fatalf("addEffectiveCapacity() returned unexpected error: %v", err)
16411641
}
16421642

16431643
// Memory should be 64 GiB * 1.5 = 96 GiB
@@ -1657,7 +1657,7 @@ func TestAddEffectiveAllocationCapacity_WithMemoryOvercommit(t *testing.T) {
16571657
}
16581658
}
16591659

1660-
func TestAddEffectiveAllocationCapacity_WithCPUOvercommit(t *testing.T) {
1660+
func TestAddEffectiveCapacity_WithCPUOvercommit(t *testing.T) {
16611661
// Test CPU overcommit ratio of 4.0
16621662
l := &LibVirt{}
16631663

@@ -1677,10 +1677,10 @@ func TestAddEffectiveAllocationCapacity_WithCPUOvercommit(t *testing.T) {
16771677
},
16781678
}
16791679

1680-
result, err := l.addEffectiveAllocationCapacity(hv)
1680+
result, err := l.addEffectiveCapacity(hv)
16811681

16821682
if err != nil {
1683-
t.Fatalf("addEffectiveAllocationCapacity() returned unexpected error: %v", err)
1683+
t.Fatalf("addEffectiveCapacity() returned unexpected error: %v", err)
16841684
}
16851685

16861686
// Memory should remain unchanged (no overcommit specified, defaults to 1.0)
@@ -1700,7 +1700,7 @@ func TestAddEffectiveAllocationCapacity_WithCPUOvercommit(t *testing.T) {
17001700
}
17011701
}
17021702

1703-
func TestAddEffectiveAllocationCapacity_WithBothOvercommit(t *testing.T) {
1703+
func TestAddEffectiveCapacity_WithBothOvercommit(t *testing.T) {
17041704
// Test both memory and CPU overcommit
17051705
l := &LibVirt{}
17061706

@@ -1721,10 +1721,10 @@ func TestAddEffectiveAllocationCapacity_WithBothOvercommit(t *testing.T) {
17211721
},
17221722
}
17231723

1724-
result, err := l.addEffectiveAllocationCapacity(hv)
1724+
result, err := l.addEffectiveCapacity(hv)
17251725

17261726
if err != nil {
1727-
t.Fatalf("addEffectiveAllocationCapacity() returned unexpected error: %v", err)
1727+
t.Fatalf("addEffectiveCapacity() returned unexpected error: %v", err)
17281728
}
17291729

17301730
// Memory should be 32 GiB * 2.0 = 64 GiB
@@ -1744,7 +1744,7 @@ func TestAddEffectiveAllocationCapacity_WithBothOvercommit(t *testing.T) {
17441744
}
17451745
}
17461746

1747-
func TestAddEffectiveAllocationCapacity_FractionalValuesFloored(t *testing.T) {
1747+
func TestAddEffectiveCapacity_FractionalValuesFloored(t *testing.T) {
17481748
// Test that fractional values are floored (not rounded)
17491749
// 11 * 1.5 = 16.5, which should be floored to 16
17501750
l := &LibVirt{}
@@ -1764,10 +1764,10 @@ func TestAddEffectiveAllocationCapacity_FractionalValuesFloored(t *testing.T) {
17641764
},
17651765
}
17661766

1767-
result, err := l.addEffectiveAllocationCapacity(hv)
1767+
result, err := l.addEffectiveCapacity(hv)
17681768

17691769
if err != nil {
1770-
t.Fatalf("addEffectiveAllocationCapacity() returned unexpected error: %v", err)
1770+
t.Fatalf("addEffectiveCapacity() returned unexpected error: %v", err)
17711771
}
17721772

17731773
// CPU should be floor(11 * 1.5) = floor(16.5) = 16
@@ -1779,7 +1779,7 @@ func TestAddEffectiveAllocationCapacity_FractionalValuesFloored(t *testing.T) {
17791779
}
17801780
}
17811781

1782-
func TestAddEffectiveAllocationCapacity_FractionalValuesFlooredDown(t *testing.T) {
1782+
func TestAddEffectiveCapacity_FractionalValuesFlooredDown(t *testing.T) {
17831783
// Test that fractional values are floored down, not rounded up
17841784
// 3 * 1.9 = 5.7, which should be floored to 5 (not rounded to 6)
17851785
l := &LibVirt{}
@@ -1799,10 +1799,10 @@ func TestAddEffectiveAllocationCapacity_FractionalValuesFlooredDown(t *testing.T
17991799
},
18001800
}
18011801

1802-
result, err := l.addEffectiveAllocationCapacity(hv)
1802+
result, err := l.addEffectiveCapacity(hv)
18031803

18041804
if err != nil {
1805-
t.Fatalf("addEffectiveAllocationCapacity() returned unexpected error: %v", err)
1805+
t.Fatalf("addEffectiveCapacity() returned unexpected error: %v", err)
18061806
}
18071807

18081808
// CPU should be floor(3 * 1.9) = floor(5.7) = 5
@@ -1814,7 +1814,7 @@ func TestAddEffectiveAllocationCapacity_FractionalValuesFlooredDown(t *testing.T
18141814
}
18151815
}
18161816

1817-
func TestAddEffectiveAllocationCapacity_MultipleCells(t *testing.T) {
1817+
func TestAddEffectiveCapacity_MultipleCells(t *testing.T) {
18181818
// Test that overcommit is applied to each cell individually
18191819
l := &LibVirt{}
18201820

@@ -1852,10 +1852,10 @@ func TestAddEffectiveAllocationCapacity_MultipleCells(t *testing.T) {
18521852
},
18531853
}
18541854

1855-
result, err := l.addEffectiveAllocationCapacity(hv)
1855+
result, err := l.addEffectiveCapacity(hv)
18561856

18571857
if err != nil {
1858-
t.Fatalf("addEffectiveAllocationCapacity() returned unexpected error: %v", err)
1858+
t.Fatalf("addEffectiveCapacity() returned unexpected error: %v", err)
18591859
}
18601860

18611861
// Check total effective capacity

0 commit comments

Comments
 (0)