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

Method runWorkload

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

Source from the content-addressed store, hash-verified

1550}
1551
1552func (c *CUDA) runWorkload() error {
1553 ctx := c.ctx
1554
1555 // load podSpec
1556 pod, err := loadPodSpec(cudaWorkloadPodSpecPath)
1557 if err != nil {
1558 return err
1559 }
1560 pod.Namespace = namespaceFlag
1561 image := os.Getenv(validatorImageEnvName)
1562 pod.Spec.Containers[0].Image = image
1563 pod.Spec.InitContainers[0].Image = image
1564
1565 imagePullPolicy := os.Getenv(validatorImagePullPolicyEnvName)
1566 if imagePullPolicy != "" {
1567 pod.Spec.Containers[0].ImagePullPolicy = corev1.PullPolicy(imagePullPolicy)
1568 pod.Spec.InitContainers[0].ImagePullPolicy = corev1.PullPolicy(imagePullPolicy)
1569 }
1570
1571 if os.Getenv(validatorImagePullSecretsEnvName) != "" {
1572 pullSecrets := strings.Split(os.Getenv(validatorImagePullSecretsEnvName), ",")
1573 for _, secret := range pullSecrets {
1574 pod.Spec.ImagePullSecrets = append(pod.Spec.ImagePullSecrets, corev1.LocalObjectReference{Name: secret})
1575 }
1576 }
1577 if os.Getenv(validatorRuntimeClassEnvName) != "" {
1578 runtimeClass := os.Getenv(validatorRuntimeClassEnvName)
1579 pod.Spec.RuntimeClassName = &runtimeClass
1580 }
1581
1582 validatorDaemonset, err := c.kubeClient.AppsV1().DaemonSets(namespaceFlag).Get(ctx, "nvidia-operator-validator", meta_v1.GetOptions{})
1583 if err != nil {
1584 return fmt.Errorf("unable to retrieve the operator validator daemonset: %w", err)
1585 }
1586
1587 // update owner reference
1588 pod.SetOwnerReferences(validatorDaemonset.OwnerReferences)
1589 // set pod tolerations
1590 pod.Spec.Tolerations = validatorDaemonset.Spec.Template.Spec.Tolerations
1591 // update podSpec with node name, so it will just run on current node
1592 pod.Spec.NodeName = nodeNameFlag
1593
1594 opts := meta_v1.ListOptions{LabelSelector: labels.Set{"app": cudaValidatorLabelValue}.AsSelector().String(),
1595 FieldSelector: fields.Set{"spec.nodeName": nodeNameFlag}.AsSelector().String()}
1596
1597 // check if cuda workload pod is already running and cleanup.
1598 podList, err := c.kubeClient.CoreV1().Pods(namespaceFlag).List(ctx, opts)
1599 if err != nil {
1600 return fmt.Errorf("cannot list existing validation pods: %s", err)
1601 }
1602
1603 if podList != nil && len(podList.Items) > 0 {
1604 propagation := meta_v1.DeletePropagationBackground
1605 gracePeriod := int64(0)
1606 options := meta_v1.DeleteOptions{PropagationPolicy: &propagation, GracePeriodSeconds: &gracePeriod}
1607 err = c.kubeClient.CoreV1().Pods(namespaceFlag).Delete(ctx, podList.Items[0].Name, options)
1608 if err != nil {
1609 return fmt.Errorf("cannot delete previous validation pod: %s", err)

Callers 1

validateMethod · 0.95

Calls 7

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