Skip to content

Commit

Permalink
Add resource field to computeclass
Browse files Browse the repository at this point in the history
Enabling admins to create computeclass with GPU and accelarators in general.

Signed-off-by: dciangot <[email protected]>
  • Loading branch information
dciangot committed Dec 20, 2023
1 parent 17a4108 commit db08e8b
Show file tree
Hide file tree
Showing 13 changed files with 609 additions and 14 deletions.
39 changes: 39 additions & 0 deletions integration/client/computeclass/computeclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
adminv1 "github.com/acorn-io/runtime/pkg/apis/internal.admin.acorn.io/v1"
"github.com/acorn-io/runtime/pkg/client"
kclient "github.com/acorn-io/runtime/pkg/k8sclient"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -28,6 +30,7 @@ func TestCreatingComputeClasses(t *testing.T) {
checks := []struct {
name string
memory adminv1.ComputeClassMemory
resources corev1.ResourceRequirements
cpuScaler float64
priorityClassName string
runtimeClassName string
Expand All @@ -40,6 +43,21 @@ func TestCreatingComputeClasses(t *testing.T) {
},
fail: false,
},
{
name: "valid-custom-resources",
memory: adminv1.ComputeClassMemory{
Max: "512Mi",
},
resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
"mygpu/nvidia": resource.MustParse("1"),
},
Requests: corev1.ResourceList{
"mygpu/nvidia": resource.MustParse("1"),
},
},
fail: false,
},
{
name: "valid-only-min",
memory: adminv1.ComputeClassMemory{
Expand Down Expand Up @@ -144,6 +162,26 @@ func TestCreatingComputeClasses(t *testing.T) {
},
fail: true,
},
// // Raise error to avoid conflicts with
// // the "first class" fields for memory and cpu scaling
// {
// name: "invalid-custom-resources-limits",
// resources: corev1.ResourceRequirements{
// Limits: corev1.ResourceList{
// "cpu": resource.MustParse("1"),
// },
// },
// fail: true,
// },
// {
// name: "invalid-custom-resources-requests",
// resources: corev1.ResourceRequirements{
// Requests: corev1.ResourceList{
// "memory": resource.MustParse("1"),
// },
// },
// fail: true,
// },
}

for _, tt := range checks {
Expand All @@ -156,6 +194,7 @@ func TestCreatingComputeClasses(t *testing.T) {
},
CPUScaler: tt.cpuScaler,
Memory: tt.memory,
Resources: &tt.resources,
PriorityClassName: tt.priorityClassName,
RuntimeClassName: tt.runtimeClassName,
}
Expand Down
11 changes: 10 additions & 1 deletion integration/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,15 +966,24 @@ func TestUsingComputeClasses(t *testing.T) {
Min: "512Mi",
Max: "1Gi",
},
Resources: &corev1.ResourceRequirements{
Limits: corev1.ResourceList{
"mygpu/nvidia": resource.MustParse("1"),
}, Requests: corev1.ResourceList{
"mygpu/nvidia": resource.MustParse("1"),
}},
SupportedRegions: []string{apiv1.LocalRegion},
},
expected: map[string]v1.Scheduling{"simple": {
Requirements: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("1Gi")},
corev1.ResourceMemory: resource.MustParse("1Gi"),
"mygpu/nvidia": resource.MustParse("1"),
},
Requests: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("1Gi"),
corev1.ResourceCPU: resource.MustParse("250m"),
"mygpu/nvidia": resource.MustParse("1"),
},
},
Tolerations: []corev1.Toleration{
Expand Down
10 changes: 6 additions & 4 deletions pkg/apis/api.acorn.io/v1/computeclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1

import (
v1 "github.com/acorn-io/runtime/pkg/apis/internal.admin.acorn.io/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -11,10 +12,11 @@ type ComputeClass struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

Memory v1.ComputeClassMemory `json:"memory,omitempty"`
Description string `json:"description,omitempty"`
Default bool `json:"default"`
SupportedRegions []string `json:"supportedRegions,omitempty"`
Memory v1.ComputeClassMemory `json:"memory,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
Description string `json:"description,omitempty"`
Default bool `json:"default"`
SupportedRegions []string `json:"supportedRegions,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
19 changes: 10 additions & 9 deletions pkg/apis/internal.admin.acorn.io/v1/computeclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ type ClusterComputeClassInstanceList struct {
type ProjectComputeClassInstance struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Description string `json:"description,omitempty"`
CPUScaler float64 `json:"cpuScaler,omitempty"`
Default bool `json:"default"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
Memory ComputeClassMemory `json:"memory,omitempty"`
SupportedRegions []string `json:"supportedRegions,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
RuntimeClassName string `json:"runtimeClassName,omitempty"`
Description string `json:"description,omitempty"`
CPUScaler float64 `json:"cpuScaler,omitempty"`
Default bool `json:"default"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
Memory ComputeClassMemory `json:"memory,omitempty"`
SupportedRegions []string `json:"supportedRegions,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
RuntimeClassName string `json:"runtimeClassName,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/appdefinition/computeclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ func TestAllSetComputeClass(t *testing.T) {
func TestAllSetOverwriteComputeClass(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/computeclass/all-set-overwrite-computeclass", DeploySpec)
}

func TestGenericResourcesComputeClass(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/computeclass/generic-resources", DeploySpec)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
kind: ClusterComputeClassInstance
apiVersion: internal.admin.acorn.io/v1
metadata:
name: sample-compute-class
description: Simple description for a simple ComputeClass
cpuScaler: 0.25
memory:
min: 1Mi
max: 2Mi
default: 1Mi
resources:
limits:
gpu-vendor.example/example-limit: 1
requests:
gpu-vendor.example/example-request: 1
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: foo
operator: In
values:
- bar
Loading

0 comments on commit db08e8b

Please sign in to comment.