Skip to content

Commit

Permalink
Add cluster resource modeling api
Browse files Browse the repository at this point in the history
Signed-off-by: halfrost <ydz627@gmail.com>
  • Loading branch information
halfrost committed Aug 16, 2022
1 parent 4224d90 commit 570956b
Show file tree
Hide file tree
Showing 14 changed files with 471 additions and 120 deletions.
80 changes: 80 additions & 0 deletions pkg/apis/cluster/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cluster

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -104,6 +105,66 @@ type ClusterSpec struct {
// any resource that does not tolerate the Taint.
// +optional
Taints []corev1.Taint

// ResourceModels is the list of resource modeling in this cluster. Each modeling quota can be customized by the user.
// Modeling name must be one of the following: cpu, memory, storage, ephemeral-storage.
// If the user does not define the modeling name and modeling quota, it will be the default model.
// The default model index from 0 to 11. Each default model's cpu quota is (2^index-1, 2^index], index >= 0
// Each default model's memory quota is also (2^index-1, 2^index], index >= 0, for example, model0 is like this:
// - index: 0
// ranges:
// - name: CPU
// min: 0 C
// max: 1 C
// - name: memory
// min: 0 GB
// max: 1 GB
// model10 is like this:
// - index: 10
// range:
// - name: CPU
// min: 512 C
// max: 1024 C
// - name: memory
// min: 512 GB
// max: 1024 GB
// model11 is like this:
// - index: 11
// range:
// - name: CPU
// min: 1024 C
// max: MAXINT
// - name: memory
// min: 1024 GB
// max: MAXINT
// +optional
ResourceModels []ResourceModel
}

// ResourceModel describes the modeling that you want to statistics.
type ResourceModel struct {
// Grade is the index for the resource modeling.
// +optional
Grade int

// Ranges describes the resource quota ranges.
// +optional
Ranges []ResourceModelItem
}

// ResourceModelItem describes the detail of each modeling quota that ranges from min to max.
type ResourceModelItem struct {
// Name is the name for the resource that you want to categorize.
// +optional
Name corev1.ResourceName

// Min is the minimum amount of this resource represented by resource name。
// +optional
Min resource.Quantity

// Max is the maximum amount of this resource represented by resource name。
// +optional
Max resource.Quantity
}

const (
Expand Down Expand Up @@ -216,6 +277,25 @@ type ResourceSummary struct {
// Total amount of required resources of all Pods that have been scheduled to nodes.
// +optional
Allocated corev1.ResourceList

// AllocatableModeling represents the number of each resources modeling in a cluster that are available for scheduling.
// Total amount of allocatable resources on all nodes.
// The Grade of AllocatableModelingItem is the index of ResourceModel,
// The Count of AllocatableModelingItem is the number of nodes that own the resources delineated by this modeling.
// For example, AllocatableModelingItem{Grade: 2, Count: 10}, which means there are 10 such resource models of ResourceModel[2].
// +optional
AllocatableModeling []AllocatableModelingItem
}

// AllocatableModelingItem represents the number of this resources modeling in a cluster that are available for scheduling.
type AllocatableModelingItem struct {
// Grade is the index of ResourceModel.
// +optional
Grade int

// Count is the number of nodes that own the resources delineated by this modeling.
// +optional
Count int
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
61 changes: 61 additions & 0 deletions pkg/apis/cluster/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -116,6 +117,66 @@ type ClusterSpec struct {
// any resource that does not tolerate the Taint.
// +optional
Taints []corev1.Taint `json:"taints,omitempty"`

// ResourceModels is the list of resource modeling in this cluster. Each modeling quota can be customized by the user.
// Modeling name must be one of the following: cpu, memory, storage, ephemeral-storage.
// If the user does not define the modeling name and modeling quota, it will be the default model.
// The default model index from 0 to 11. Each default model's cpu quota is (2^index-1, 2^index], index >= 0
// Each default model's memory quota is also (2^index-1, 2^index], index >= 0, for example, model0 is like this:
// - index: 0
// ranges:
// - name: CPU
// min: 0 C
// max: 1 C
// - name: memory
// min: 0 GB
// max: 1 GB
// model10 is like this:
// - index: 10
// range:
// - name: CPU
// min: 512 C
// max: 1024 C
// - name: memory
// min: 512 GB
// max: 1024 GB
// model11 is like this:
// - index: 11
// range:
// - name: CPU
// min: 1024 C
// max: MAXINT
// - name: memory
// min: 1024 GB
// max: MAXINT
// +optional
ResourceModels []ResourceModel `json:"resourceModels,omitempty"`
}

// ResourceModel describes the modeling that you want to statistics.
type ResourceModel struct {
// Grade is the index for the resource modeling.
// +optional
Grade int `json:"grade,omitempty"`

// Ranges describes the resource quota ranges.
// +optional
Ranges []ResourceModelItem `json:"ranges,omitempty"`
}

// ResourceModelItem describes the detail of each modeling quota that ranges from min to max.
type ResourceModelItem struct {
// Name is the name for the resource that you want to categorize.
// +optional
Name corev1.ResourceName `json:"name,omitempty"`

// Min is the minimum amount of this resource represented by resource name。
// +optional
Min resource.Quantity `json:"min,omitempty"`

// Max is the maximum amount of this resource represented by resource name。
// +optional
Max resource.Quantity `json:"max,omitempty"`
}

const (
Expand Down
118 changes: 109 additions & 9 deletions pkg/apis/cluster/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 570956b

Please sign in to comment.