-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add CapacityQuota API #8894
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
Open
norbertcyran
wants to merge
1
commit into
kubernetes:master
Choose a base branch
from
norbertcyran:capacity-quota-crd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,603
−162
Open
Add CapacityQuota API #8894
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| REPO_ROOT = $(shell git rev-parse --show-toplevel) | ||
|
|
||
| ## Tool Binaries | ||
| CONTROLLER_GEN = go tool sigs.k8s.io/controller-tools/cmd/controller-gen | ||
|
|
||
| .PHONY: manifests | ||
| manifests: ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. | ||
| $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=./config/crd | ||
|
|
||
| .PHONY: generate | ||
| generate: | ||
| $(CONTROLLER_GEN) object:headerFile="$(REPO_ROOT)/hack/boilerplate/boilerplate.generatego.txt" paths="./..." | ||
|
|
||
| .PHONY: clients | ||
| clients: | ||
| ./hack/update-codegen.sh | ||
|
|
||
| .PHONY: all | ||
| all: manifests generate clients |
16 changes: 4 additions & 12 deletions
16
...ter-autoscaler/apis/capacitybuffer/autoscaling.x-k8s.io/v1alpha1/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
cluster-autoscaler/apis/capacityquota/autoscaling.x-k8s.io/v1alpha1/capacityquota_types.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| Copyright 2025 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| // +groupName=autoscaling.x-k8s.io | ||
| // +k8s:protobuf-gen=package | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| "k8s.io/apimachinery/pkg/api/resource" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // ResourceName is the name identifying a resource mirroring k8s.io/api/core/v1.ResourceName. | ||
| type ResourceName string | ||
|
|
||
| const ( | ||
| // ResourceCPU - CPU, in cores. (500m = .5 cores) | ||
| ResourceCPU ResourceName = "cpu" | ||
| // ResourceMemory - memory in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024) | ||
| ResourceMemory ResourceName = "memory" | ||
| // ResourceNodes - number of nodes, in units. | ||
| ResourceNodes ResourceName = "nodes" | ||
| ) | ||
|
|
||
| // ResourceList is a set of (resource name, quantity) pairs. | ||
| type ResourceList map[ResourceName]resource.Quantity | ||
|
|
||
| // CapacityQuotaSpec defines the desired state of CapacityQuota | ||
| type CapacityQuotaSpec struct { | ||
| // Selector is a label selector selecting the nodes to which the quota applies. | ||
| // Empty or nil selector matches all nodes. | ||
| // +optional | ||
| Selector *metav1.LabelSelector `json:"selector,omitempty"` | ||
|
|
||
| // Limits define quota limits. | ||
| // +required | ||
| Limits CapacityQuotaLimits `json:"limits"` | ||
| } | ||
|
|
||
| // CapacityQuotaStatus defines the observed state of CapacityQuota. | ||
| type CapacityQuotaStatus struct { | ||
| // TODO: status should report resources currently in use | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
| // +kubebuilder:subresource:status | ||
| // +kubebuilder:resource:scope=Cluster,shortName=cq | ||
| // +genclient | ||
|
|
||
| // CapacityQuota limits the amount of resources that can be provisioned in the cluster | ||
| // by the node autoscaler. Resources used are calculated by summing up resources | ||
| // reported in the status.capacity field of each node passing the configured | ||
| // label selector. When making a provisioning decision, node autoscaler will | ||
| // take all CapacityQuota objects that match the labels of the upcoming node. | ||
| // If provisioning that node would exceed any of the matching quotas, node | ||
| // autoscaler will not provision it. Quotas are best-effort, and it is possible | ||
| // that in rare circumstances node autoscaler will exceed them, for example | ||
| // due to stale caches. | ||
| // More info: https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/proposals/granular-resource-limits.md | ||
| type CapacityQuota struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
|
|
||
| // metadata is a standard object metadata | ||
| // +optional | ||
| metav1.ObjectMeta `json:"metadata,omitempty,omitzero"` | ||
|
|
||
| // spec defines the desired state of CapacityQuota | ||
| // +required | ||
| Spec CapacityQuotaSpec `json:"spec"` | ||
|
|
||
| // status defines the observed state of CapacityQuota | ||
| // +optional | ||
| Status CapacityQuotaStatus `json:"status,omitempty,omitzero"` | ||
| } | ||
|
|
||
| // CapacityQuotaLimits define quota limits. | ||
| type CapacityQuotaLimits struct { | ||
| // Resources define resource limits of this quota. | ||
| // | ||
| // Currently supported built-in resources: cpu, memory. Additionally, | ||
| // nodes key can be used to limit the number of existing nodes. | ||
| // Node autoscaler implementations and cloud providers can support custom | ||
| // resources, such as GPU. | ||
| // +required | ||
| Resources ResourceList `json:"resources"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
| // CapacityQuotaList contains a list of CapacityQuota | ||
| type CapacityQuotaList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []CapacityQuota `json:"items"` | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&CapacityQuota{}, &CapacityQuotaList{}) | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
cluster-autoscaler/apis/capacityquota/autoscaling.x-k8s.io/v1alpha1/doc.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| Copyright 2025 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| // Package v1alpha1 contains API Schema definitions for the v1alpha1 API group. | ||
| package v1alpha1 |
44 changes: 44 additions & 0 deletions
44
cluster-autoscaler/apis/capacityquota/autoscaling.x-k8s.io/v1alpha1/groupversion_info.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| Copyright 2025 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| // +groupName=autoscaling.x-k8s.io | ||
| // +k8s:openapi-gen=true | ||
| // +k8s:protobuf-gen=package | ||
| // +k8s:prerelease-lifecycle-gen=true | ||
| // +kubebuilder:object:generate=true | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "sigs.k8s.io/controller-runtime/pkg/scheme" | ||
| ) | ||
|
|
||
| var ( | ||
| // GroupVersion is group version used to register these objects. | ||
| GroupVersion = schema.GroupVersion{Group: "autoscaling.x-k8s.io", Version: "v1alpha1"} | ||
|
|
||
| // SchemeBuilder is used to add go types to the GroupVersionKind scheme. | ||
| SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
|
||
| // AddToScheme adds the types in this group-version to the given scheme. | ||
| AddToScheme = SchemeBuilder.AddToScheme | ||
| ) | ||
|
|
||
| // Resource takes an unqualified resource and returns a Group qualified GroupResource | ||
| func Resource(resource string) schema.GroupResource { | ||
| return GroupVersion.WithResource(resource).GroupResource() | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional, some of these are already defined upstream if you wanted to point to them.