Skip to content

Commit de9f18d

Browse files
apten-forstariq1890
andcommitted
Feat: Allow to configure kubelet root directory
Signed-off-by: Aleksandr Zhitnikov <aleksandr.zhitnikov@gcore.com> Signed-off-by: Tariq Ibrahim <tibrahim@nvidia.com> Co-authored-by: Tariq <tibrahim@nvidia.com>
1 parent eaa68e3 commit de9f18d

8 files changed

Lines changed: 74 additions & 2 deletions

File tree

api/nvidia/v1/clusterpolicy_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ type HostPathsSpec struct {
174174
// DriverInstallDir represents the root at which driver files including libraries,
175175
// config files, and executables can be found.
176176
DriverInstallDir string `json:"driverInstallDir,omitempty"`
177+
178+
// KubeletRootDir represents the location of the kubelet root directory.
179+
// If empty, it will default to "/var/lib/kubelet".
180+
// +kubebuilder:default="/var/lib/kubelet"
181+
KubeletRootDir string `json:"kubeletRootDir,omitempty"`
177182
}
178183

179184
// EnvVar represents an environment variable present in a Container.

bundle/manifests/nvidia.com_clusterpolicies.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,12 @@ spec:
15041504
DriverInstallDir represents the root at which driver files including libraries,
15051505
config files, and executables can be found.
15061506
type: string
1507+
kubeletRootDir:
1508+
default: /var/lib/kubelet
1509+
description: |-
1510+
KubeletRootDir represents the location of the kubelet root directory.
1511+
If empty, it will default to "/var/lib/kubelet".
1512+
type: string
15071513
rootFS:
15081514
description: |-
15091515
RootFS represents the path to the root filesystem of the host.

config/crd/bases/nvidia.com_clusterpolicies.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,12 @@ spec:
15041504
DriverInstallDir represents the root at which driver files including libraries,
15051505
config files, and executables can be found.
15061506
type: string
1507+
kubeletRootDir:
1508+
default: /var/lib/kubelet
1509+
description: |-
1510+
KubeletRootDir represents the location of the kubelet root directory.
1511+
If empty, it will default to "/var/lib/kubelet".
1512+
type: string
15071513
rootFS:
15081514
description: |-
15091515
RootFS represents the path to the root filesystem of the host.

controllers/object_controls.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ const (
181181
HostRootEnvName = "HOST_ROOT"
182182
// DefaultDriverInstallDir represents the default path of a driver container installation
183183
DefaultDriverInstallDir = "/run/nvidia/driver"
184+
// DefaultKubeletRootDir represents the default path of a kubelet root directory
185+
DefaultKubeletRootDir = "/var/lib/kubelet"
184186
// DriverInstallDirEnvName is the name of the envvar used by the driver-validator to represent the driver install dir
185187
DriverInstallDirEnvName = "DRIVER_INSTALL_DIR"
186188
// DriverInstallDirCtrPathEnvName is the name of the envvar used by the driver-validator to represent the path
@@ -1850,6 +1852,17 @@ func TransformDCGMExporter(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpe
18501852
setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), "DCGM_EXPORTER_COLLECTORS", MetricsConfigMountPath)
18511853
}
18521854

1855+
kubeletRootDir := config.HostPaths.KubeletRootDir
1856+
if len(kubeletRootDir) > 0 && kubeletRootDir != DefaultKubeletRootDir {
1857+
for i := range obj.Spec.Template.Spec.Volumes {
1858+
volume := &obj.Spec.Template.Spec.Volumes[i]
1859+
if volume.Name == "pod-resources" {
1860+
volume.HostPath.Path = filepath.Join(kubeletRootDir, "pod-resources")
1861+
break
1862+
}
1863+
}
1864+
}
1865+
18531866
for _, env := range config.DCGMExporter.Env {
18541867
setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), env.Name, env.Value)
18551868
}

