Skip to content
Merged
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
12 changes: 10 additions & 2 deletions api/nvidia/v1/clusterpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1
import (
"fmt"
"os"
"reflect"
"strings"

kata_v1alpha1 "github.com/NVIDIA/k8s-kata-manager/api/v1alpha1/config"
Expand Down Expand Up @@ -2087,6 +2088,14 @@ func imagePath(repository string, image string, version string, imagePathEnvName

// ImagePath sets image path for given component type
func ImagePath(spec interface{}) (string, error) {
if spec == nil {
return "", fmt.Errorf("invalid nil spec to construct image path")
}
value := reflect.ValueOf(spec)
if value.Kind() == reflect.Pointer && value.IsNil() {
return "", fmt.Errorf("invalid nil spec to construct image path: %T", spec)
}

switch v := spec.(type) {
case *DriverSpec:
config := spec.(*DriverSpec)
Expand Down Expand Up @@ -2128,8 +2137,7 @@ func ImagePath(spec interface{}) (string, error) {
config := spec.(*DriverManagerSpec)
return imagePath(config.Repository, config.Image, config.Version, "DRIVER_MANAGER_IMAGE")
case *GPUDirectStorageSpec:
config := spec.(*GPUDirectStorageSpec)
return imagePath(config.Repository, config.Image, config.Version, "GDS_IMAGE")
return imagePath(v.Repository, v.Image, v.Version, "GDS_IMAGE")
case *GDRCopySpec:
config := spec.(*GDRCopySpec)
return imagePath(config.Repository, config.Image, config.Version, "GDRCOPY_IMAGE")
Expand Down
14 changes: 14 additions & 0 deletions api/nvidia/v1/clusterpolicy_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,18 @@ func TestImagePath(t *testing.T) {
assert.Empty(t, path)
assert.ErrorContains(t, err, "invalid type to construct image path")
})

t.Run("nil spec errors", func(t *testing.T) {
path, err := ImagePath(nil)
require.Error(t, err)
assert.Empty(t, path)
assert.ErrorContains(t, err, "invalid nil spec")
})

t.Run("typed nil spec errors", func(t *testing.T) {
path, err := ImagePath((*GPUDirectStorageSpec)(nil))
require.Error(t, err)
assert.Empty(t, path)
assert.ErrorContains(t, err, "invalid nil spec")
})
}
24 changes: 13 additions & 11 deletions cmd/gpuop-cfg/validate/clusterpolicy/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,19 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}

// GPUDirectStorage
path, err = v1.ImagePath(spec.GPUDirectStorage)
if err != nil {
return fmt.Errorf("failed to construct the image path: %v", err)
}
// For GDS driver, we must append the os-tag
path += "-ubuntu22.04"

err = validateImage(ctx, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
// GPUDirectStorage is optional and nil when GDS is omitted from the ClusterPolicy.
if spec.GPUDirectStorage != nil {
path, err = v1.ImagePath(spec.GPUDirectStorage)
if err != nil {
return fmt.Errorf("failed to construct the image path: %v", err)
}
// For GDS driver, we must append the os-tag
path += "-ubuntu22.04"

err = validateImage(ctx, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}
}

// VFIOManager
Expand Down
Loading