rebase: update replaced k8s.io modules to v0.33.0

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos
2025-05-07 13:13:33 +02:00
committed by mergify[bot]
parent dd77e72800
commit 107407b44b
1723 changed files with 65035 additions and 175239 deletions

View File

@ -26,6 +26,8 @@ package resourceclaim
import (
"errors"
"fmt"
"slices"
"strings"
v1 "k8s.io/api/core/v1"
resourceapi "k8s.io/api/resource/v1beta1"
@ -106,3 +108,36 @@ func CanBeReserved(claim *resourceapi.ResourceClaim) bool {
// Currently no restrictions on sharing...
return true
}
// BaseRequestRef returns the request name if the reference is to a top-level
// request and the name of the parent request if the reference is to a subrequest.
func BaseRequestRef(requestRef string) string {
segments := strings.Split(requestRef, "/")
return segments[0]
}
// ConfigForResult returns the configs that are applicable to device
// allocated for the provided result.
func ConfigForResult(deviceConfigurations []resourceapi.DeviceAllocationConfiguration, result resourceapi.DeviceRequestAllocationResult) []resourceapi.DeviceAllocationConfiguration {
var configs []resourceapi.DeviceAllocationConfiguration
for _, deviceConfiguration := range deviceConfigurations {
if deviceConfiguration.Opaque != nil &&
isMatch(deviceConfiguration.Requests, result.Request) {
configs = append(configs, deviceConfiguration)
}
}
return configs
}
func isMatch(requests []string, requestRef string) bool {
if len(requests) == 0 {
return true
}
if slices.Contains(requests, requestRef) {
return true
}
baseRequestRef := BaseRequestRef(requestRef)
return slices.Contains(requests, baseRequestRef)
}