Skip to content

Commit

Permalink
Expands regexp to also match 64k page size kernels
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Vazquez <[email protected]>
  • Loading branch information
mvazquezc committed Jan 27, 2025
1 parent f7dc6d7 commit 9ec434e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion controllers/object_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2814,7 +2814,7 @@ func transformGDRCopyContainer(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolic
// 2. ensure to meet k8s constraints for metadata.name, i.e it
// must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character
func getSanitizedKernelVersion(kernelVersion string) string {
archRegex := regexp.MustCompile("x86_64|aarch64")
archRegex := regexp.MustCompile("x86_64(?:_64k)?|aarch64(?:_64k)?")
// remove arch strings, "_" and any trailing "." from the kernel version
sanitizedVersion := strings.TrimSuffix(strings.ReplaceAll(archRegex.ReplaceAllString(kernelVersion, ""), "_", "."), ".")
return strings.ToLower(sanitizedVersion)
Expand Down
18 changes: 18 additions & 0 deletions controllers/object_controls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,3 +1065,21 @@ func TestDCGMExporter(t *testing.T) {
})
}
}

func TestGetSanitizedKernelVersion(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"5.14.0-427.37.1.el9_4.aarch64_64k", "5.14.0-427.37.1.el9.4"},
{"5.14.0-427.37.1.el9_4.aarch64", "5.14.0-427.37.1.el9.4"},
{"5.14.0-427.37.1.el9_4.x86_64_64k", "5.14.0-427.37.1.el9.4"},
{"5.14.0-427.37.1.el9_4.x86_64", "5.14.0-427.37.1.el9.4"},
}

for _, test := range tests {
result := getSanitizedKernelVersion(test.input)
require.NotEmpty(t, result)
require.Equal(t, test.expected, result)
}
}
2 changes: 1 addition & 1 deletion internal/state/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func getRuntimeSpec(ctx context.Context, k8sClient client.Client, info clusterin
// 2. ensure to meet k8s constraints for metadata.name, i.e it
// must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character
func getSanitizedKernelVersion(kernelVersion string) string {
archRegex := regexp.MustCompile("x86_64|aarch64")
archRegex := regexp.MustCompile("x86_64(?:_64k)?|aarch64(?:_64k)?")
// remove arch strings, "_" and any trailing "." from the kernel version
sanitizedVersion := strings.TrimSuffix(strings.ReplaceAll(archRegex.ReplaceAllString(kernelVersion, ""), "_", "."), ".")
return strings.ToLower(sanitizedVersion)
Expand Down
18 changes: 18 additions & 0 deletions internal/state/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,3 +770,21 @@ func TestDriverVGPULicensing(t *testing.T) {
require.Equal(t, string(o), actual)

}

func TestGetSanitizedKernelVersion(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"5.14.0-427.37.1.el9_4.aarch64_64k", "5.14.0-427.37.1.el9.4"},
{"5.14.0-427.37.1.el9_4.aarch64", "5.14.0-427.37.1.el9.4"},
{"5.14.0-427.37.1.el9_4.x86_64_64k", "5.14.0-427.37.1.el9.4"},
{"5.14.0-427.37.1.el9_4.x86_64", "5.14.0-427.37.1.el9.4"},
}

for _, test := range tests {
result := getSanitizedKernelVersion(test.input)
require.NotEmpty(t, result)
require.Equal(t, test.expected, result)
}
}

0 comments on commit 9ec434e

Please sign in to comment.