Skip to content
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ check: FORCE static-check build/cover.html build-all

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

Expand Down
84 changes: 80 additions & 4 deletions api/v1/hypervisor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ResourceName is the name identifying a hypervisor resource.
// Note: this type is similar to the type defined in the kubernetes core api,
// but may be extended to support additional resource types in the future.
// See: https://github.com/kubernetes/api/blob/7e7aaba/core/v1/types.go#L6954-L6970
type ResourceName string

// Resource names must be not more than 63 characters, consisting of upper- or
// lower-case alphanumeric characters, with the -, _, and . characters allowed
// anywhere, except the first or last character. The default convention,
// matching that for annotations, is to use lower-case names, with dashes,
// rather than camel case, separating compound words. Fully-qualified resource
// typenames are constructed from a DNS-style subdomain, followed by a slash `/`
// and a name.
const (
// CPU, in cores. Note that currently, it is not supported to provide
// fractional cpu resources, such as 500m for 0.5 cpu.
ResourceCPU ResourceName = "cpu"
// Memory, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
ResourceMemory ResourceName = "memory"
)

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
Expand Down Expand Up @@ -133,6 +154,24 @@ type HypervisorSpec struct {
// +kubebuilder:optional
// MaintenanceReason provides the reason for manual maintenance mode.
MaintenanceReason string `json:"maintenanceReason,omitempty"`

// Overcommit specifies the desired overcommit ratio by resource type.
//
// If no overcommit is specified for a resource type, the default overcommit
// ratio of 1.0 should be applied, i.e. the effective capacity is the same
// as the actual capacity.
//
// If the overcommit ratio results in a fractional effective capacity,
// the effective capacity is expected to be rounded down. This allows
// gradually adjusting the hypervisor capacity.
//
// +kubebuilder:validation:Optional
//
// It is validated that all overcommit ratios are greater than or equal to
// 1.0, if specified. For this we don't need extra validating webhooks.
// See: https://kubernetes.io/blog/2022/09/23/crd-validation-rules-beta/#crd-transition-rules
// +kubebuilder:validation:XValidation:rule="self.all(k, self[k] >= 1.0)",message="overcommit ratios must be >= 1.0"
Overcommit map[ResourceName]float64 `json:"overcommit,omitempty"`
}

const (
Expand Down Expand Up @@ -300,11 +339,29 @@ type Cell struct {

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

// Auto-discovered capacity of this cell.
//
// Note that this capacity does not include the applied overcommit ratios,
// and represents the actual capacity of the cell. Use the effective capacity
// field to get the capacity considering the applied overcommit ratios.
//
// +kubebuilder:validation:Optional
Capacity map[string]resource.Quantity `json:"capacity"`
Capacity map[ResourceName]resource.Quantity `json:"capacity"`

// Auto-discovered capacity of this cell, considering the
// applied overcommit ratios.
//
// In case no overcommit ratio is specified for a resource type, the default
// overcommit ratio of 1 should be applied, meaning the effective capacity
// is the same as the actual capacity.
//
// If the overcommit ratio results in a fractional effective capacity, the
// effective capacity is expected to be rounded down.
//
// +kubebuilder:validation:Optional
EffectiveCapacity map[ResourceName]resource.Quantity `json:"effectiveCapacity,omitempty"`
}

// HypervisorStatus defines the observed state of Hypervisor
Expand Down Expand Up @@ -337,11 +394,30 @@ type HypervisorStatus struct {

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

// Auto-discovered capacity of the hypervisor.
//
// Note that this capacity does not include the applied overcommit ratios,
// and represents the actual capacity of the hypervisor. Use the
// effective capacity field to get the capacity considering the applied
// overcommit ratios.
//
// +kubebuilder:validation:Optional
Capacity map[ResourceName]resource.Quantity `json:"capacity"`

// Auto-discovered capacity of the hypervisor, considering the
// applied overcommit ratios.
//
// In case no overcommit ratio is specified for a resource type, the default
// overcommit ratio of 1 should be applied, meaning the effective capacity
// is the same as the actual capacity.
//
// If the overcommit ratio results in a fractional effective capacity, the
// effective capacity is expected to be rounded down.
//
// +kubebuilder:validation:Optional
Capacity map[string]resource.Quantity `json:"capacity"`
EffectiveCapacity map[ResourceName]resource.Quantity `json:"effectiveCapacity,omitempty"`

// Auto-discovered cells on this hypervisor.
// +kubebuilder:validation:Optional
Expand Down
29 changes: 25 additions & 4 deletions api/v1/zz_generated.deepcopy.go

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

30 changes: 23 additions & 7 deletions applyconfigurations/api/v1/cell.go

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

45 changes: 32 additions & 13 deletions applyconfigurations/api/v1/hypervisorspec.go

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

28 changes: 22 additions & 6 deletions applyconfigurations/api/v1/hypervisorstatus.go

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

Loading
Loading