Skip to content

Commit 7cd9dbe

Browse files
Extract newHostPathType to public HostPathTypePtr utility function
Signed-off-by: Karthik Vetrivel <[email protected]>
1 parent c5d513d commit 7cd9dbe

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

internal/state/driver_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ func getSampleAdditionalConfigs() *additionalConfigs {
703703
VolumeSource: corev1.VolumeSource{
704704
HostPath: &corev1.HostPathVolumeSource{
705705
Path: "/opt/config/test-host-path",
706-
Type: newHostPathType(corev1.HostPathDirectoryOrCreate),
706+
Type: utils.HostPathTypePtr(corev1.HostPathDirectoryOrCreate),
707707
},
708708
},
709709
},
@@ -712,7 +712,7 @@ func getSampleAdditionalConfigs() *additionalConfigs {
712712
VolumeSource: corev1.VolumeSource{
713713
HostPath: &corev1.HostPathVolumeSource{
714714
Path: "/opt/config/test-host-path-ro",
715-
Type: newHostPathType(corev1.HostPathDirectoryOrCreate),
715+
Type: utils.HostPathTypePtr(corev1.HostPathDirectoryOrCreate),
716716
},
717717
},
718718
},

internal/state/driver_volumes.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/NVIDIA/gpu-operator/api/nvidia/v1alpha1"
2828
"github.com/NVIDIA/gpu-operator/controllers/clusterinfo"
2929
"github.com/NVIDIA/gpu-operator/internal/consts"
30+
"github.com/NVIDIA/gpu-operator/internal/utils"
3031
)
3132

3233
// RepoConfigPathMap indicates standard OS specific paths for repository configuration files
@@ -60,79 +61,72 @@ var SubscriptionPathMap = map[string]MountPathToVolumeSource{
6061
"/run/secrets/etc-pki-entitlement": corev1.VolumeSource{
6162
HostPath: &corev1.HostPathVolumeSource{
6263
Path: "/etc/pki/entitlement",
63-
Type: newHostPathType(corev1.HostPathDirectory),
64+
Type: utils.HostPathTypePtr(corev1.HostPathDirectory),
6465
},
6566
},
6667
"/run/secrets/redhat.repo": corev1.VolumeSource{
6768
HostPath: &corev1.HostPathVolumeSource{
6869
Path: "/etc/yum.repos.d/redhat.repo",
69-
Type: newHostPathType(corev1.HostPathFile),
70+
Type: utils.HostPathTypePtr(corev1.HostPathFile),
7071
},
7172
},
7273
"/run/secrets/rhsm": corev1.VolumeSource{
7374
HostPath: &corev1.HostPathVolumeSource{
7475
Path: "/etc/rhsm",
75-
Type: newHostPathType(corev1.HostPathDirectory),
76+
Type: utils.HostPathTypePtr(corev1.HostPathDirectory),
7677
},
7778
},
7879
},
7980
"rhcos": {
8081
"/run/secrets/etc-pki-entitlement": corev1.VolumeSource{
8182
HostPath: &corev1.HostPathVolumeSource{
8283
Path: "/etc/pki/entitlement",
83-
Type: newHostPathType(corev1.HostPathDirectory),
84+
Type: utils.HostPathTypePtr(corev1.HostPathDirectory),
8485
},
8586
},
8687
"/run/secrets/redhat.repo": corev1.VolumeSource{
8788
HostPath: &corev1.HostPathVolumeSource{
8889
Path: "/etc/yum.repos.d/redhat.repo",
89-
Type: newHostPathType(corev1.HostPathFile),
90+
Type: utils.HostPathTypePtr(corev1.HostPathFile),
9091
},
9192
},
9293
"/run/secrets/rhsm": corev1.VolumeSource{
9394
HostPath: &corev1.HostPathVolumeSource{
9495
Path: "/etc/rhsm",
95-
Type: newHostPathType(corev1.HostPathDirectory),
96+
Type: utils.HostPathTypePtr(corev1.HostPathDirectory),
9697
},
9798
},
9899
},
99100
"sles": {
100101
"/etc/zypp/credentials.d": corev1.VolumeSource{
101102
HostPath: &corev1.HostPathVolumeSource{
102103
Path: "/etc/zypp/credentials.d",
103-
Type: newHostPathType(corev1.HostPathDirectory),
104+
Type: utils.HostPathTypePtr(corev1.HostPathDirectory),
104105
},
105106
},
106107
"/etc/SUSEConnect": corev1.VolumeSource{
107108
HostPath: &corev1.HostPathVolumeSource{
108109
Path: "/etc/SUSEConnect",
109-
Type: newHostPathType(corev1.HostPathFileOrCreate),
110+
Type: utils.HostPathTypePtr(corev1.HostPathFileOrCreate),
110111
},
111112
},
112113
},
113114
"sl-micro": {
114115
"/etc/zypp/credentials.d": corev1.VolumeSource{
115116
HostPath: &corev1.HostPathVolumeSource{
116117
Path: "/etc/zypp/credentials.d",
117-
Type: newHostPathType(corev1.HostPathDirectory),
118+
Type: utils.HostPathTypePtr(corev1.HostPathDirectory),
118119
},
119120
},
120121
"/etc/SUSEConnect": corev1.VolumeSource{
121122
HostPath: &corev1.HostPathVolumeSource{
122123
Path: "/etc/SUSEConnect",
123-
Type: newHostPathType(corev1.HostPathFileOrCreate),
124+
Type: utils.HostPathTypePtr(corev1.HostPathFileOrCreate),
124125
},
125126
},
126127
},
127128
}
128129

129-
// TODO: make this a public utils method
130-
func newHostPathType(pathType corev1.HostPathType) *corev1.HostPathType {
131-
hostPathType := new(corev1.HostPathType)
132-
*hostPathType = pathType
133-
return hostPathType
134-
}
135-
136130
func (s *stateDriver) getDriverAdditionalConfigs(ctx context.Context, cr *v1alpha1.NVIDIADriver, info clusterinfo.Interface, pool nodePool) (*additionalConfigs, error) {
137131
logger := log.FromContext(ctx, "method", "getDriverAdditionalConfigs")
138132

internal/utils/utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525

2626
"github.com/davecgh/go-spew/spew"
27+
corev1 "k8s.io/api/core/v1"
2728
"k8s.io/apimachinery/pkg/util/rand"
2829
)
2930

@@ -67,6 +68,11 @@ func Int64Ptr(v int64) *int64 {
6768
return &v
6869
}
6970

71+
// HostPathTypePtr returns a pointer to the HostPathType passed in.
72+
func HostPathTypePtr(v corev1.HostPathType) *corev1.HostPathType {
73+
return &v
74+
}
75+
7076
// GetObjectHash invokes Sum32 Hash function to return hash value of an unstructured Object
7177
func GetObjectHash(obj interface{}) string {
7278
hasher := fnv.New32a()

0 commit comments

Comments
 (0)