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

Function getDriverAppName

internal/state/driver.go:502–531  ·  view source on GitHub ↗

getDriverAppName returns a unique name for an NVIDIA driver instance in the format nvidia- -driver- - The hash string is calculated from the NVIDIADriver CR UID. The '- ' or '- ' suffix may also be used to calculate the hash if precompi

(cr *nvidiav1alpha1.NVIDIADriver, pool nodePool)

Source from the content-addressed store, hash-verified

500// The '-<kernelVersion>' or '-<rhcosVersion>' suffix may also be used to calculate the hash if precompiled drivers
501// are enabled or the OpenShift Driver Toolkit is used.
502func getDriverAppName(cr *nvidiav1alpha1.NVIDIADriver, pool nodePool) string {
503 const (
504 appNamePrefixFormat = "nvidia-%s-driver-%s"
505 // https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
506 // https://github.com/kubernetes/apimachinery/blob/v0.28.1/pkg/util/validation/validation.go#L182
507 appNameMaxLength = 63
508 )
509
510 var hashBuilder strings.Builder
511
512 appNamePrefix := fmt.Sprintf(appNamePrefixFormat, cr.Spec.DriverType, pool.osTag)
513 uid := string(cr.UID)
514
515 hashBuilder.WriteString(uid)
516 if pool.kernel != "" {
517 hashBuilder.WriteString("-" + pool.kernel)
518 } else if pool.rhcosVersion != "" {
519 hashBuilder.WriteString("-" + pool.rhcosVersion)
520 }
521
522 hash := utils.GetStringHash(hashBuilder.String())
523 appName := fmt.Sprintf("%s-%s", appNamePrefix, hash)
524
525 // truncate the prefix if the app name exceeds the maximum length
526 if len(appName) > appNameMaxLength {
527 appNamePrefixMaxLength := appNameMaxLength - (len(hash) + 1)
528 appName = fmt.Sprintf("%s-%s", appNamePrefix[:appNamePrefixMaxLength], hash)
529 }
530 return appName
531}
532
533func getDefaultStartupProbe(spec *nvidiav1alpha1.NVIDIADriverSpec) *nvidiav1alpha1.ContainerProbeSpec {
534 initialDelaySeconds := int32(60)

Callers 3

getDriverSpecFunction · 0.85
TestGetDriverAppNameFunction · 0.85

Calls 2

GetStringHashFunction · 0.92
StringMethod · 0.80

Tested by 2

TestGetDriverAppNameFunction · 0.68