Skip to content

Commit 792459f

Browse files
Use methods in methods provided in k8s.io/utils/ptr instead of internal package
Signed-off-by: Karthik Vetrivel <[email protected]>
1 parent 62ca84d commit 792459f

File tree

5 files changed

+64
-101
lines changed

5 files changed

+64
-101
lines changed

controllers/object_controls.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ import (
4545
"k8s.io/apimachinery/pkg/runtime/schema"
4646
"k8s.io/apimachinery/pkg/types"
4747
"k8s.io/apimachinery/pkg/util/intstr"
48+
"k8s.io/utils/ptr"
4849
"sigs.k8s.io/controller-runtime/pkg/client"
4950
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
5051
"sigs.k8s.io/yaml"
5152

5253
gpuv1 "github.com/NVIDIA/gpu-operator/api/nvidia/v1"
5354
"github.com/NVIDIA/gpu-operator/internal/consts"
5455
"github.com/NVIDIA/gpu-operator/internal/utils"
55-
"github.com/NVIDIA/gpu-operator/internal/utils/ptr"
5656
)
5757

5858
const (
@@ -202,7 +202,7 @@ const (
202202
)
203203

204204
// rootUID represents user 0
205-
var rootUID = ptr.Int64(0)
205+
var rootUID = ptr.To(int64(0))
206206

207207
// RepoConfigPathMap indicates standard OS specific paths for repository configuration files
208208
var RepoConfigPathMap = map[string]string{
@@ -235,67 +235,67 @@ var SubscriptionPathMap = map[string](MountPathToVolumeSource){
235235
"/run/secrets/etc-pki-entitlement": corev1.VolumeSource{
236236
HostPath: &corev1.HostPathVolumeSource{
237237
Path: "/etc/pki/entitlement",
238-
Type: ptr.HostPathType(corev1.HostPathDirectory),
238+
Type: ptr.To(corev1.HostPathDirectory),
239239
},
240240
},
241241
"/run/secrets/redhat.repo": corev1.VolumeSource{
242242
HostPath: &corev1.HostPathVolumeSource{
243243
Path: "/etc/yum.repos.d/redhat.repo",
244-
Type: ptr.HostPathType(corev1.HostPathFile),
244+
Type: ptr.To(corev1.HostPathFile),
245245
},
246246
},
247247
"/run/secrets/rhsm": corev1.VolumeSource{
248248
HostPath: &corev1.HostPathVolumeSource{
249249
Path: "/etc/rhsm",
250-
Type: ptr.HostPathType(corev1.HostPathDirectory),
250+
Type: ptr.To(corev1.HostPathDirectory),
251251
},
252252
},
253253
},
254254
"rhcos": {
255255
"/run/secrets/etc-pki-entitlement": corev1.VolumeSource{
256256
HostPath: &corev1.HostPathVolumeSource{
257257
Path: "/etc/pki/entitlement",
258-
Type: ptr.HostPathType(corev1.HostPathDirectory),
258+
Type: ptr.To(corev1.HostPathDirectory),
259259
},
260260
},
261261
"/run/secrets/redhat.repo": corev1.VolumeSource{
262262
HostPath: &corev1.HostPathVolumeSource{
263263
Path: "/etc/yum.repos.d/redhat.repo",
264-
Type: ptr.HostPathType(corev1.HostPathFile),
264+
Type: ptr.To(corev1.HostPathFile),
265265
},
266266
},
267267
"/run/secrets/rhsm": corev1.VolumeSource{
268268
HostPath: &corev1.HostPathVolumeSource{
269269
Path: "/etc/rhsm",
270-
Type: ptr.HostPathType(corev1.HostPathDirectory),
270+
Type: ptr.To(corev1.HostPathDirectory),
271271
},
272272
},
273273
},
274274
"sles": {
275275
"/etc/zypp/credentials.d": corev1.VolumeSource{
276276
HostPath: &corev1.HostPathVolumeSource{
277277
Path: "/etc/zypp/credentials.d",
278-
Type: ptr.HostPathType(corev1.HostPathDirectory),
278+
Type: ptr.To(corev1.HostPathDirectory),
279279
},
280280
},
281281
"/etc/SUSEConnect": corev1.VolumeSource{
282282
HostPath: &corev1.HostPathVolumeSource{
283283
Path: "/etc/SUSEConnect",
284-
Type: ptr.HostPathType(corev1.HostPathFileOrCreate),
284+
Type: ptr.To(corev1.HostPathFileOrCreate),
285285
},
286286
},
287287
},
288288
"sl-micro": {
289289
"/etc/zypp/credentials.d": corev1.VolumeSource{
290290
HostPath: &corev1.HostPathVolumeSource{
291291
Path: "/etc/zypp/credentials.d",
292-
Type: ptr.HostPathType(corev1.HostPathDirectory),
292+
Type: ptr.To(corev1.HostPathDirectory),
293293
},
294294
},
295295
"/etc/SUSEConnect": corev1.VolumeSource{
296296
HostPath: &corev1.HostPathVolumeSource{
297297
Path: "/etc/SUSEConnect",
298-
Type: ptr.HostPathType(corev1.HostPathFileOrCreate),
298+
Type: ptr.To(corev1.HostPathFileOrCreate),
299299
},
300300
},
301301
},
@@ -1380,7 +1380,7 @@ func transformForRuntime(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec,
13801380
volMountConfig := corev1.VolumeMount{Name: volMountConfigName, MountPath: containerConfigDir}
13811381
container.VolumeMounts = append(container.VolumeMounts, volMountConfig)
13821382

1383-
configVol := corev1.Volume{Name: volMountConfigName, VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{Path: sourceConfigDir, Type: ptr.HostPathType(corev1.HostPathDirectoryOrCreate)}}}
1383+
configVol := corev1.Volume{Name: volMountConfigName, VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{Path: sourceConfigDir, Type: ptr.To(corev1.HostPathDirectoryOrCreate)}}}
13841384
obj.Spec.Template.Spec.Volumes = append(obj.Spec.Template.Spec.Volumes, configVol)
13851385
}
13861386

