Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c9a272f
fix/nodelock-time-parsec-panic
maishivamhoo123 Apr 18, 2026
f604948
added all the suggestions
maishivamhoo123 Apr 18, 2026
07e9868
writing cleaner code
maishivamhoo123 Apr 18, 2026
385e32c
adding the file
maishivamhoo123 Apr 30, 2026
f6cc3d6
refactor(score): replace JSON clone with DeepCopy
maishivamhoo123 May 6, 2026
99d945f
fix: add per-device memory validation for init containers
maishivamhoo123 May 15, 2026
a680055
suggested changes in score and score_test
maishivamhoo123 May 15, 2026
9519a0a
Merge remote-tracking branch 'origin/master' into fix/nodelock-time-p…
maishivamhoo123 Jun 20, 2026
1de5b18
Added and tested
maishivamhoo123 Jun 28, 2026
b5fdd29
Removed lint
maishivamhoo123 Jun 28, 2026
b28b135
Added all the changes
maishivamhoo123 Jul 1, 2026
55556da
modiefied the sequemsital logic for initcontainer and added the test
maishivamhoo123 Jul 6, 2026
3b3ca97
Merge branch 'master' into fix/nodelock-time-parsec
maishivamhoo123 Jul 6, 2026
6be1ae2
Fixed the linter issue
maishivamhoo123 Jul 6, 2026
25d3602
fixed e2e test
maishivamhoo123 Jul 6, 2026
db04eaa
Added the suggestion
maishivamhoo123 Jul 6, 2026
5c78cd7
fixed the resource quota and added a test TestFitResourceQuota_InitCo…
maishivamhoo123 Jul 8, 2026
648b4ae
removed the stripInitContainerAliasSlots
maishivamhoo123 Jul 8, 2026
11e160b
Merge branch 'master' into fix/nodelock-time-parsec
maishivamhoo123 Jul 27, 2026
c8763b2
testing merge
maishivamhoo123 Jul 27, 2026
6e3a48a
Add CollapseInitContainerUsage/AppContainersOnlyDeviceUsage and fix t…
maishivamhoo123 Jul 28, 2026
08cee54
Merge remote-tracking branch 'upstream/master' into fix/nodelock-time…
maishivamhoo123 Jul 28, 2026
d21bb56
init-container usage shrink and atomic device replace
maishivamhoo123 Jul 28, 2026
4325718
Merge remote-tracking branch 'upstream/master' into fix/nodelock-time…
maishivamhoo123 Jul 29, 2026
3ebcd35
Added the changes
maishivamhoo123 Aug 1, 2026
d76c695
Removed unused func getDeviceBaseType
maishivamhoo123 Aug 3, 2026
d5a2f70
Merge branch 'master' into fix/nodelock-time-parsec
maishivamhoo123 Aug 3, 2026
5bacf27
cleansed the allocateInitContainers and allocateAppContainers
maishivamhoo123 Aug 3, 2026
2ff3f7c
Verified and fixed the overcounting problem
maishivamhoo123 Aug 3, 2026
f716dec
cleaned the comments
maishivamhoo123 Aug 3, 2026
7cbce1e
Merge remote-tracking branch 'upstream/master' into fix/nodelock-time…
maishivamhoo123 Aug 5, 2026
df86aa7
restored the fitquota and changed the logic such that it will not cau…
maishivamhoo123 Aug 6, 2026
e104f17
Checked everything
maishivamhoo123 Aug 6, 2026
0f8f7c9
Merge remote-tracking branch 'upstream/master' into fix/nodelock-time…
maishivamhoo123 Aug 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/device/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package common

import (
"fmt"
"sort"
"strings"
)

Expand Down Expand Up @@ -45,6 +46,7 @@ func GenReason(reasons map[string]int, cards int) string {
for r, cnt := range reasons {
reason = append(reason, fmt.Sprintf("%d/%d %s", cnt, cards, r))
}
sort.Strings(reason)
return strings.Join(reason, ", ")
}

Expand Down
145 changes: 145 additions & 0 deletions pkg/device/initContainer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
Copyright 2026 The HAMi Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package device

import (
"sort"

corev1 "k8s.io/api/core/v1"
)

type deviceKey struct {
devType string
uuid string
}
type usage struct {
mem int32
cores int32
}

// CollapseInitContainerUsage returns the effective device usage for a pod.
func CollapseInitContainerUsage(pod *corev1.Pod, raw PodDevices) PodDevices {
if raw == nil {
return nil
}
numInit := len(pod.Spec.InitContainers)
initPeak := make(map[deviceKey]usage)
appSum := make(map[deviceKey]usage)

for devType, podSingle := range raw {
for cidx, ctrDevs := range podSingle {
for _, dev := range ctrDevs {
key := deviceKey{devType: devType, uuid: dev.UUID}
if cidx < numInit {
cur := initPeak[key]
if dev.Usedmem > cur.mem {
cur.mem = dev.Usedmem
}
if dev.Usedcores > cur.cores {
cur.cores = dev.Usedcores
}
initPeak[key] = cur
} else {
cur := appSum[key]
cur.mem += dev.Usedmem
cur.cores += dev.Usedcores
appSum[key] = cur
}
}
}
}

collapsed := make(PodDevices)
for devType := range raw {
uuidSet := make(map[string]struct{})
for k := range initPeak {
if k.devType == devType {
uuidSet[k.uuid] = struct{}{}
}
}
for k := range appSum {
if k.devType == devType {
uuidSet[k.uuid] = struct{}{}
}
}

collapsedSingle := make(PodSingleDevice, 1)
var containerDevs ContainerDevices

for uuid := range uuidSet {
initU := initPeak[deviceKey{devType, uuid}]
appU := appSum[deviceKey{devType, uuid}]

effMem := max(initU.mem, appU.mem)
effCores := max(initU.cores, appU.cores)

containerDevs = append(containerDevs, ContainerDevice{
UUID: uuid,
Type: devType,
Usedmem: effMem,
Usedcores: effCores,
})
}
sort.Slice(containerDevs, func(i, j int) bool {
return containerDevs[i].UUID < containerDevs[j].UUID
})
collapsedSingle[0] = containerDevs
collapsed[devType] = collapsedSingle
}
return collapsed
}

// AppContainersOnlyDeviceUsage returns the device usage considering only app containers.
// Used when init containers have finished and we want to shrink to app-only footprint.
func AppContainersOnlyDeviceUsage(pod *corev1.Pod, raw PodDevices) PodDevices {
if raw == nil {
return nil
}
numInit := len(pod.Spec.InitContainers)

collapsed := make(PodDevices)
for devType, podSingle := range raw {
sums := make(map[string]usage)
for cidx, ctrDevs := range podSingle {
if cidx < numInit {
continue // skip init containers
}
for _, dev := range ctrDevs {
s := sums[dev.UUID]
s.mem += dev.Usedmem
s.cores += dev.Usedcores
sums[dev.UUID] = s
}
}
collapsedSingle := make(PodSingleDevice, 1)
var containerDevs ContainerDevices
for uuid, s := range sums {
containerDevs = append(containerDevs, ContainerDevice{
UUID: uuid,
Type: devType,
Usedmem: s.mem,
Usedcores: s.cores,
})
}
sort.Slice(containerDevs, func(i, j int) bool {
return containerDevs[i].UUID < containerDevs[j].UUID
})
collapsedSingle[0] = containerDevs
collapsed[devType] = collapsedSingle
}
return collapsed
}
Loading
Loading