@@ -39,6 +39,7 @@ import io.fabric8.kubernetes.api.model.ResourceRequirements
3939import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder
4040import io.fabric8.kubernetes.api.model.VolumeBuilder
4141import io.fabric8.kubernetes.api.model.VolumeMountBuilder
42+ import java.util.*
4243
4344class PodTemplateSpecFactory (config : Config ) {
4445
@@ -225,7 +226,13 @@ class PodTemplateSpecFactory(config: Config) {
225226 }
226227
227228 private fun parseCpuQuantity (value : String ): Quantity {
228- val quantity = Quantity (value)
229+ // convert upper case suffix automatically to a value accepted by k8s
230+ val converted = if (value.endsWith(" M" )) {
231+ value.dropLast(1 ) + " m" ;
232+ } else {
233+ value
234+ }
235+ val quantity = Quantity (converted)
229236 quantity.numericalAmount // validates the quantity
230237 if (quantity.format != " m" && quantity.format != " " ) {
231238 throw RuntimeException (" Invalid format for CPU resources" )
@@ -234,10 +241,21 @@ class PodTemplateSpecFactory(config: Config) {
234241 }
235242
236243 private fun parseMemorQuantity (value : String ): Quantity {
237- val quantity = Quantity (value)
244+ var converted = value
245+ // convert lower case suffixes automatically to a value accepted by k8s
246+ for (suffix in listOf (" p" , " t" , " g" , " m" , " k" )) {
247+ if (value.endsWith(suffix)) {
248+ converted = value.dropLast(1 ) + suffix.uppercase(Locale .getDefault())
249+ break
250+ } else if (value.endsWith(suffix + " i" )) {
251+ converted = value.dropLast(2 ) + suffix.uppercase(Locale .getDefault()) + " i"
252+ break
253+ }
254+ }
255+ val quantity = Quantity (converted)
238256 quantity.numericalAmount // validates the quantity
239- if (quantity.format == " m" || quantity.format == " " ) {
240- throw RuntimeException (" Invalid format for memory resources" )
257+ if (quantity.format == " m" || quantity.format == " mi " || quantity.format == " " ) {
258+ throw RuntimeException (" Invalid format for memory resources" );
241259 }
242260 return quantity
243261 }
0 commit comments