Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions cluster-autoscaler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,3 @@ test-in-docker: clean docker-builder
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}'

.PHONY: all build test-unit clean format execute-release dev-release docker-builder build-in-docker release generate push-image push-manifest

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen

## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.14.0

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: manifest
manifest: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./apis/..." output:crd:artifacts:config=apis/config/crd
19 changes: 19 additions & 0 deletions cluster-autoscaler/apis/Makefile
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

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

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"
Copy link
Contributor

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.

// 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{})
}
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
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()
}
Loading