Skip to content

Commit 80f53bb

Browse files
Add overcommit spec and status (#257)
We want to reflect the overcommit ratio in the hypervisor crd. This is useful for cortex, so it can calculate how much space is left on a hypervisor. By default, it is assumed that the overcommit for each resource is set to 1. If anything else is specified, it will be reflected in the new `effectiveCapacity` status field by the kvm node agent. This will allow cortex to take control of the hypervisor overcommit ratio, for now statically, and in the future dynamically.
1 parent 05f22f6 commit 80f53bb

File tree

7 files changed

+253
-37
lines changed

7 files changed

+253
-37
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ check: FORCE static-check build/cover.html build-all
117117

118118
generate: install-controller-gen
119119
@printf "\e[1;36m>> controller-gen\e[0m\n"
120-
@controller-gen crd rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
120+
@controller-gen crd:allowDangerousTypes=true rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
121121
@controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
122122
@controller-gen applyconfiguration paths="./..."
123123

api/v1/hypervisor_types.go

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ import (
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
)
2424

25+
// ResourceName is the name identifying a hypervisor resource.
26+
// Note: this type is similar to the type defined in the kubernetes core api,
27+
// but may be extended to support additional resource types in the future.
28+
// See: https://github.com/kubernetes/api/blob/7e7aaba/core/v1/types.go#L6954-L6970
29+
type ResourceName string
30+
31+
// Resource names must be not more than 63 characters, consisting of upper- or
32+
// lower-case alphanumeric characters, with the -, _, and . characters allowed
33+
// anywhere, except the first or last character. The default convention,
34+
// matching that for annotations, is to use lower-case names, with dashes,
35+
// rather than camel case, separating compound words. Fully-qualified resource
36+
// typenames are constructed from a DNS-style subdomain, followed by a slash `/`
37+
// and a name.
38+
const (
39+
// CPU, in cores. Note that currently, it is not supported to provide
40+
// fractional cpu resources, such as 500m for 0.5 cpu.
41+
ResourceCPU ResourceName = "cpu"
42+
// Memory, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
43+
ResourceMemory ResourceName = "memory"
44+
)
45+
2546
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
2647
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
2748
// Important: Run "make" to regenerate code after modifying this file
@@ -138,6 +159,24 @@ type HypervisorSpec struct {
138159
// +kubebuilder:optional
139160
// MaintenanceReason provides the reason for manual maintenance mode.
140161
MaintenanceReason string `json:"maintenanceReason,omitempty"`
162+
163+
// Overcommit specifies the desired overcommit ratio by resource type.
164+
//
165+
// If no overcommit is specified for a resource type, the default overcommit
166+
// ratio of 1.0 should be applied, i.e. the effective capacity is the same
167+
// as the actual capacity.
168+
//
169+
// If the overcommit ratio results in a fractional effective capacity,
170+
// the effective capacity is expected to be rounded down. This allows
171+
// gradually adjusting the hypervisor capacity.
172+
//
173+
// +kubebuilder:validation:Optional
174+
//
175+
// It is validated that all overcommit ratios are greater than or equal to
176+
// 1.0, if specified. For this we don't need extra validating webhooks.
177+
// See: https://kubernetes.io/blog/2022/09/23/crd-validation-rules-beta/#crd-transition-rules
178+
// +kubebuilder:validation:XValidation:rule="self.all(k, self[k] >= 1.0)",message="overcommit ratios must be >= 1.0"
179+
Overcommit map[ResourceName]float64 `json:"overcommit,omitempty"`
141180
}
142181

143182
const (
@@ -305,11 +344,29 @@ type Cell struct {
305344

306345
// Auto-discovered resource allocation of all hosted VMs in this cell.
307346
// +kubebuilder:validation:Optional
308-
Allocation map[string]resource.Quantity `json:"allocation"`
347+
Allocation map[ResourceName]resource.Quantity `json:"allocation"`
309348

310349
// Auto-discovered capacity of this cell.
350+
//
351+
// Note that this capacity does not include the applied overcommit ratios,
352+
// and represents the actual capacity of the cell. Use the effective capacity
353+
// field to get the capacity considering the applied overcommit ratios.
354+
//
311355
// +kubebuilder:validation:Optional
312-
Capacity map[string]resource.Quantity `json:"capacity"`
356+
Capacity map[ResourceName]resource.Quantity `json:"capacity"`
357+
358+
// Auto-discovered capacity of this cell, considering the
359+
// applied overcommit ratios.
360+
//
361+
// In case no overcommit ratio is specified for a resource type, the default
362+
// overcommit ratio of 1 should be applied, meaning the effective capacity
363+
// is the same as the actual capacity.
364+
//
365+
// If the overcommit ratio results in a fractional effective capacity, the
366+
// effective capacity is expected to be rounded down.
367+
//
368+
// +kubebuilder:validation:Optional
369+
EffectiveCapacity map[ResourceName]resource.Quantity `json:"effectiveCapacity,omitempty"`
313370
}
314371

315372
// HypervisorStatus defines the observed state of Hypervisor
@@ -342,11 +399,30 @@ type HypervisorStatus struct {
342399

343400
// Auto-discovered resource allocation of all hosted VMs.
344401
// +kubebuilder:validation:Optional
345-
Allocation map[string]resource.Quantity `json:"allocation"`
402+
Allocation map[ResourceName]resource.Quantity `json:"allocation"`
346403

347404
// Auto-discovered capacity of the hypervisor.
405+
//
406+
// Note that this capacity does not include the applied overcommit ratios,
407+
// and represents the actual capacity of the hypervisor. Use the
408+
// effective capacity field to get the capacity considering the applied
409+
// overcommit ratios.
410+
//
411+
// +kubebuilder:validation:Optional
412+
Capacity map[ResourceName]resource.Quantity `json:"capacity"`
413+
414+
// Auto-discovered capacity of the hypervisor, considering the
415+
// applied overcommit ratios.
416+
//
417+
// In case no overcommit ratio is specified for a resource type, the default
418+
// overcommit ratio of 1 should be applied, meaning the effective capacity
419+
// is the same as the actual capacity.
420+
//
421+
// If the overcommit ratio results in a fractional effective capacity, the
422+
// effective capacity is expected to be rounded down.
423+
//
348424
// +kubebuilder:validation:Optional
349-
Capacity map[string]resource.Quantity `json:"capacity"`
425+
EffectiveCapacity map[ResourceName]resource.Quantity `json:"effectiveCapacity,omitempty"`
350426

351427
// Auto-discovered cells on this hypervisor.
352428
// +kubebuilder:validation:Optional

api/v1/zz_generated.deepcopy.go

Lines changed: 25 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

applyconfigurations/api/v1/cell.go

Lines changed: 23 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

applyconfigurations/api/v1/hypervisorspec.go

Lines changed: 32 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

applyconfigurations/api/v1/hypervisorstatus.go

Lines changed: 22 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)