Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for GPU resources #1701

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions config/crds/troubleshoot.sh_analyzers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,10 @@ spec:
type: string
ephemeralStorageCapacity:
type: string
gpuAllocatable:
type: string
gpuCapacity:
type: string
memoryAllocatable:
type: string
memoryCapacity:
Expand Down
4 changes: 4 additions & 0 deletions config/crds/troubleshoot.sh_preflights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,10 @@ spec:
type: string
ephemeralStorageCapacity:
type: string
gpuAllocatable:
type: string
gpuCapacity:
type: string
memoryAllocatable:
type: string
memoryCapacity:
Expand Down
4 changes: 4 additions & 0 deletions config/crds/troubleshoot.sh_supportbundles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,10 @@ spec:
type: string
ephemeralStorageCapacity:
type: string
gpuAllocatable:
type: string
gpuCapacity:
type: string
memoryAllocatable:
type: string
memoryCapacity:
Expand Down
27 changes: 27 additions & 0 deletions pkg/analyze/node_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/replicatedhq/troubleshoot/pkg/constants"
)

const gpuResourceName = "nvidia.com/gpu"

type AnalyzeNodeResources struct {
analyzer *troubleshootv1beta2.NodeResources
}
Expand Down Expand Up @@ -329,6 +331,10 @@ func getQuantity(node corev1.Node, property string) *resource.Quantity {
return node.Status.Capacity.StorageEphemeral()
case "ephemeralStorageAllocatable":
return node.Status.Allocatable.StorageEphemeral()
case "gpuCapacity":
return node.Status.Capacity.Name(gpuResourceName, resource.DecimalSI)
case "gpuAllocatable":
return node.Status.Allocatable.Name(gpuResourceName, resource.DecimalSI)
}
return nil
}
Expand Down Expand Up @@ -492,5 +498,26 @@ func nodeMatchesFilters(node corev1.Node, filters *troubleshootv1beta2.NodeResou
}
}

if filters.GPUCapacity != "" {
parsed, err := resource.ParseQuantity(filters.GPUCapacity)
if err != nil {
return false, errors.Wrap(err, "failed to parse gpu capacity")
}

if node.Status.Capacity.Name(gpuResourceName, resource.DecimalSI).Cmp(parsed) == -1 {
return false, nil
}
}
if filters.GPUAllocatable != "" {
parsed, err := resource.ParseQuantity(filters.GPUAllocatable)
if err != nil {
return false, errors.Wrap(err, "failed to parse gpu allocatable")
}

if node.Status.Allocatable.Name(gpuResourceName, resource.DecimalSI).Cmp(parsed) == -1 {
return false, nil
}
}