controllers/transforms_test.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,8 @@ func TestTransformDCGMExporter(t *testing.T) {
12481248
description: "transform dcgm exporter",
12491249
ds: NewDaemonset().
12501250
WithContainer(corev1.Container{Name: "dcgm-exporter"}).
1251-
WithContainer(corev1.Container{Name: "dummy"}),
1251+
WithContainer(corev1.Container{Name: "dummy"}).
1252+
WithHostPathVolume("pod-resources", "/var/lib/kubelet/pod-resources", nil),
12521253
cpSpec: &gpuv1.ClusterPolicySpec{
12531254
DCGMExporter: gpuv1.DCGMExporterSpec{
12541255
Repository: "nvcr.io/nvidia/cloud-native",
@@ -1274,7 +1275,9 @@ func TestTransformDCGMExporter(t *testing.T) {
12741275
{Name: "DCGM_REMOTE_HOSTENGINE_INFO", Value: "nvidia-dcgm:5555"},
12751276
{Name: "foo", Value: "bar"},
12761277
},
1277-
}).WithContainer(corev1.Container{Name: "dummy"}).WithPullSecret("pull-secret").WithRuntimeClassName("nvidia"),
1278+
}).WithContainer(corev1.Container{Name: "dummy"}).WithPullSecret("pull-secret").
1279+
WithRuntimeClassName("nvidia").
1280+
WithHostPathVolume("pod-resources", "/var/lib/kubelet/pod-resources", nil),
12781281
},
12791282
{
12801283
description: "transform dcgm exporter with hostPID enabled",
@@ -1607,6 +1610,32 @@ func TestTransformDCGMExporter(t *testing.T) {
16071610
}).
16081611
WithRuntimeClassName("nvidia"),
16091612
},
1613+
{
1614+
description: "transform dcgm exporter with custom kubelet root",
1615+
ds: NewDaemonset().
1616+
WithContainer(corev1.Container{Name: "dcgm-exporter"}).
1617+
WithHostPathVolume("pod-resources", "/var/lib/kubelet/pod-resources", nil),
1618+
cpSpec: &gpuv1.ClusterPolicySpec{
1619+
HostPaths: gpuv1.HostPathsSpec{
1620+
KubeletRootDir: "/custom-kubelet",
1621+
},
1622+
DCGMExporter: gpuv1.DCGMExporterSpec{
1623+
Repository: "nvcr.io/nvidia/cloud-native",
1624+
Image: "dcgm-exporter",
1625+
Version: "v1.0.0",
1626+
ImagePullPolicy: "IfNotPresent",
1627+
},
1628+
},
1629+
expectedDs: NewDaemonset().WithContainer(corev1.Container{
1630+
Name: "dcgm-exporter",
1631+
Image: "nvcr.io/nvidia/cloud-native/dcgm-exporter:v1.0.0",
1632+
ImagePullPolicy: corev1.PullIfNotPresent,
1633+
Env: []corev1.EnvVar{
1634+
{Name: "DCGM_REMOTE_HOSTENGINE_INFO", Value: "nvidia-dcgm:5555"},
1635+
},
1636+
}).WithRuntimeClassName("nvidia").
1637+
WithHostPathVolume("pod-resources", "/custom-kubelet/pod-resources", nil),
1638+
},
16101639
}
16111640

16121641
for _, tc := range testCases {

deployments/gpu-operator/crds/nvidia.com_clusterpolicies.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,12 @@ spec:
15041504
DriverInstallDir represents the root at which driver files including libraries,
15051505
config files, and executables can be found.
15061506
type: string
1507+
kubeletRootDir:
1508+
default: /var/lib/kubelet
1509+
description: |-
1510+
KubeletRootDir represents the location of the kubelet root directory.
1511+
If empty, it will default to "/var/lib/kubelet".
1512+
type: string
15071513
rootFS:
15081514
description: |-
15091515
RootFS represents the path to the root filesystem of the host.

deployments/gpu-operator/templates/clusterpolicy.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ spec:
1515
hostPaths:
1616
rootFS: {{ .Values.hostPaths.rootFS }}
1717
driverInstallDir: {{ .Values.hostPaths.driverInstallDir }}
18+
{{- if .Values.hostPaths.kubeletRootDir }}
19+
kubeletRootDir: {{ .Values.hostPaths.kubeletRootDir }}
20+
{{- end }}
1821
operator:
1922
{{- if .Values.operator.runtimeClass }}
2023
runtimeClass: {{ .Values.operator.runtimeClass }}

deployments/gpu-operator/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ hostPaths:
3434
# config files, and executables can be found.
3535
driverInstallDir: "/run/nvidia/driver"
3636

37+
# kubeletRootDir represents the root with the kubelet base directory
38+
# if empty will use /var/lib/kubelet as the default path
39+
# kubeletRootDir: ""
40+
3741
daemonsets:
3842
labels: {}
3943
annotations: {}

0 commit comments

Comments
 (0)