Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 3 additions & 30 deletions controllers/state_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"path/filepath"
"strconv"
"strings"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -662,42 +661,16 @@ func (n *ClusterPolicyController) getGPUNodeOSInfo() (string, string, error) {
if !ok {
return "", "", fmt.Errorf("unable to retrieve OS version from label %s", nfdOSVersionIDLabelKey)
}
osMajorVersion := strings.Split(osVersion, ".")[0]

// If the OS is RockyLinux or RHEL 10 & above, we will omit the minor version when constructing the os image tag
// If the OS is RockyLinux or RHEL, we will omit the minor version when constructing the os image tag
switch osName {
case "rocky":
osVersion = osMajorVersion
case "rhel":
osMajorNumber, err := parseOSMajorVersion(osVersion)
if err != nil {
return "", "", err
}
if osMajorNumber >= 10 {
osVersion = osMajorVersion
}
case "rocky", "rhel":
osVersion = strings.Split(osVersion, ".")[0]
}
osTag := fmt.Sprintf("%s%s", osName, osVersion)

return osName, osTag, nil
}

func parseOSMajorVersion(osVersion string) (int, error) {
osMajorVersion := strings.Split(osVersion, ".")[0]
osMajorVersion = strings.TrimSpace(osMajorVersion)
osMajorVersion = strings.TrimPrefix(strings.TrimPrefix(osMajorVersion, "v"), "V")
if osMajorVersion == "" {
return 0, fmt.Errorf("empty OS major version")
}

osMajorNumber, err := strconv.Atoi(osMajorVersion)
if err != nil {
return 0, fmt.Errorf("error processing OS major version %s: %w", osMajorVersion, err)
}

return osMajorNumber, nil
}

func (n *ClusterPolicyController) setPodSecurityLabelsForNamespace() error {
ctx := n.ctx
namespaceName := clusterPolicyCtrl.operatorNamespace
Expand Down
19 changes: 12 additions & 7 deletions controllers/state_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ func TestGetGPUNodeOSInfo(t *testing.T) {
osVersion: "v1.12.6",
expected: "talosv1.12.6",
},
{
name: "rhel 9 omits minor version",
osName: "rhel",
osVersion: "9.4",
expected: "rhel9",
},
{
name: "rhel 8 omits minor version",
osName: "rhel",
osVersion: "8.10",
expected: "rhel8",
},
{
name: "rhel 10 omits minor version",
osName: "rhel",
Expand Down Expand Up @@ -88,13 +100,6 @@ func TestGetGPUNodeOSInfo(t *testing.T) {
osVersion: "rolling",
expected: "archlinuxrolling",
},
{
name: "rhel invalid major version errors",
osName: "rhel",
osVersion: "A.10",
expectError: true,
errorContainsText: "error processing OS major version",
},
}

for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion deployments/gpu-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ driver:
usePrecompiled: false
repository: nvcr.io/nvidia
image: driver
version: "595.58.03"
version: "595.71.05"
imagePullPolicy: IfNotPresent
imagePullSecrets: []
startupProbe:
Expand Down
35 changes: 3 additions & 32 deletions internal/state/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"maps"
"strconv"
"strings"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -141,41 +140,13 @@ func getNodePools(ctx context.Context, k8sClient client.Client, selector map[str
}

func getOSTag(osRelease, osVersion string) (string, error) {
osMajorVersion := strings.Split(osVersion, ".")[0]

var osTagSuffix string
// If the OS is RockyLinux or RHEL 10 & above, we will omit the minor version when constructing the os image tag
// If the OS is RockyLinux or RHEL, we will omit the minor version when constructing the os image tag
switch osRelease {
case "rocky":
osTagSuffix = osMajorVersion
case "rhel":
osMajorNumber, err := parseOSMajorVersion(osVersion)
if err != nil {
return "", fmt.Errorf("failed to parse os version: %w", err)
}
if osMajorNumber >= 10 {
osTagSuffix = osMajorVersion
} else {
osTagSuffix = osVersion
}
case "rocky", "rhel":
osTagSuffix = strings.Split(osVersion, ".")[0]
default:
osTagSuffix = osVersion
}
return fmt.Sprintf("%s%s", osRelease, osTagSuffix), nil
}

func parseOSMajorVersion(osVersion string) (int, error) {
osMajorVersion := strings.Split(osVersion, ".")[0]
osMajorVersion = strings.TrimSpace(osMajorVersion)
osMajorVersion = strings.TrimPrefix(strings.TrimPrefix(osMajorVersion, "v"), "V")
if osMajorVersion == "" {
return 0, fmt.Errorf("empty OS major version")
}

osMajorNumber, err := strconv.Atoi(osMajorVersion)
if err != nil {
return 0, err
}

return osMajorNumber, nil
}
16 changes: 8 additions & 8 deletions internal/state/nodepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ func TestGetOSTag(t *testing.T) {
description: "valid os release & version",
osRelease: "rhel",
osVersion: "9.4",
expected: "rhel9.4",
expected: "rhel9",
expectError: false,
},
{
description: "valid os release & version - rhel8",
osRelease: "rhel",
osVersion: "8.10",
expected: "rhel8",
expectError: false,
},
{
Expand Down Expand Up @@ -73,13 +80,6 @@ func TestGetOSTag(t *testing.T) {
expected: "archlinuxrolling",
expectError: false,
},
{
description: "invalid os version",
osRelease: "rhel",
osVersion: "A.10",
expectError: true,
errorMessage: "failed to parse os version: strconv.Atoi: parsing \"A\": invalid syntax",
},
}

for _, test := range tests {
Expand Down
Loading