Skip to content

Commit

Permalink
Merge pull request #7669 from jbartosik/rm-dead-code
Browse files Browse the repository at this point in the history
Remove an unused function and fix a comment
  • Loading branch information
k8s-ci-robot authored Jan 7, 2025
2 parents 998e45a + 87b234f commit a587c55
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 67 deletions.
8 changes: 1 addition & 7 deletions vertical-pod-autoscaler/pkg/recommender/model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ func ResourceNamesApiToModel(resources []apiv1.ResourceName) *[]ResourceName {
return &result
}

// RoundResourceAmount returns the given resource amount rounded down to the
// whole multiple of another resource amount (unit).
func RoundResourceAmount(amount, unit ResourceAmount) ResourceAmount {
return ResourceAmount(int64(amount) - int64(amount)%int64(unit))
}

// ResourceAmountMax returns the larger of two resource amounts.
func ResourceAmountMax(amount1, amount2 ResourceAmount) ResourceAmount {
if amount1 > amount2 {
Expand All @@ -149,7 +143,7 @@ func resourceAmountFromFloat(amount float64) ResourceAmount {
}
}

// HumanizeMemoryQuantity converts raw bytes to human-readable string using binary units (KiB, MiB, GiB, TiB) with no decimal places.
// HumanizeMemoryQuantity converts raw bytes to human-readable string using binary units (KiB, MiB, GiB, TiB) with two decimal places.
func HumanizeMemoryQuantity(bytes int64) string {
const (
KiB = 1024
Expand Down
60 changes: 0 additions & 60 deletions vertical-pod-autoscaler/pkg/recommender/model/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,66 +609,6 @@ func TestResourceNamesApiToModel(t *testing.T) {
}
}

type RoundResourceAmountsTestCase struct {
name string
resources Resources
want Resources
}

func TestRoundResourceAmounts(t *testing.T) {
tc := []RoundResourceAmountsTestCase{
{
name: "should round down CPU and memory",
resources: Resources{
ResourceCPU: ResourceAmount(4500), // 4.5 CPU cores
ResourceMemory: ResourceAmount(7168), // 7168MB memory
},
want: Resources{
ResourceCPU: ResourceAmount(4000), // Round down to 4.0 CPU cores
ResourceMemory: ResourceAmount(7000), // Round down to 7000MB
},
},
{
name: "exact multiples should remain unchanged",
resources: Resources{
ResourceCPU: ResourceAmount(2000), // 2.0 CPU cores
ResourceMemory: ResourceAmount(4000), // 4000MB memory
},
want: Resources{
ResourceCPU: ResourceAmount(2000), // Should remain 2.0
ResourceMemory: ResourceAmount(4000), // Should remain 4000
},
},
{
name: "small values should round to zero",
resources: Resources{
ResourceCPU: ResourceAmount(499), // 0.499 CPU cores
ResourceMemory: ResourceAmount(999), // 999MB memory
},
want: Resources{
ResourceCPU: ResourceAmount(0), // Round down to 0
ResourceMemory: ResourceAmount(0), // Round down to 0
},
},
{
name: "empty resources should remain empty",
resources: Resources{},
want: Resources{},
},
}

for _, tc := range tc {
t.Run(tc.name, func(t *testing.T) {
result := tc.resources
for resource, amount := range result {
// Assuming unit of 1000 for both CPU and Memory
result[resource] = RoundResourceAmount(amount, 1000)
}
assert.Equal(t, tc.want, result)
})
}
}

type ResourceAmountFromFloatTestCase struct {
name string
amount float64
Expand Down

0 comments on commit a587c55

Please sign in to comment.