Skip to content

Commit 0b542ab

Browse files
author
Valeriy Khorunzhin
committed
t
Signed-off-by: Valeriy Khorunzhin <[email protected]>
1 parent d582d20 commit 0b542ab

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

crds/virtualmachineclasses.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ spec:
341341
x-kubernetes-int-or-string: true
342342
type: object
343343
type: object
344+
x-kubernetes-validations:
345+
- message: The defaultCoreFraction must be one of the values in coreFractions
346+
rule: "!has(self.defaultCoreFraction) || self.defaultCoreFraction in self.coreFractions"
344347
type: array
345348
tolerations:
346349
description: |-
@@ -838,6 +841,9 @@ spec:
838841
x-kubernetes-int-or-string: true
839842
type: object
840843
type: object
844+
x-kubernetes-validations:
845+
- message: The defaultCoreFraction must be one of the values in coreFractions
846+
rule: "!has(self.defaultCoreFraction) || self.defaultCoreFraction in self.coreFractions"
841847
type: array
842848
tolerations:
843849
description: |-

images/virtualization-artifact/pkg/controller/vm/internal/defaulter/core_fraction.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ func (d *CoreFractionDefaulter) Default(ctx context.Context, vm *v1alpha2.Virtua
5959
defaultCoreFraction := d.getDefaultCoreFraction(vm, vmClass)
6060
if defaultCoreFraction != "" {
6161
vm.Spec.CPU.CoreFraction = defaultCoreFraction
62-
} else {
63-
// If no default is set in the class, use 100% as fallback.
64-
vm.Spec.CPU.CoreFraction = "100%"
6562
}
6663

6764
return nil
@@ -70,8 +67,10 @@ func (d *CoreFractionDefaulter) Default(ctx context.Context, vm *v1alpha2.Virtua
7067
// getDefaultCoreFraction finds the default core fraction from the VMClass sizing policy
7168
// that matches the VM's CPU cores count.
7269
func (d *CoreFractionDefaulter) getDefaultCoreFraction(vm *v1alpha2.VirtualMachine, vmClass *v1alpha3.VirtualMachineClass) string {
70+
const defaultValue = "100%"
71+
7372
if vmClass == nil || len(vmClass.Spec.SizingPolicies) == 0 {
74-
return ""
73+
return defaultValue
7574
}
7675

7776
for _, sp := range vmClass.Spec.SizingPolicies {
@@ -84,9 +83,9 @@ func (d *CoreFractionDefaulter) getDefaultCoreFraction(vm *v1alpha2.VirtualMachi
8483
if sp.DefaultCoreFraction != nil {
8584
return string(*sp.DefaultCoreFraction)
8685
}
87-
return ""
86+
return defaultValue
8887
}
8988
}
9089

91-
return ""
90+
return defaultValue
9291
}

0 commit comments

Comments
 (0)