MCPcopy Create free account
hub / github.com/NVIDIA/gpu-operator / runWorkload

Method runWorkload

cmd/nvidia-validator/main.go:1288–1372  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1286}
1287
1288func (p *Plugin) runWorkload() error {
1289 ctx := p.ctx
1290 // load podSpec
1291 pod, err := loadPodSpec(pluginWorkloadPodSpecPath)
1292 if err != nil {
1293 return err
1294 }
1295
1296 pod.Namespace = namespaceFlag
1297 image := os.Getenv(validatorImageEnvName)
1298 pod.Spec.Containers[0].Image = image
1299 pod.Spec.InitContainers[0].Image = image
1300
1301 imagePullPolicy := os.Getenv(validatorImagePullPolicyEnvName)
1302 if imagePullPolicy != "" {
1303 pod.Spec.Containers[0].ImagePullPolicy = corev1.PullPolicy(imagePullPolicy)
1304 pod.Spec.InitContainers[0].ImagePullPolicy = corev1.PullPolicy(imagePullPolicy)
1305 }
1306
1307 if os.Getenv(validatorImagePullSecretsEnvName) != "" {
1308 pullSecrets := strings.Split(os.Getenv(validatorImagePullSecretsEnvName), ",")
1309 for _, secret := range pullSecrets {
1310 pod.Spec.ImagePullSecrets = append(pod.Spec.ImagePullSecrets, corev1.LocalObjectReference{Name: secret})
1311 }
1312 }
1313 if os.Getenv(validatorRuntimeClassEnvName) != "" {
1314 runtimeClass := os.Getenv(validatorRuntimeClassEnvName)
1315 pod.Spec.RuntimeClassName = &runtimeClass
1316 }
1317
1318 validatorDaemonset, err := p.kubeClient.AppsV1().DaemonSets(namespaceFlag).Get(ctx, "nvidia-operator-validator", meta_v1.GetOptions{})
1319 if err != nil {
1320 return fmt.Errorf("unable to retrieve the operator validator daemonset: %w", err)
1321 }
1322
1323 // update owner reference
1324 pod.SetOwnerReferences(validatorDaemonset.OwnerReferences)
1325 // set pod tolerations
1326 pod.Spec.Tolerations = validatorDaemonset.Spec.Template.Spec.Tolerations
1327 // update podSpec with node name, so it will just run on current node
1328 pod.Spec.NodeName = nodeNameFlag
1329
1330 resourceName, err := p.getGPUResourceName()
1331 if err != nil {
1332 return err
1333 }
1334
1335 gpuResource := corev1.ResourceList{
1336 resourceName: resource.MustParse("1"),
1337 }
1338
1339 pod.Spec.InitContainers[0].Resources.Limits = gpuResource
1340 pod.Spec.InitContainers[0].Resources.Requests = gpuResource
1341 opts := meta_v1.ListOptions{LabelSelector: labels.Set{"app": pluginValidatorLabelValue}.AsSelector().String(),
1342 FieldSelector: fields.Set{"spec.nodeName": nodeNameFlag}.AsSelector().String()}
1343
1344 // check if plugin validation pod is already running and cleanup.
1345 podList, err := p.kubeClient.CoreV1().Pods(namespaceFlag).List(ctx, opts)

Callers 1

validateMethod · 0.95

Calls 8

getGPUResourceNameMethod · 0.95
loadPodSpecFunction · 0.85
waitForPodFunction · 0.85
StringMethod · 0.80
GetMethod · 0.65
ListMethod · 0.65
DeleteMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected