@@ -45,14 +45,14 @@ func (s *SizePolicyService) CheckVMMatchedSizePolicy(vm *v1alpha2.VirtualMachine
4545 return NewNoSizingPolicyMatchError (vm .Name , vm .Spec .VirtualMachineClassName )
4646 }
4747
48- var errorsArray []error
48+ var errs []error
4949
50- errorsArray = append (errorsArray , validateCoreFraction (vm , sizePolicy )... )
51- errorsArray = append (errorsArray , validateMemory (vm , sizePolicy )... )
52- errorsArray = append (errorsArray , validatePerCoreMemory (vm , sizePolicy )... )
50+ errs = append (errs , validateCoreFraction (vm , sizePolicy )... )
51+ errs = append (errs , validateMemory (vm , sizePolicy )... )
52+ errs = append (errs , validatePerCoreMemory (vm , sizePolicy )... )
5353
54- if len (errorsArray ) > 0 {
55- return fmt .Errorf ("sizing policy validate: %w" , errors .Join (errorsArray ... ))
54+ if len (errs ) > 0 {
55+ return fmt .Errorf ("sizing policy validate: %w" , errors .Join (errs ... ))
5656 }
5757
5858 return nil
@@ -72,15 +72,15 @@ func getVMSizePolicy(vm *v1alpha2.VirtualMachine, vmClass *v1alpha2.VirtualMachi
7272 return nil
7373}
7474
75- func validateCoreFraction (vm * v1alpha2.VirtualMachine , sp * v1alpha2.SizingPolicy ) (errorsArray []error ) {
75+ func validateCoreFraction (vm * v1alpha2.VirtualMachine , sp * v1alpha2.SizingPolicy ) (errs []error ) {
7676 if len (sp .CoreFractions ) == 0 {
7777 return
7878 }
7979
8080 fractionStr := strings .ReplaceAll (vm .Spec .CPU .CoreFraction , "%" , "" )
8181 fraction , err := strconv .Atoi (fractionStr )
8282 if err != nil {
83- errorsArray = append (errorsArray , fmt .Errorf ("unable to parse CPU core fraction: %w" , err ))
83+ errs = append (errs , fmt .Errorf ("unable to parse CPU core fraction: %w" , err ))
8484 return
8585 }
8686
@@ -92,19 +92,19 @@ func validateCoreFraction(vm *v1alpha2.VirtualMachine, sp *v1alpha2.SizingPolicy
9292 }
9393
9494 if ! hasFractionValueInPolicy {
95- errorsArray = append (errorsArray , fmt .Errorf ("VM core fraction value %d is not within the allowed values" , fraction ))
95+ errs = append (errs , fmt .Errorf ("VM core fraction value %d is not within the allowed values: %v " , fraction , sp . CoreFractions ))
9696 }
9797
9898 return
9999}
100100
101- func validateMemory (vm * v1alpha2.VirtualMachine , sp * v1alpha2.SizingPolicy ) (errorsArray []error ) {
101+ func validateMemory (vm * v1alpha2.VirtualMachine , sp * v1alpha2.SizingPolicy ) (errs []error ) {
102102 if sp .Memory == nil || sp .Memory .Max == nil || sp .Memory .Max .IsZero () {
103103 return
104104 }
105105
106106 if sp .Memory .Min != nil && vm .Spec .Memory .Size .Cmp (* sp .Memory .Min ) == common .CmpLesser {
107- errorsArray = append (errorsArray , fmt .Errorf (
107+ errs = append (errs , fmt .Errorf (
108108 "requested VM memory (%s) is less than the minimum allowed, available range [%s, %s]" ,
109109 vm .Spec .Memory .Size .String (),
110110 sp .Memory .Min .String (),
@@ -113,7 +113,7 @@ func validateMemory(vm *v1alpha2.VirtualMachine, sp *v1alpha2.SizingPolicy) (err
113113 }
114114
115115 if vm .Spec .Memory .Size .Cmp (* sp .Memory .Max ) == common .CmpGreater {
116- errorsArray = append (errorsArray , fmt .Errorf (
116+ errs = append (errs , fmt .Errorf (
117117 "requested VM memory (%s) exceeds the maximum allowed, available range [%s, %s]" ,
118118 vm .Spec .Memory .Size .String (),
119119 sp .Memory .Min .String (),
@@ -128,14 +128,14 @@ func validateMemory(vm *v1alpha2.VirtualMachine, sp *v1alpha2.SizingPolicy) (err
128128 }
129129 err := validateIsQuantized (vm .Spec .Memory .Size , minVal , * sp .Memory .Max , * sp .Memory .Step , "VM memory" )
130130 if err != nil {
131- errorsArray = append (errorsArray , err )
131+ errs = append (errs , err )
132132 }
133133 }
134134
135135 return
136136}
137137
138- func validatePerCoreMemory (vm * v1alpha2.VirtualMachine , sp * v1alpha2.SizingPolicy ) (errorsArray []error ) {
138+ func validatePerCoreMemory (vm * v1alpha2.VirtualMachine , sp * v1alpha2.SizingPolicy ) (errs []error ) {
139139 if sp .Memory == nil || sp .Memory .PerCore == nil || sp .Memory .PerCore .Max == nil || sp .Memory .PerCore .Max .IsZero () {
140140 return
141141 }
@@ -147,7 +147,7 @@ func validatePerCoreMemory(vm *v1alpha2.VirtualMachine, sp *v1alpha2.SizingPolic
147147 perCoreMemory := resource .NewQuantity (vmPerCore , resource .BinarySI )
148148
149149 if sp .Memory .PerCore .Min != nil && perCoreMemory .Cmp (* sp .Memory .PerCore .Min ) == common .CmpLesser {
150- errorsArray = append (errorsArray , fmt .Errorf (
150+ errs = append (errs , fmt .Errorf (
151151 "requested VM per core memory (%s) is less than the minimum allowed, available range [%s, %s]" ,
152152 perCoreMemory .String (),
153153 sp .Memory .PerCore .Min .String (),
@@ -156,7 +156,7 @@ func validatePerCoreMemory(vm *v1alpha2.VirtualMachine, sp *v1alpha2.SizingPolic
156156 }
157157
158158 if perCoreMemory .Cmp (* sp .Memory .PerCore .Max ) == common .CmpGreater {
159- errorsArray = append (errorsArray , fmt .Errorf (
159+ errs = append (errs , fmt .Errorf (
160160 "requested VM per core memory (%s) exceeds the maximum allowed, available range [%s, %s]" ,
161161 perCoreMemory .String (),
162162 sp .Memory .PerCore .Min .String (),
@@ -171,7 +171,7 @@ func validatePerCoreMemory(vm *v1alpha2.VirtualMachine, sp *v1alpha2.SizingPolic
171171 }
172172 err := validateIsQuantized (* perCoreMemory , minVal , * sp .Memory .PerCore .Max , * sp .Memory .Step , "VM per core memory" )
173173 if err != nil {
174- errorsArray = append (errorsArray , err )
174+ errs = append (errs , err )
175175 }
176176 }
177177
0 commit comments