Skip to content

Commit 29513ca

Browse files
committed
Add CapacityQuota API
1 parent a5fcba5 commit 29513ca

File tree

46 files changed

+2603
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2603
-162
lines changed

cluster-autoscaler/Makefile

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,3 @@ test-in-docker: clean docker-builder
139139
docker run ${RM_FLAG} -v `pwd`:/cluster-autoscaler/:Z autoscaling-builder:latest bash -c 'cd /cluster-autoscaler && go test -race ./... -vet="${GO_TEST_DEFAULT_ANALYZERS}" ${TAGS_FLAG}'
140140

141141
.PHONY: all build test-unit clean format execute-release dev-release docker-builder build-in-docker release generate push-image push-manifest
142-
143-
## Location to install dependencies to
144-
LOCALBIN ?= $(shell pwd)/bin
145-
$(LOCALBIN):
146-
mkdir -p $(LOCALBIN)
147-
148-
## Tool Binaries
149-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
150-
151-
## Tool Versions
152-
CONTROLLER_TOOLS_VERSION ?= v0.14.0
153-
154-
.PHONY: controller-gen
155-
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
156-
$(CONTROLLER_GEN): $(LOCALBIN)
157-
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
158-
159-
.PHONY: manifest
160-
manifest: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
161-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./apis/..." output:crd:artifacts:config=apis/config/crd

cluster-autoscaler/apis/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
REPO_ROOT = $(shell git rev-parse --show-toplevel)
2+
3+
## Tool Binaries
4+
CONTROLLER_GEN = go tool sigs.k8s.io/controller-tools/cmd/controller-gen
5+
6+
.PHONY: manifests
7+
manifests: ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
8+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=./config/crd
9+
10+
.PHONY: generate
11+
generate:
12+
$(CONTROLLER_GEN) object:headerFile="$(REPO_ROOT)/hack/boilerplate/boilerplate.generatego.txt" paths="./..."
13+
14+
.PHONY: clients
15+
clients:
16+
./hack/update-codegen.sh
17+
18+
.PHONY: all
19+
all: manifests generate clients

cluster-autoscaler/apis/capacitybuffer/autoscaling.x-k8s.io/v1alpha1/zz_generated.deepcopy.go

Lines changed: 4 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +groupName=autoscaling.x-k8s.io
18+
// +k8s:protobuf-gen=package
19+
20+
package v1alpha1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/api/resource"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
)
26+
27+
// ResourceName is the name identifying a resource mirroring k8s.io/api/core/v1.ResourceName.
28+
type ResourceName string
29+
30+
const (
31+
// ResourceCPU - CPU, in cores. (500m = .5 cores)
32+
ResourceCPU ResourceName = "cpu"
33+
// ResourceMemory - memory in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
34+
ResourceMemory ResourceName = "memory"
35+
// ResourceNodes - number of nodes, in units.
36+
ResourceNodes ResourceName = "nodes"
37+
)
38+
39+
// ResourceList is a set of (resource name, quantity) pairs.
40+
type ResourceList map[ResourceName]resource.Quantity
41+
42+
// CapacityQuotaSpec defines the desired state of CapacityQuota
43+
type CapacityQuotaSpec struct {
44+
// Selector is a label selector selecting the nodes to which the quota applies.
45+
// Empty or nil selector matches all nodes.
46+
// +optional
47+
Selector *metav1.LabelSelector `json:"selector,omitempty"`
48+
49+
// Limits define quota limits.
50+
// +required
51+
Limits CapacityQuotaLimits `json:"limits"`
52+
}
53+
54+
// CapacityQuotaStatus defines the observed state of CapacityQuota.
55+
type CapacityQuotaStatus struct {
56+
// TODO: status should report resources currently in use
57+
}
58+
59+
// +kubebuilder:object:root=true
60+
// +kubebuilder:subresource:status
61+
// +kubebuilder:resource:scope=Cluster,shortName=cq
62+
// +genclient
63+
64+
// CapacityQuota limits the amount of resources that can be provisioned in the cluster
65+
// by the node autoscaler. Resources used are calculated by summing up resources
66+
// reported in the status.capacity field of each node passing the configured
67+
// label selector. When making a provisioning decision, node autoscaler will
68+
// take all CapacityQuota objects that match the labels of the upcoming node.
69+
// If provisioning that node would exceed any of the matching quotas, node
70+
// autoscaler will not provision it. Quotas are best-effort, and it is possible
71+
// that in rare circumstances node autoscaler will exceed them, for example
72+
// due to stale caches.
73+
// More info: https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/proposals/granular-resource-limits.md
74+
type CapacityQuota struct {
75+
metav1.TypeMeta `json:",inline"`
76+
77+
// metadata is a standard object metadata
78+
// +optional
79+
metav1.ObjectMeta `json:"metadata,omitempty,omitzero"`
80+
81+
// spec defines the desired state of CapacityQuota
82+
// +required
83+
Spec CapacityQuotaSpec `json:"spec"`
84+
85+
// status defines the observed state of CapacityQuota
86+
// +optional
87+
Status CapacityQuotaStatus `json:"status,omitempty,omitzero"`
88+
}
89+
90+
// CapacityQuotaLimits define quota limits.
91+
type CapacityQuotaLimits struct {
92+
// Resources define resource limits of this quota.
93+
//
94+
// Currently supported built-in resources: cpu, memory. Additionally,
95+
// nodes key can be used to limit the number of existing nodes.
96+
// Node autoscaler implementations and cloud providers can support custom
97+
// resources, such as GPU.
98+
// +required
99+
Resources ResourceList `json:"resources"`
100+
}
101+
102+
// +kubebuilder:object:root=true
103+
104+
// CapacityQuotaList contains a list of CapacityQuota
105+
type CapacityQuotaList struct {
106+
metav1.TypeMeta `json:",inline"`
107+
metav1.ListMeta `json:"metadata,omitempty"`
108+
Items []CapacityQuota `json:"items"`
109+
}
110+
111+
func init() {
112+
SchemeBuilder.Register(&CapacityQuota{}, &CapacityQuotaList{})
113+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1alpha1 contains API Schema definitions for the v1alpha1 API group.
18+
package v1alpha1
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +groupName=autoscaling.x-k8s.io
18+
// +k8s:openapi-gen=true
19+
// +k8s:protobuf-gen=package
20+
// +k8s:prerelease-lifecycle-gen=true
21+
// +kubebuilder:object:generate=true
22+
23+
package v1alpha1
24+
25+
import (
26+
"k8s.io/apimachinery/pkg/runtime/schema"
27+
"sigs.k8s.io/controller-runtime/pkg/scheme"
28+
)
29+
30+
var (
31+
// GroupVersion is group version used to register these objects.
32+
GroupVersion = schema.GroupVersion{Group: "autoscaling.x-k8s.io", Version: "v1alpha1"}
33+
34+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
35+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
36+
37+
// AddToScheme adds the types in this group-version to the given scheme.
38+
AddToScheme = SchemeBuilder.AddToScheme
39+
)
40+
41+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
42+
func Resource(resource string) schema.GroupResource {
43+
return GroupVersion.WithResource(resource).GroupResource()
44+
}

0 commit comments

Comments
 (0)