return true, nil
}
104 changes: 102 additions & 2 deletions pkg/analyze/node_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func Test_compareNodeResourceConditionalToActual(t *testing.T) {
nodeData := []corev1.Node{
corev1.Node{
{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Node",
Expand All @@ -28,16 +28,18 @@ func Test_compareNodeResourceConditionalToActual(t *testing.T) {
"ephemeral-storage": resource.MustParse("20959212Ki"),
"memory": resource.MustParse("3999Ki"),
"pods": resource.MustParse("15"),
gpuResourceName: resource.MustParse("4"),
},
Allocatable: corev1.ResourceList{
"cpu": resource.MustParse("1.5"),
"ephemeral-storage": resource.MustParse("19316009748"),
"memory": resource.MustParse("16Ki"),
"pods": resource.MustParse("14"),
gpuResourceName: resource.MustParse("4"),
},
},
},
corev1.Node{
{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Node",
Expand Down Expand Up @@ -366,6 +368,70 @@ func Test_compareNodeResourceConditionalToActual(t *testing.T) {
expected: false,
isError: true,
},
{
name: "sum(gpuCapacity) > 1 (true)",
conditional: "sum(gpuCapacity) > 1",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: true,
isError: false,
},
{
name: "sum(gpuCapacity) >= 8 (false)",
conditional: "sum(gpuCapacity) >= 8",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: false,
isError: false,
},
{
name: "min(gpuCapacity) > 1 (false)",
conditional: "min(gpuCapacity) > 1",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: false,
isError: false,
},
{
name: "min(gpuAllocatable) > 1 (false)",
conditional: "min(gpuAllocatable) > 1",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: false,
isError: false,
},
{
name: "max(gpuCapacity) == 4 (true)",
conditional: "max(gpuCapacity) == 4",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: true,
isError: false,
},
{
name: "max(gpuAllocatable) == 4 (true)",
conditional: "max(gpuAllocatable) == 4",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: true,
isError: false,
},
{
name: "sum(gpuAllocatable) > 1 (true)",
conditional: "sum(gpuAllocatable) > 1",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: true,
isError: false,
},
{
name: "sum(gpuAllocatable) >= 8 (false)",
conditional: "sum(gpuAllocatable) >= 8",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: false,
isError: false,
},
}

for _, test := range tests {
Expand Down Expand Up @@ -404,6 +470,7 @@ func Test_nodeMatchesFilters(t *testing.T) {
"hugepages-2Mi": resource.MustParse("0"),
"memory": resource.MustParse("7951376Ki"),
"pods": resource.MustParse("29"),
gpuResourceName: resource.MustParse("1"),
},
Allocatable: corev1.ResourceList{
"attachable-volumes-aws-ebs": resource.MustParse("25"),
Expand All @@ -413,6 +480,7 @@ func Test_nodeMatchesFilters(t *testing.T) {
"hugepages-2Mi": resource.MustParse("0"),
"memory": resource.MustParse("7848976Ki"),
"pods": resource.MustParse("29"),
gpuResourceName: resource.MustParse("1"),
},
},
}
Expand Down Expand Up @@ -626,6 +694,38 @@ func Test_nodeMatchesFilters(t *testing.T) {
},
expectResult: false,
},
{
name: "true when gpu capacity is available",
node: node,
filters: &troubleshootv1beta2.NodeResourceFilters{
GPUCapacity: "1",
},
expectResult: true,
},
{
name: "true when allocatable gpu is available",
node: node,
filters: &troubleshootv1beta2.NodeResourceFilters{
GPUAllocatable: "1",
},
expectResult: true,
},
{
name: "false when gpu capacity is not available",
node: node,
filters: &troubleshootv1beta2.NodeResourceFilters{
GPUCapacity: "2",
},
expectResult: false,
},
{
name: "false when allocatable gpu is not available",
node: node,
filters: &troubleshootv1beta2.NodeResourceFilters{
GPUAllocatable: "2",
},
expectResult: false,
},
}

for _, test := range tests {
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/troubleshoot/v1beta2/analyzer_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ type NodeResourceFilters struct {
PodAllocatable string `json:"podAllocatable,omitempty" yaml:"podAllocatable,omitempty"`
EphemeralStorageCapacity string `json:"ephemeralStorageCapacity,omitempty" yaml:"ephemeralStorageCapacity,omitempty"`
EphemeralStorageAllocatable string `json:"ephemeralStorageAllocatable,omitempty" yaml:"ephemeralStorageAllocatable,omitempty"`
GPUCapacity string `json:"gpuCapacity,omitempty" yaml:"gpuCapacity,omitempty"`
GPUAllocatable string `json:"gpuAllocatable,omitempty" yaml:"gpuAllocatable,omitempty"`
Selector *NodeResourceSelectors `json:"selector,omitempty" yaml:"selector,omitempty"`
}

Expand Down
6 changes: 6 additions & 0 deletions schemas/analyzer-troubleshoot-v1beta2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,12 @@
"ephemeralStorageCapacity": {
"type": "string"
},
"gpuAllocatable": {
"type": "string"
},
"gpuCapacity": {
"type": "string"
},
"memoryAllocatable": {
"type": "string"
},
Expand Down
6 changes: 6 additions & 0 deletions schemas/preflight-troubleshoot-v1beta2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,12 @@
"ephemeralStorageCapacity": {
"type": "string"
},
"gpuAllocatable": {
"type": "string"
},
"gpuCapacity": {
"type": "string"
},
"memoryAllocatable": {
"type": "string"
},
Expand Down
6 changes: 6 additions & 0 deletions schemas/supportbundle-troubleshoot-v1beta2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,12 @@
"ephemeralStorageCapacity": {
"type": "string"
},
"gpuAllocatable": {
"type": "string"
},
"gpuCapacity": {
"type": "string"
},
"memoryAllocatable": {
"type": "string"
},
Expand Down
Loading