@@ -1402,7 +1402,7 @@ func transformForRuntime(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec,
14021402
volMountConfig := corev1.VolumeMount{Name: volMountConfigName, MountPath: containerConfigDir}
14031403
container.VolumeMounts = append(container.VolumeMounts, volMountConfig)
14041404

1405-
configVol := corev1.Volume{Name: volMountConfigName, VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{Path: sourceConfigDir, Type: ptr.HostPathType(corev1.HostPathDirectoryOrCreate)}}}
1405+
configVol := corev1.Volume{Name: volMountConfigName, VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{Path: sourceConfigDir, Type: ptr.To(corev1.HostPathDirectoryOrCreate)}}}
14061406
obj.Spec.Template.Spec.Volumes = append(obj.Spec.Template.Spec.Volumes, configVol)
14071407
}
14081408

@@ -1959,7 +1959,7 @@ func TransformKataManager(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec
19591959
artifactsVolMount := corev1.VolumeMount{Name: "kata-artifacts", MountPath: artifactsDir}
19601960
obj.Spec.Template.Spec.Containers[0].VolumeMounts = append(obj.Spec.Template.Spec.Containers[0].VolumeMounts, artifactsVolMount)
19611961

1962-
artifactsVol := corev1.Volume{Name: "kata-artifacts", VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{Path: artifactsDir, Type: ptr.HostPathType(corev1.HostPathDirectoryOrCreate)}}}
1962+
artifactsVol := corev1.Volume{Name: "kata-artifacts", VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{Path: artifactsDir, Type: ptr.To(corev1.HostPathDirectoryOrCreate)}}}
19631963
obj.Spec.Template.Spec.Volumes = append(obj.Spec.Template.Spec.Volumes, artifactsVol)
19641964

