Skip to content

Commit dc835ef

Browse files
authored
Merge pull request #1831 from karthikvetrivel/refactor/deduplicate-vgpu-constants
[refactor] Remove duplicated VGPU constants from controllers and use internal/consts package
2 parents d0e377a + 93b1e8b commit dc835ef

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

controllers/object_controls.go

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,6 @@ const (
7878
TrustedCABundleMountDir = "/etc/pki/ca-trust/extracted/pem"
7979
// TrustedCACertificate indicates injected CA certificate name
8080
TrustedCACertificate = "tls-ca-bundle.pem"
81-
// VGPULicensingConfigMountPath indicates target mount path for vGPU licensing configuration file
82-
VGPULicensingConfigMountPath = "/drivers/gridd.conf"
83-
// VGPULicensingFileName is the vGPU licensing configuration filename
84-
VGPULicensingFileName = "gridd.conf"
85-
// NLSClientTokenMountPath inidicates the target mount path for NLS client config token file (.tok)
86-
NLSClientTokenMountPath = "/drivers/ClientConfigToken/client_configuration_token.tok"
87-
// NLSClientTokenFileName is the NLS client config token filename
88-
NLSClientTokenFileName = "client_configuration_token.tok"
89-
// VGPUTopologyConfigMountPath indicates target mount path for vGPU topology daemon configuration file
90-
VGPUTopologyConfigMountPath = "/etc/nvidia/nvidia-topologyd.conf"
91-
// VGPUTopologyConfigFileName is the vGPU topology daemon configuration filename
92-
VGPUTopologyConfigFileName = "nvidia-topologyd.conf"
9381
// DefaultRuntimeClass represents "nvidia" RuntimeClass
9482
DefaultRuntimeClass = "nvidia"
9583
// DriverInstallPathVolName represents volume name for driver install path provided to toolkit
@@ -3329,23 +3317,23 @@ func applyLicensingConfig(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec
33293317
podSpec := &obj.Spec.Template.Spec
33303318

33313319
// add new volume mount
3332-
licensingConfigVolMount := corev1.VolumeMount{Name: "licensing-config", ReadOnly: true, MountPath: VGPULicensingConfigMountPath, SubPath: VGPULicensingFileName}
3320+
licensingConfigVolMount := corev1.VolumeMount{Name: "licensing-config", ReadOnly: true, MountPath: consts.VGPULicensingConfigMountPath, SubPath: consts.VGPULicensingFileName}
33333321
driverContainer.VolumeMounts = append(driverContainer.VolumeMounts, licensingConfigVolMount)
33343322

33353323
// gridd.conf always mounted
33363324
licenseItemsToInclude := []corev1.KeyToPath{
33373325
{
3338-
Key: VGPULicensingFileName,
3339-
Path: VGPULicensingFileName,
3326+
Key: consts.VGPULicensingFileName,
3327+
Path: consts.VGPULicensingFileName,
33403328
},
33413329
}
33423330
// client config token only mounted when NLS is enabled
33433331
if config.Driver.LicensingConfig.IsNLSEnabled() {
33443332
licenseItemsToInclude = append(licenseItemsToInclude, corev1.KeyToPath{
3345-
Key: NLSClientTokenFileName,
3346-
Path: NLSClientTokenFileName,
3333+
Key: consts.NLSClientTokenFileName,
3334+
Path: consts.NLSClientTokenFileName,
33473335
})
3348-
nlsTokenVolMount := corev1.VolumeMount{Name: "licensing-config", ReadOnly: true, MountPath: NLSClientTokenMountPath, SubPath: NLSClientTokenFileName}
3336+
nlsTokenVolMount := corev1.VolumeMount{Name: "licensing-config", ReadOnly: true, MountPath: consts.NLSClientTokenMountPath, SubPath: consts.NLSClientTokenFileName}
33493337
driverContainer.VolumeMounts = append(driverContainer.VolumeMounts, nlsTokenVolMount)
33503338
}
33513339

@@ -3446,7 +3434,7 @@ func transformDriverContainer(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicy
34463434

34473435
// set virtual topology daemon configuration if specified for vGPU driver
34483436
if config.Driver.VirtualTopology != nil && config.Driver.VirtualTopology.Config != "" {
3449-
topologyConfigVolMount := corev1.VolumeMount{Name: "topology-config", ReadOnly: true, MountPath: VGPUTopologyConfigMountPath, SubPath: VGPUTopologyConfigFileName}
3437+
topologyConfigVolMount := corev1.VolumeMount{Name: "topology-config", ReadOnly: true, MountPath: consts.VGPUTopologyConfigMountPath, SubPath: consts.VGPUTopologyConfigFileName}
34503438
driverContainer.VolumeMounts = append(driverContainer.VolumeMounts, topologyConfigVolMount)
34513439

34523440
topologyConfigVolumeSource := corev1.VolumeSource{
@@ -3456,8 +3444,8 @@ func transformDriverContainer(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicy
34563444
},
34573445
Items: []corev1.KeyToPath{
34583446
{
3459-
Key: VGPUTopologyConfigFileName,
3460-
Path: VGPUTopologyConfigFileName,
3447+
Key: consts.VGPUTopologyConfigFileName,
3448+
Path: consts.VGPUTopologyConfigFileName,
34613449
},
34623450
},
34633451
},

controllers/transforms_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3434

3535
gpuv1 "github.com/NVIDIA/gpu-operator/api/nvidia/v1"
36+
"github.com/NVIDIA/gpu-operator/internal/consts"
3637
)
3738

3839
var mockClientMap map[string]client.Client
@@ -2910,8 +2911,8 @@ func TestTransformDriverWithLicensingConfig(t *testing.T) {
29102911
{
29112912
Name: "licensing-config",
29122913
ReadOnly: true,
2913-
MountPath: VGPULicensingConfigMountPath,
2914-
SubPath: VGPULicensingFileName,
2914+
MountPath: consts.VGPULicensingConfigMountPath,
2915+
SubPath: consts.VGPULicensingFileName,
29152916
},
29162917
},
29172918
}).WithInitContainer(corev1.Container{
@@ -2925,8 +2926,8 @@ func TestTransformDriverWithLicensingConfig(t *testing.T) {
29252926
SecretName: "test-secret",
29262927
Items: []corev1.KeyToPath{
29272928
{
2928-
Key: VGPULicensingFileName,
2929-
Path: VGPULicensingFileName,
2929+
Key: consts.VGPULicensingFileName,
2930+
Path: consts.VGPULicensingFileName,
29302931
},
29312932
},
29322933
},
@@ -2964,8 +2965,8 @@ func TestTransformDriverWithLicensingConfig(t *testing.T) {
29642965
{
29652966
Name: "licensing-config",
29662967
ReadOnly: true,
2967-
MountPath: VGPULicensingConfigMountPath,
2968-
SubPath: VGPULicensingFileName,
2968+
MountPath: consts.VGPULicensingConfigMountPath,
2969+
SubPath: consts.VGPULicensingFileName,
29692970
},
29702971
},
29712972
}).WithInitContainer(corev1.Container{
@@ -2981,8 +2982,8 @@ func TestTransformDriverWithLicensingConfig(t *testing.T) {
29812982
},
29822983
Items: []corev1.KeyToPath{
29832984
{
2984-
Key: VGPULicensingFileName,
2985-
Path: VGPULicensingFileName,
2985+
Key: consts.VGPULicensingFileName,
2986+
Path: consts.VGPULicensingFileName,
29862987
},
29872988
},
29882989
},

0 commit comments

Comments
 (0)