Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the use of CDI on OpenShift #733

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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
42 changes: 29 additions & 13 deletions controllers/object_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@
MPSRootEnvName = "MPS_ROOT"
// DefaultMPSRoot is the default MPS root path on the host
DefaultMPSRoot = "/run/nvidia/mps"
// NvidiaRuntimeSetAsDefaultEnvName is the name of the toolkit container env for configuring NVIDIA Container Runtime as the default runtime
NvidiaRuntimeSetAsDefaultEnvName = "NVIDIA_RUNTIME_SET_AS_DEFAULT"
)

// ContainerProbe defines container probe types
Expand Down Expand Up @@ -824,7 +826,7 @@
}

// set RuntimeClass for supported runtimes
setRuntimeClass(&obj.Spec.Template.Spec, n.runtime, config.Operator.RuntimeClass)
setRuntimeClass(&obj.Spec.Template.Spec, n, config.Operator.RuntimeClass)

// update env required for MIG support
applyMIGConfiguration(&(obj.Spec.Template.Spec.Containers[0]), config.MIG.Strategy)
Expand Down Expand Up @@ -1125,6 +1127,10 @@
if config.CDI.IsDefault() {
setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), NvidiaCtrRuntimeModeEnvName, "cdi")
}
// do not set 'nvidia' as the default runtime on OpenShift
if n.openshift != "" {
setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), NvidiaRuntimeSetAsDefaultEnvName, "false")
}
}

// set install directory for the toolkit
Expand Down Expand Up @@ -1270,7 +1276,7 @@
}

// set RuntimeClass for supported runtimes
setRuntimeClass(&obj.Spec.Template.Spec, n.runtime, config.Operator.RuntimeClass)
setRuntimeClass(&obj.Spec.Template.Spec, n, config.Operator.RuntimeClass)

// update env required for MIG support
applyMIGConfiguration(&(obj.Spec.Template.Spec.Containers[0]), config.MIG.Strategy)
Expand All @@ -1279,7 +1285,12 @@
if config.CDI.IsEnabled() {
setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), CDIEnabledEnvName, "true")
setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), DeviceListStrategyEnvName, "envvar,cdi-annotations")
setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), CDIAnnotationPrefixEnvName, "nvidia.cdi.k8s.io/")
// for OpenShift, use native-CDI support in CRI-O as the 'nvidia' runtime will not be configured as the default runtime
cdiAnnotationPrefix := "nvidia.cdi.k8s.io/"
if n.openshift != "" {
cdiAnnotationPrefix = "cdi.k8s.io/"
}
setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), CDIAnnotationPrefixEnvName, cdiAnnotationPrefix)
if config.Toolkit.IsEnabled() {
setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), NvidiaCTKPathEnvName, filepath.Join(config.Toolkit.InstallDir, "toolkit/nvidia-ctk"))
}
Expand Down Expand Up @@ -1358,7 +1369,7 @@
}

// set RuntimeClass for supported runtimes
setRuntimeClass(&obj.Spec.Template.Spec, n.runtime, config.Operator.RuntimeClass)

Check failure on line 1372 in controllers/object_controls.go

View workflow job for this annotation

GitHub Actions / validate-csv

cannot use n.runtime (variable of type "github.com/NVIDIA/gpu-operator/api/nvidia/v1".Runtime) as ClusterPolicyController value in argument to setRuntimeClass

Check failure on line 1372 in controllers/object_controls.go

View workflow job for this annotation

GitHub Actions / validate-helm-values

cannot use n.runtime (variable of type "github.com/NVIDIA/gpu-operator/api/nvidia/v1".Runtime) as ClusterPolicyController value in argument to setRuntimeClass

// update env required for MIG support
applyMIGConfiguration(mainContainer, config.MIG.Strategy)
Expand Down Expand Up @@ -1472,7 +1483,7 @@
}

// set RuntimeClass for supported runtimes
setRuntimeClass(&obj.Spec.Template.Spec, n.runtime, config.Operator.RuntimeClass)
setRuntimeClass(&obj.Spec.Template.Spec, n, config.Operator.RuntimeClass)

// mount configmap for custom metrics if provided by user
if config.DCGMExporter.MetricsConfig != nil && config.DCGMExporter.MetricsConfig.Name != "" {
Expand Down Expand Up @@ -1589,7 +1600,7 @@
}

// set RuntimeClass for supported runtimes
setRuntimeClass(&obj.Spec.Template.Spec, n.runtime, config.Operator.RuntimeClass)
setRuntimeClass(&obj.Spec.Template.Spec, n, config.Operator.RuntimeClass)

return nil
}
Expand Down Expand Up @@ -1639,7 +1650,7 @@
}

// set RuntimeClass for supported runtimes
setRuntimeClass(&obj.Spec.Template.Spec, n.runtime, config.Operator.RuntimeClass)
setRuntimeClass(&obj.Spec.Template.Spec, n, config.Operator.RuntimeClass)

// set ConfigMap name for "mig-parted-config" Volume
for i, vol := range obj.Spec.Template.Spec.Volumes {
Expand Down Expand Up @@ -1948,7 +1959,7 @@
}

// set RuntimeClass for supported runtimes
setRuntimeClass(&obj.Spec.Template.Spec, n.runtime, config.Operator.RuntimeClass)
setRuntimeClass(&obj.Spec.Template.Spec, n, config.Operator.RuntimeClass)

var validatorErr error
// apply changes for individual component validators(initContainers)
Expand Down Expand Up @@ -2280,13 +2291,18 @@
return DefaultRuntimeClass
}

func setRuntimeClass(podSpec *corev1.PodSpec, runtime gpuv1.Runtime, runtimeClass string) {
if runtime == gpuv1.Containerd {
if runtimeClass == "" {
runtimeClass = DefaultRuntimeClass
}
podSpec.RuntimeClassName = &runtimeClass
// setRuntimeClass sets the runtimeClass for a pod, unless CRI-O is the container runtime
// being used and CDI is not enabled. In this case, an OCI hook is used and the nvidia
// runtime is not configured.
func setRuntimeClass(podSpec *corev1.PodSpec, n ClusterPolicyController, runtimeClass string) {
if n.runtime == gpuv1.CRIO && !n.singleton.Spec.CDI.IsEnabled() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this enable for docker too?

return
}

if runtimeClass == "" {
runtimeClass = DefaultRuntimeClass
}
podSpec.RuntimeClassName = &runtimeClass
}

func setContainerProbe(container *corev1.Container, probe *gpuv1.ContainerProbeSpec, probeType ContainerProbe) {
Expand Down
Loading