Skip to content

Commit b1acf5e

Browse files
committed
Add CapacityQuota API
1 parent a5fcba5 commit b1acf5e

File tree

46 files changed

+2554
-163
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

+2554
-163
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: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
corev1 "k8s.io/api/core/v1"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
)
26+
27+
// CapacityQuotaSpec defines the desired state of CapacityQuota
28+
type CapacityQuotaSpec struct {
29+
// Selector is a label selector selecting the nodes to which the quota applies.
30+
// +optional
31+
Selector metav1.LabelSelector `json:"selector,omitempty"`
32+
33+
// Limits define quota limits.
34+
// +required
35+
Limits CapacityQuotaLimits `json:"limits"`
36+
}
37+
38+
// CapacityQuotaStatus defines the observed state of CapacityQuota.
39+
type CapacityQuotaStatus struct {
40+
// TODO: status should report resources currently in use
41+
}
42+
43+
// +kubebuilder:object:root=true
44+
// +kubebuilder:subresource:status
45+
// +kubebuilder:resource:scope=Cluster
46+
// +genclient
47+
48+
// CapacityQuota limits the amount of resources that can be provisioned in the cluster
49+
// by the node autoscaler. Resources used are calculated by summing up resources
50+
// reported in the status.capacity field of each node passing the configured
51+
// label selector. When making a provisioning decision, node autoscaler will
52+
// take all CapacityQuota objects that match the labels of the upcoming node.
53+
// If provisioning that node would exceed any of the matching quotas, node
54+
// autoscaler will not provision it. Quotas are best-effort, and it is possible
55+
// that in rare circumstances node autoscaler will exceed them, for example
56+
// due to stale caches.
57+
// More info: https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/proposals/granular-resource-limits.md
58+
type CapacityQuota struct {
59+
metav1.TypeMeta `json:",inline"`
60+
61+
// metadata is a standard object metadata
62+
// +optional
63+
metav1.ObjectMeta `json:"metadata,omitempty,omitzero"`
64+
65+
// spec defines the desired state of CapacityQuota
66+
// +required
67+
Spec CapacityQuotaSpec `json:"spec"`
68+
69+
// status defines the observed state of CapacityQuota
70+
// +optional
71+
Status CapacityQuotaStatus `json:"status,omitempty,omitzero"`
72+
}
73+
74+
type CapacityQuotaLimits struct {
75+
// Resources define resource limits of this quota.
76+
//
77+
// Currently supported built-in resources: cpu, memory. Additionally,
78+
// nodes key can be used to limit the number of existing nodes.
79+
// Node autoscaler implementations and cloud providers can support custom
80+
// resources, such as GPU.
81+
// +required
82+
Resources corev1.ResourceList `json:"resources"`
83+
}
84+
85+
// +kubebuilder:object:root=true
86+
87+
// CapacityQuotaList contains a list of CapacityQuota
88+
type CapacityQuotaList struct {
89+
metav1.TypeMeta `json:",inline"`
90+
metav1.ListMeta `json:"metadata,omitempty"`
91+
Items []CapacityQuota `json:"items"`
92+
}
93+
94+
func init() {
95+
SchemeBuilder.Register(&CapacityQuota{}, &CapacityQuotaList{})
96+
}
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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
)

0 commit comments

Comments
 (0)