@@ -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
143182const (
@@ -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
0 commit comments