19651965
// Compute hash of kata manager config and add an annotation with the value.

controllers/transforms_test.go

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

3535
gpuv1 "github.com/NVIDIA/gpu-operator/api/nvidia/v1"
36-
internalptr "github.com/NVIDIA/gpu-operator/internal/utils/ptr"
3736
)
3837

3938
var mockClientMap map[string]client.Client
@@ -378,8 +377,8 @@ func TestTransformForRuntime(t *testing.T) {
378377
input: NewDaemonset().
379378
WithContainer(corev1.Container{Name: "test-ctr"}),
380379
expectedOutput: NewDaemonset().
381-
WithHostPathVolume("containerd-config", filepath.Dir(DefaultContainerdConfigFile), internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
382-
WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
380+
WithHostPathVolume("containerd-config", filepath.Dir(DefaultContainerdConfigFile), ptr.To(corev1.HostPathDirectoryOrCreate)).
381+
WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)).
383382
WithHostPathVolume("containerd-socket", filepath.Dir(DefaultContainerdSocketFile), nil).
384383
WithContainer(corev1.Container{
385384
Name: "test-ctr",
@@ -411,8 +410,8 @@ func TestTransformForRuntime(t *testing.T) {
411410
},
412411
}),
413412
expectedOutput: NewDaemonset().
414-
WithHostPathVolume("containerd-config", filepath.Dir(DefaultContainerdConfigFile), internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
415-
WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
413+
WithHostPathVolume("containerd-config", filepath.Dir(DefaultContainerdConfigFile), ptr.To(corev1.HostPathDirectoryOrCreate)).
414+
WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)).
416415
WithHostPathVolume("containerd-socket", filepath.Dir(DefaultContainerdSocketFile), nil).
417416
WithContainer(corev1.Container{
418417
Name: "test-ctr",
@@ -445,8 +444,8 @@ func TestTransformForRuntime(t *testing.T) {
445444
},
446445
}),
447446
expectedOutput: NewDaemonset().
448-
WithHostPathVolume("containerd-config", filepath.Dir(DefaultContainerdConfigFile), internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
449-
WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
447+
WithHostPathVolume("containerd-config", filepath.Dir(DefaultContainerdConfigFile), ptr.To(corev1.HostPathDirectoryOrCreate)).
448+
WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)).
450449
WithHostPathVolume("containerd-socket", filepath.Dir(DefaultContainerdSocketFile), nil).
451450
WithContainer(corev1.Container{
452451
Name: "test-ctr",
@@ -473,8 +472,8 @@ func TestTransformForRuntime(t *testing.T) {
473472
runtime: gpuv1.CRIO,
474473
input: NewDaemonset().WithContainer(corev1.Container{Name: "test-ctr"}),
475474
expectedOutput: NewDaemonset().
476-
WithHostPathVolume("crio-config", "/etc/crio", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
477-
WithHostPathVolume("crio-drop-in-config", "/etc/crio/crio.conf.d", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
475+
WithHostPathVolume("crio-config", "/etc/crio", ptr.To(corev1.HostPathDirectoryOrCreate)).
476+
WithHostPathVolume("crio-drop-in-config", "/etc/crio/crio.conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)).
478477
WithContainer(corev1.Container{
479478
Name: "test-ctr",
480479
Env: []corev1.EnvVar{
@@ -497,7 +496,7 @@ func TestTransformForRuntime(t *testing.T) {
497496
input: NewDaemonset().
498497
WithContainer(corev1.Container{Name: "nvidia-kata-manager"}),
499498
expectedOutput: NewDaemonset().
500-
WithHostPathVolume("containerd-config", filepath.Dir(DefaultContainerdConfigFile), internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
499+
WithHostPathVolume("containerd-config", filepath.Dir(DefaultContainerdConfigFile), ptr.To(corev1.HostPathDirectoryOrCreate)).
501500
WithHostPathVolume("containerd-socket", filepath.Dir(DefaultContainerdSocketFile), nil).
502501
WithContainer(corev1.Container{
503502
Name: "nvidia-kata-manager",
@@ -520,7 +519,7 @@ func TestTransformForRuntime(t *testing.T) {
520519
runtime: gpuv1.Docker,
521520
input: NewDaemonset().WithContainer(corev1.Container{Name: "test-ctr"}),
522521
expectedOutput: NewDaemonset().
523-
WithHostPathVolume("docker-config", filepath.Dir(DefaultDockerConfigFile), internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
522+
WithHostPathVolume("docker-config", filepath.Dir(DefaultDockerConfigFile), ptr.To(corev1.HostPathDirectoryOrCreate)).
524523
WithHostPathVolume("docker-socket", filepath.Dir(DefaultDockerSocketFile), nil).
525524
WithContainer(corev1.Container{
526525
Name: "test-ctr",
@@ -841,8 +840,8 @@ func TestTransformToolkit(t *testing.T) {
841840
{Name: "containerd-socket", MountPath: "/runtime/sock-dir/"},
842841
},
843842
}).
844-
WithHostPathVolume("containerd-config", "/etc/containerd", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
845-
WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
843+
WithHostPathVolume("containerd-config", "/etc/containerd", ptr.To(corev1.HostPathDirectoryOrCreate)).
844+
WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)).
846845
WithHostPathVolume("containerd-socket", "/run/containerd", nil).
847846
WithPullSecret("pull-secret"),
848847
},
@@ -920,8 +919,8 @@ func TestTransformToolkit(t *testing.T) {
920919
{Name: "containerd-socket", MountPath: "/runtime/sock-dir/"},
921920
},
922921
}).
923-
WithHostPathVolume("containerd-config", "/var/lib/rancher/k3s/agent/etc/containerd", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
924-
WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
922+
WithHostPathVolume("containerd-config", "/var/lib/rancher/k3s/agent/etc/containerd", ptr.To(corev1.HostPathDirectoryOrCreate)).
923+
WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)).
925924
WithHostPathVolume("containerd-socket", "/run/k3s/containerd", nil).
926925
WithPullSecret("pull-secret"),
927926
},
@@ -958,8 +957,8 @@ func TestTransformToolkit(t *testing.T) {
958957
{Name: "crio-drop-in-config", MountPath: "/runtime/config-dir.d/"},
959958
},
960959
}).
961-
WithHostPathVolume("crio-config", "/etc/crio", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
962-
WithHostPathVolume("crio-drop-in-config", "/etc/crio/crio.conf.d", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)),
960+
WithHostPathVolume("crio-config", "/etc/crio", ptr.To(corev1.HostPathDirectoryOrCreate)).
961+
WithHostPathVolume("crio-drop-in-config", "/etc/crio/crio.conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)),
963962
},
964963
{
965964
description: "transform nvidia-container-toolkit-ctr container, cri-o runtime, cdi disabled",
@@ -994,8 +993,8 @@ func TestTransformToolkit(t *testing.T) {
994993
{Name: "crio-drop-in-config", MountPath: "/runtime/config-dir.d/"},
995994
},
996995
}).
997-
WithHostPathVolume("crio-config", "/etc/crio", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
998-
WithHostPathVolume("crio-drop-in-config", "/etc/crio/crio.conf.d", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)),
996+
WithHostPathVolume("crio-config", "/etc/crio", ptr.To(corev1.HostPathDirectoryOrCreate)).
997+
WithHostPathVolume("crio-drop-in-config", "/etc/crio/crio.conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)),
999998
},
1000999
}
10011000

@@ -1121,8 +1120,8 @@ func TestTransformMPSControlDaemon(t *testing.T) {
11211120
daemonset: NewDaemonset().
11221121
WithInitContainer(corev1.Container{Name: "mps-control-daemon-mounts"}).
11231122
WithContainer(corev1.Container{Name: "mps-control-daemon-ctr"}).
1124-
WithHostPathVolume("mps-root", "/run/nvidia/mps", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
1125-
WithHostPathVolume("mps-shm", "/run/nvidia/mps/shm", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)),
1123+
WithHostPathVolume("mps-root", "/run/nvidia/mps", ptr.To(corev1.HostPathDirectoryOrCreate)).
1124+
WithHostPathVolume("mps-shm", "/run/nvidia/mps/shm", ptr.To(corev1.HostPathDirectoryOrCreate)),
11261125
clusterPolicySpec: &gpuv1.ClusterPolicySpec{
11271126
DevicePlugin: gpuv1.DevicePluginSpec{
11281127
Repository: "nvcr.io",
@@ -1147,8 +1146,8 @@ func TestTransformMPSControlDaemon(t *testing.T) {
11471146
{Name: "NVIDIA_MIG_MONITOR_DEVICES", Value: "all"},
11481147
},
11491148
}).
1150-
WithHostPathVolume("mps-root", "/var/mps", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
1151-
WithHostPathVolume("mps-shm", "/var/mps/shm", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
1149+
WithHostPathVolume("mps-root", "/var/mps", ptr.To(corev1.HostPathDirectoryOrCreate)).
1150+
WithHostPathVolume("mps-shm", "/var/mps/shm", ptr.To(corev1.HostPathDirectoryOrCreate)).
11521151
WithPullSecret("secret").
11531152
WithRuntimeClassName("nvidia"),
11541153
},
@@ -1541,7 +1540,7 @@ func TestTransformKataManager(t *testing.T) {
15411540
{Name: "containerd-config", MountPath: "/runtime/config-dir/"},
15421541
{Name: "containerd-socket", MountPath: "/runtime/sock-dir/"},
15431542
},
1544-
}).WithPullSecret("pull-secret").WithPodAnnotations(map[string]string{"nvidia.com/kata-manager.last-applied-hash": "1929911998"}).WithHostPathVolume("kata-artifacts", "/var/lib/kata", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).WithHostPathVolume("containerd-config", "/etc/containerd", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).WithHostPathVolume("containerd-socket", "/run/containerd", nil),
1543+
}).WithPullSecret("pull-secret").WithPodAnnotations(map[string]string{"nvidia.com/kata-manager.last-applied-hash": "1929911998"}).WithHostPathVolume("kata-artifacts", "/var/lib/kata", ptr.To(corev1.HostPathDirectoryOrCreate)).WithHostPathVolume("containerd-config", "/etc/containerd", ptr.To(corev1.HostPathDirectoryOrCreate)).WithHostPathVolume("containerd-socket", "/run/containerd", nil),
15451544
},
15461545
{
15471546
description: "transform kata manager with custom container runtime socket",
@@ -1595,8 +1594,8 @@ func TestTransformKataManager(t *testing.T) {
15951594
},
15961595
}).WithPullSecret("pull-secret").
15971596
WithPodAnnotations(map[string]string{"nvidia.com/kata-manager.last-applied-hash": "1929911998"}).
1598-
WithHostPathVolume("kata-artifacts", "/var/lib/kata", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
1599-
WithHostPathVolume("containerd-config", "/var/lib/rancher/k3s/agent/etc/containerd", internalptr.HostPathType(corev1.HostPathDirectoryOrCreate)).
1597+
WithHostPathVolume("kata-artifacts", "/var/lib/kata", ptr.To(corev1.HostPathDirectoryOrCreate)).
1598+
WithHostPathVolume("containerd-config", "/var/lib/rancher/k3s/agent/etc/containerd", ptr.To(corev1.HostPathDirectoryOrCreate)).
16001599
WithHostPathVolume("containerd-socket", "/run/k3s/containerd", nil),
16011600
},
16021601
}

0 commit comments

Comments
 (0)