generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor how opaque device configs are handled
Previously, each config was being applied independently to each request that referenced it. However, some configs may need to operate collectively on all of the requests they are associated with it. The code has been refactored to handle this situation. Additionally, the code to define the ContainerEdits for any custom config has been moved into the config code itself to better encapsulate it. Signed-off-by: Kevin Klues <[email protected]>
- Loading branch information
Showing
5 changed files
with
204 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2024 The Kubernetes 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 v1alpha1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
resourceapi "k8s.io/api/resource/v1alpha3" | ||
|
||
cdiapi "tags.cncf.io/container-device-interface/pkg/cdi" | ||
cdispec "tags.cncf.io/container-device-interface/specs-go" | ||
) | ||
|
||
// +k8s:deepcopy-gen=false | ||
type PerDeviceCDIContainerEdits map[string]*cdiapi.ContainerEdits | ||
|
||
func (c *GpuConfig) Apply(results []*resourceapi.DeviceRequestAllocationResult) (PerDeviceCDIContainerEdits, error) { | ||
perDeviceEdits := make(PerDeviceCDIContainerEdits) | ||
|
||
for _, result := range results { | ||
envs := []string{} | ||
|
||
if c.Sharing != nil { | ||
envs = append(envs, fmt.Sprintf("GPU_DEVICE_%s_SHARING_STRATEGY=%s", result.Device[4:], c.Sharing.Strategy)) | ||
} | ||
|
||
switch { | ||
case c.Sharing.IsTimeSlicing(): | ||
tsconfig, err := c.Sharing.GetTimeSlicingConfig() | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to get time slicing config for device %v: %w", result.Device, err) | ||
} | ||
envs = append(envs, fmt.Sprintf("GPU_DEVICE_%s_TIMESLICE_INTERVAL=%v", result.Device[4:], tsconfig.Interval)) | ||
case c.Sharing.IsSpacePartitioning(): | ||
spconfig, err := c.Sharing.GetSpacePartitioningConfig() | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to get space partitioning config for device %v: %w", result.Device, err) | ||
} | ||
envs = append(envs, fmt.Sprintf("GPU_DEVICE_%s_PARTITION_COUNT=%v", result.Device[4:], spconfig.PartitionCount)) | ||
} | ||
|
||
edits := &cdispec.ContainerEdits{ | ||
Env: envs, | ||
} | ||
|
||
perDeviceEdits[result.Device] = &cdiapi.ContainerEdits{ContainerEdits: edits} | ||
} | ||
|
||
return perDeviceEdits, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.