Skip to content

Commit

Permalink
Merge pull request #221 from openshift-kni/knidebug-eph-stor-4.14
Browse files Browse the repository at this point in the history
[KNI][release-4.14] log ephemeral-storage resources
  • Loading branch information
ffromani authored Jun 25, 2024
2 parents 986716a + 4826300 commit 457b063
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
41 changes: 26 additions & 15 deletions pkg-kni/knidebug/knidebug.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ func frameworkResourceToLoggable(logKey string, req *framework.Resource) []inter
"memory", humanMemory(req.Memory),
}

if req.EphemeralStorage > 0 {
items = append(items,
"ephemeral-storage", humanMemory(req.EphemeralStorage),
)
}

if len(req.ScalarResources) == 0 {
return items
}

resNames := []string{}
for resName := range req.ScalarResources {
resNames = append(resNames, string(resName))
Expand Down Expand Up @@ -123,25 +133,26 @@ func (hc humanCPU) String() string {
// the max in each dimension iteratively. In contrast, we sum the resource vectors for
// regular containers since they run simultaneously.
//
// The resources defined for Overhead should be added to the calculated Resource request sum
// # The resources defined for Overhead should be added to the calculated Resource request sum
//
// Example:
//
// Pod:
// InitContainers
// IC1:
// CPU: 2
// Memory: 1G
// IC2:
// CPU: 2
// Memory: 3G
// Containers
// C1:
// CPU: 2
// Memory: 1G
// C2:
// CPU: 1
// Memory: 1G
//
// InitContainers
// IC1:
// CPU: 2
// Memory: 1G
// IC2:
// CPU: 2
// Memory: 3G
// Containers
// C1:
// CPU: 2
// Memory: 1G
// C2:
// CPU: 1
// Memory: 1G
//
// Result: CPU: 3, Memory: 3G
func computePodResourceRequest(pod *corev1.Pod) *framework.Resource {
Expand Down
29 changes: 29 additions & 0 deletions pkg-kni/knidebug/knidebug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ func TestFrameworkResourceToLoggable(t *testing.T) {
},
expected: ` logKey="TEST4" cpu="24000 (24)" memory="17179869184 (16 GiB)" hugepages-2Mi="1073741824 (1.0 GiB)"`,
},
{
name: "CPUs, Memory, hugepages-2Mi, ephemeral-storage",
logKey: "TEST4",
resources: &framework.Resource{
MilliCPU: 24000,
Memory: 16 * 1024 * 1024 * 1024,
EphemeralStorage: 128 * 1024 * 1024 * 1024,
ScalarResources: map[corev1.ResourceName]int64{
corev1.ResourceName("hugepages-2Mi"): 1 * 1024 * 1024 * 1024,
},
},
expected: ` logKey="TEST4" cpu="24000 (24)" memory="17179869184 (16 GiB)" ephemeral-storage="137438953472 (128 GiB)" hugepages-2Mi="1073741824 (1.0 GiB)"`,
},

{
name: "CPUs, Memory, hugepages-2Mi, hugepages-1Gi",
logKey: "TEST4",
Expand Down Expand Up @@ -120,6 +134,21 @@ func TestFrameworkResourceToLoggable(t *testing.T) {
},
expected: ` logKey="TEST4" cpu="24000 (24)" memory="17179869184 (16 GiB)" awesome.net/gpu="4" example.com/netdevice="16" hugepages-2Mi="1073741824 (1.0 GiB)"`,
},
{
name: "CPUs, Memory, hugepages-2Mi, devices, ephemeral-storage",
logKey: "TEST4",
resources: &framework.Resource{
MilliCPU: 24000,
Memory: 16 * 1024 * 1024 * 1024,
EphemeralStorage: 128 * 1024 * 1024 * 1024,
ScalarResources: map[corev1.ResourceName]int64{
corev1.ResourceName("hugepages-2Mi"): 1 * 1024 * 1024 * 1024,
corev1.ResourceName("example.com/netdevice"): 16,
corev1.ResourceName("awesome.net/gpu"): 4,
},
},
expected: ` logKey="TEST4" cpu="24000 (24)" memory="17179869184 (16 GiB)" ephemeral-storage="137438953472 (128 GiB)" awesome.net/gpu="4" example.com/netdevice="16" hugepages-2Mi="1073741824 (1.0 GiB)"`,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 457b063

Please sign in to comment.