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

Function createConfigMapVolumeMounts

controllers/object_controls.go:3461–3489  ·  view source on GitHub ↗

createConfigMapVolumeMounts creates a VolumeMount for each key in the ConfigMap. Use subPath to ensure original contents at destinationDir are not overwritten.

(n ClusterPolicyController, configMapName string, destinationDir string)

Source from the content-addressed store, hash-verified

3459// in the ConfigMap. Use subPath to ensure original contents
3460// at destinationDir are not overwritten.
3461func createConfigMapVolumeMounts(n ClusterPolicyController, configMapName string, destinationDir string) ([]corev1.VolumeMount, []corev1.KeyToPath, error) {
3462 ctx := n.ctx
3463 // get the ConfigMap
3464 cm := &corev1.ConfigMap{}
3465 opts := client.ObjectKey{Namespace: n.operatorNamespace, Name: configMapName}
3466 err := n.client.Get(ctx, opts, cm)
3467 if err != nil {
3468 return nil, nil, fmt.Errorf("ERROR: could not get ConfigMap %s from client: %v", configMapName, err)
3469 }
3470
3471 // create one volume mount per file in the ConfigMap and use subPath
3472 var filenames []string
3473 for filename := range cm.Data {
3474 filenames = append(filenames, filename)
3475 }
3476 // sort so volume mounts are added to spec in deterministic order
3477 sort.Strings(filenames)
3478 var itemsToInclude []corev1.KeyToPath
3479 var volumeMounts []corev1.VolumeMount
3480 for _, filename := range filenames {
3481 volumeMounts = append(volumeMounts,
3482 corev1.VolumeMount{Name: configMapName, ReadOnly: true, MountPath: filepath.Join(destinationDir, filename), SubPath: filename})
3483 itemsToInclude = append(itemsToInclude, corev1.KeyToPath{
3484 Key: filename,
3485 Path: filename,
3486 })
3487 }
3488 return volumeMounts, itemsToInclude, nil
3489}
3490
3491func createConfigMapVolume(configMapName string, itemsToInclude []corev1.KeyToPath) corev1.Volume {
3492 volumeSource := corev1.VolumeSource{

Callers 5

transformGDSContainerFunction · 0.85
transformDriverContainerFunction · 0.85

Calls 1

GetMethod · 0.65

Tested by

no test coverage detected