Skip to content

Commit

Permalink
Add cluster resource modeling api
Browse files Browse the repository at this point in the history
  • Loading branch information
halfrost committed Aug 16, 2022
1 parent 4224d90 commit d6fc8e0
Show file tree
Hide file tree
Showing 17 changed files with 736 additions and 37 deletions.
71 changes: 71 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -14054,6 +14054,22 @@
}
}
},
"com.github.karmada-io.karmada.pkg.apis.cluster.v1alpha1.AllocatableModelingItem": {
"description": "AllocatableModelingItem represents the number of this resources modeling in a cluster that are available for scheduling.",
"type": "object",
"properties": {
"count": {
"description": "Count is the number of nodes that own the resources delineated by this modeling.",
"type": "integer",
"format": "int32"
},
"grade": {
"description": "Grade is the index of ResourceModel.",
"type": "integer",
"format": "int32"
}
}
},
"com.github.karmada-io.karmada.pkg.apis.cluster.v1alpha1.Cluster": {
"description": "Cluster represents the desire state and status of a member cluster.",
"type": "object",
Expand Down Expand Up @@ -14171,6 +14187,14 @@
"description": "Region represents the region of the member cluster locate in.",
"type": "string"
},
"resourceModels": {
"description": "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 \u003e= 0 Each default model's memory quota is also (2^index-1, 2^index], index \u003e= 0, for example, model0 is like this: - index: 0 ranges:\n - name: CPU\n min: 0 C\n max: 1 C\n - name: memory\n min: 0 GB\n max: 1 GB\nmodel10 is like this: - index: 10 range:\n - name: CPU\n min: 512 C\n max: 1024 C\n - name: memory\n min: 512 GB\n max: 1024 GB\nmodel11 is like this: - index: 11 range:\n - name: CPU\n min: 1024 C\n max: MAXINT\n - name: memory\n min: 1024 GB\n max: MAXINT",
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.cluster.v1alpha1.ResourceModel"
}
},
"secretRef": {
"description": "SecretRef represents the secret contains mandatory credentials to access the member cluster. The secret should hold credentials as follows: - secret.data.token - secret.data.caBundle",
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.cluster.v1alpha1.LocalSecretReference"
Expand Down Expand Up @@ -14264,6 +14288,45 @@
}
}
},
"com.github.karmada-io.karmada.pkg.apis.cluster.v1alpha1.ResourceModel": {
"description": "ResourceModel describes the modeling that you want to statistics.",
"type": "object",
"properties": {
"grade": {
"description": "Grade is the index for the resource modeling.",
"type": "integer",
"format": "int32"
},
"ranges": {
"description": "Ranges describes the resource quota ranges.",
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.cluster.v1alpha1.ResourceModelItem"
}
}
}
},
"com.github.karmada-io.karmada.pkg.apis.cluster.v1alpha1.ResourceModelItem": {
"description": "ResourceModelItem describes the detail of each modeling quota that ranges from min to max.",
"type": "object",
"properties": {
"max": {
"description": "Max is the maximum amount of this resource represented by resource name。",
"default": {},
"$ref": "#/definitions/io.k8s.apimachinery.pkg.api.resource.Quantity"
},
"min": {
"description": "Min is the minimum amount of this resource represented by resource name。",
"default": {},
"$ref": "#/definitions/io.k8s.apimachinery.pkg.api.resource.Quantity"
},
"name": {
"description": "Name is the name for the resource that you want to categorize.",
"type": "string"
}
}
},
"com.github.karmada-io.karmada.pkg.apis.cluster.v1alpha1.ResourceSummary": {
"description": "ResourceSummary represents the summary of resources in the member cluster.",
"type": "object",
Expand All @@ -14276,6 +14339,14 @@
"$ref": "#/definitions/io.k8s.apimachinery.pkg.api.resource.Quantity"
}
},
"allocatableModeling": {
"description": "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].",
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.cluster.v1alpha1.AllocatableModelingItem"
}
},
"allocated": {
"description": "Allocated represents the resources of a cluster that have been scheduled. Total amount of required resources of all Pods that have been scheduled to nodes.",
"type": "object",
Expand Down
103 changes: 103 additions & 0 deletions pkg/apis/cluster/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,33 @@ package cluster

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

// ResourceName is the name identifying various resources in a ResourceList.
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 (
// CPU, in cores. (500m = .5 cores)
ResourceCPU ResourceName = "cpu"
// Memory, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
ResourceMemory ResourceName = "memory"
// Volume size, in bytes (e,g. 5Gi = 5GiB = 5 * 1024 * 1024 * 1024)
ResourceStorage ResourceName = "storage"
// Local ephemeral storage, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
// The resource name for ResourceEphemeralStorage is alpha and it can change across releases.
ResourceEphemeralStorage ResourceName = "ephemeral-storage"
)

// ResourceList is a set of (resource name, quantity) pairs.
type ResourceList map[ResourceName]resource.Quantity

//revive:disable:exported

// +genclient
Expand Down Expand Up @@ -104,6 +128,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 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 +300,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
105 changes: 105 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 All @@ -16,6 +17,29 @@ const (
ResourceNamespaceScopedCluster = false
)

// ResourceName is the name identifying various resources in a ResourceList.
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 (
// CPU, in cores. (e,g. 500m = .5 cores)
ResourceCPU ResourceName = "cpu"
// Memory, in bytes. (e,g. 500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
ResourceMemory ResourceName = "memory"
// Volume size, in bytes (e,g. 5Gi = 5GiB = 5 * 1024 * 1024 * 1024)
ResourceStorage ResourceName = "storage"
// 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"
)

// ResourceList is a set of (resource name, quantity) pairs.
type ResourceList map[ResourceName]resource.Quantity

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -116,6 +140,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 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 Expand Up @@ -215,14 +299,35 @@ type ResourceSummary struct {
// Total amount of allocatable resources on all nodes.
// +optional
Allocatable corev1.ResourceList `json:"allocatable,omitempty"`

// Allocating represents the resources of a cluster that are pending for scheduling.
// Total amount of required resources of all Pods that are waiting for scheduling.
// +optional
Allocating corev1.ResourceList `json:"allocating,omitempty"`

// Allocated represents the resources of a cluster that have been scheduled.
// Total amount of required resources of all Pods that have been scheduled to nodes.
// +optional
Allocated corev1.ResourceList `json:"allocated,omitempty"`

// 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 `json:"allocatableModeling,omitempty"`
}

// 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 `json:"grade,omitempty"`

// Count is the number of nodes that own the resources delineated by this modeling.
// +optional
Count int `json:"count,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
Loading

0 comments on commit d6fc8e0

Please sign in to comment.