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

resourceModels supports extended resources #4307

Merged
merged 1 commit into from
Nov 24, 2023
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
36 changes: 18 additions & 18 deletions pkg/apis/cluster/mutation/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func SetDefaultClusterResourceModels(cluster *clusterapis.Cluster) {
Grade: 0,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(0, resource.DecimalSI),
Max: *resource.NewQuantity(1, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(0, resource.BinarySI),
Max: *resource.NewQuantity(4*GB, resource.BinarySI),
},
Expand All @@ -99,12 +99,12 @@ func SetDefaultClusterResourceModels(cluster *clusterapis.Cluster) {
Grade: 1,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(1, resource.DecimalSI),
Max: *resource.NewQuantity(2, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(4*GB, resource.BinarySI),
Max: *resource.NewQuantity(16*GB, resource.BinarySI),
},
Expand All @@ -114,12 +114,12 @@ func SetDefaultClusterResourceModels(cluster *clusterapis.Cluster) {
Grade: 2,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(2, resource.DecimalSI),
Max: *resource.NewQuantity(4, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(16*GB, resource.BinarySI),
Max: *resource.NewQuantity(32*GB, resource.BinarySI),
},
Expand All @@ -129,12 +129,12 @@ func SetDefaultClusterResourceModels(cluster *clusterapis.Cluster) {
Grade: 3,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(4, resource.DecimalSI),
Max: *resource.NewQuantity(8, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(32*GB, resource.BinarySI),
Max: *resource.NewQuantity(64*GB, resource.BinarySI),
},
Expand All @@ -144,12 +144,12 @@ func SetDefaultClusterResourceModels(cluster *clusterapis.Cluster) {
Grade: 4,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(8, resource.DecimalSI),
Max: *resource.NewQuantity(16, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(64*GB, resource.BinarySI),
Max: *resource.NewQuantity(128*GB, resource.BinarySI),
},
Expand All @@ -159,12 +159,12 @@ func SetDefaultClusterResourceModels(cluster *clusterapis.Cluster) {
Grade: 5,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(16, resource.DecimalSI),
Max: *resource.NewQuantity(32, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(128*GB, resource.BinarySI),
Max: *resource.NewQuantity(256*GB, resource.BinarySI),
},
Expand All @@ -174,12 +174,12 @@ func SetDefaultClusterResourceModels(cluster *clusterapis.Cluster) {
Grade: 6,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(32, resource.DecimalSI),
Max: *resource.NewQuantity(64, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(256*GB, resource.BinarySI),
Max: *resource.NewQuantity(512*GB, resource.BinarySI),
},
Expand All @@ -189,12 +189,12 @@ func SetDefaultClusterResourceModels(cluster *clusterapis.Cluster) {
Grade: 7,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(64, resource.DecimalSI),
Max: *resource.NewQuantity(128, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(512*GB, resource.BinarySI),
Max: *resource.NewQuantity(1024*GB, resource.BinarySI),
},
Expand All @@ -204,12 +204,12 @@ func SetDefaultClusterResourceModels(cluster *clusterapis.Cluster) {
Grade: 8,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(128, resource.DecimalSI),
Max: *resource.NewQuantity(math.MaxInt64, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(1024*GB, resource.BinarySI),
Max: *resource.NewQuantity(math.MaxInt64, resource.BinarySI),
},
Expand Down
52 changes: 26 additions & 26 deletions pkg/apis/cluster/mutation/mutation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestStandardizeClusterResourceModels(t *testing.T) {
Grade: 2,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(2, resource.DecimalSI),
Max: *resource.NewQuantity(math.MaxInt64, resource.DecimalSI),
},
Expand All @@ -110,7 +110,7 @@ func TestStandardizeClusterResourceModels(t *testing.T) {
Grade: 1,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(0, resource.DecimalSI),
Max: *resource.NewQuantity(2, resource.DecimalSI),
},
Expand All @@ -122,7 +122,7 @@ func TestStandardizeClusterResourceModels(t *testing.T) {
Grade: 1,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(0, resource.DecimalSI),
Max: *resource.NewQuantity(2, resource.DecimalSI),
},
Expand All @@ -132,7 +132,7 @@ func TestStandardizeClusterResourceModels(t *testing.T) {
Grade: 2,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(2, resource.DecimalSI),
Max: *resource.NewQuantity(math.MaxInt64, resource.DecimalSI),
},
Expand All @@ -146,7 +146,7 @@ func TestStandardizeClusterResourceModels(t *testing.T) {
Grade: 1,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(1, resource.DecimalSI),
Max: *resource.NewQuantity(math.MaxInt64, resource.DecimalSI),
},
Expand All @@ -158,7 +158,7 @@ func TestStandardizeClusterResourceModels(t *testing.T) {
Grade: 1,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(0, resource.DecimalSI),
Max: *resource.NewQuantity(math.MaxInt64, resource.DecimalSI),
},
Expand All @@ -172,7 +172,7 @@ func TestStandardizeClusterResourceModels(t *testing.T) {
Grade: 1,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(0, resource.DecimalSI),
Max: *resource.NewQuantity(2, resource.DecimalSI),
},
Expand All @@ -184,7 +184,7 @@ func TestStandardizeClusterResourceModels(t *testing.T) {
Grade: 1,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(0, resource.DecimalSI),
Max: *resource.NewQuantity(math.MaxInt64, resource.DecimalSI),
},
Expand Down Expand Up @@ -222,12 +222,12 @@ func TestSetDefaultClusterResourceModels(t *testing.T) {
Grade: 0,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(0, resource.DecimalSI),
Max: *resource.NewQuantity(1, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(0, resource.BinarySI),
Max: *resource.NewQuantity(4*GB, resource.BinarySI),
},
Expand All @@ -237,12 +237,12 @@ func TestSetDefaultClusterResourceModels(t *testing.T) {
Grade: 1,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(1, resource.DecimalSI),
Max: *resource.NewQuantity(2, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(4*GB, resource.BinarySI),
Max: *resource.NewQuantity(16*GB, resource.BinarySI),
},
Expand All @@ -252,12 +252,12 @@ func TestSetDefaultClusterResourceModels(t *testing.T) {
Grade: 2,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(2, resource.DecimalSI),
Max: *resource.NewQuantity(4, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(16*GB, resource.BinarySI),
Max: *resource.NewQuantity(32*GB, resource.BinarySI),
},
Expand All @@ -267,12 +267,12 @@ func TestSetDefaultClusterResourceModels(t *testing.T) {
Grade: 3,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(4, resource.DecimalSI),
Max: *resource.NewQuantity(8, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(32*GB, resource.BinarySI),
Max: *resource.NewQuantity(64*GB, resource.BinarySI),
},
Expand All @@ -282,12 +282,12 @@ func TestSetDefaultClusterResourceModels(t *testing.T) {
Grade: 4,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(8, resource.DecimalSI),
Max: *resource.NewQuantity(16, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(64*GB, resource.BinarySI),
Max: *resource.NewQuantity(128*GB, resource.BinarySI),
},
Expand All @@ -297,12 +297,12 @@ func TestSetDefaultClusterResourceModels(t *testing.T) {
Grade: 5,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(16, resource.DecimalSI),
Max: *resource.NewQuantity(32, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(128*GB, resource.BinarySI),
Max: *resource.NewQuantity(256*GB, resource.BinarySI),
},
Expand All @@ -312,12 +312,12 @@ func TestSetDefaultClusterResourceModels(t *testing.T) {
Grade: 6,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(32, resource.DecimalSI),
Max: *resource.NewQuantity(64, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(256*GB, resource.BinarySI),
Max: *resource.NewQuantity(512*GB, resource.BinarySI),
},
Expand All @@ -327,12 +327,12 @@ func TestSetDefaultClusterResourceModels(t *testing.T) {
Grade: 7,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(64, resource.DecimalSI),
Max: *resource.NewQuantity(128, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(512*GB, resource.BinarySI),
Max: *resource.NewQuantity(1024*GB, resource.BinarySI),
},
Expand All @@ -342,12 +342,12 @@ func TestSetDefaultClusterResourceModels(t *testing.T) {
Grade: 8,
Ranges: []clusterapis.ResourceModelRange{
{
Name: clusterapis.ResourceCPU,
Name: corev1.ResourceCPU,
Min: *resource.NewQuantity(128, resource.DecimalSI),
Max: *resource.NewQuantity(math.MaxInt64, resource.DecimalSI),
},
{
Name: clusterapis.ResourceMemory,
Name: corev1.ResourceMemory,
Min: *resource.NewQuantity(1024*GB, resource.BinarySI),
Max: *resource.NewQuantity(math.MaxInt64, resource.BinarySI),
},
Expand Down
22 changes: 1 addition & 21 deletions pkg/apis/cluster/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ResourceName is the name identifying various resources in a ResourceList.
chaosi-zju marked this conversation as resolved.
Show resolved Hide resolved
type ResourceName string

// Resource names must be not more than 63 characters, consisting of upper- or lower-case alphanumeric characters,
// with the -, _, and . characters allowed anywhere, except the first or last character.
// The default convention, matching that for annotations, is to use lower-case names, with dashes, rather than
// camel case, separating compound words.
// Fully-qualified resource typenames are constructed from a DNS-style subdomain, followed by a slash `/` and a name.
const (
// ResourceCPU in cores. (e,g. 500m = .5 cores)
ResourceCPU ResourceName = "cpu"
// ResourceMemory in bytes. (e,g. 500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
ResourceMemory ResourceName = "memory"
// ResourceStorage is volume size, in bytes (e,g. 5Gi = 5GiB = 5 * 1024 * 1024 * 1024)
ResourceStorage ResourceName = "storage"
// ResourceEphemeralStorage is local ephemeral storage, in bytes. (e,g. 500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
// The resource name for ResourceEphemeralStorage is alpha and it can change across releases.
ResourceEphemeralStorage ResourceName = "ephemeral-storage"
)

//revive:disable:exported

// +genclient
Expand Down Expand Up @@ -233,7 +213,7 @@ type ResourceModel struct {
type ResourceModelRange struct {
// Name is the name for the resource that you want to categorize.
// +required
Name ResourceName
Name corev1.ResourceName
chaosi-zju marked this conversation as resolved.
Show resolved Hide resolved

// Min is the minimum amount of this resource represented by resource name.
// Note: The Min value of first grade(usually 0) always acts as zero.
Expand Down
Loading
Loading