You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
return0, errors.Wrapf(err, "failed to caculate MachinePool replicas value: could not parse the value of the %q annotation", clusterv1.AutoscalerMinSizeAnnotation)
return0, errors.Wrapf(err, "failed to caculate MachinePool replicas value: could not parse the value of the %q annotation", clusterv1.AutoscalerMaxSizeAnnotation)
238
+
}
239
+
240
+
// If it's a new MachinePool => Use the min size.
241
+
// Note: This will result in a scale up to get into the range where autoscaler takes over.
242
+
ifoldMP==nil {
243
+
if!dryRun {
244
+
log.V(2).Info(fmt.Sprintf("Replica field has been defaulted to %d based on the %s annotation (MP is a new MP)", minSize, clusterv1.AutoscalerMinSizeAnnotation))
245
+
}
246
+
returnint32(minSize), nil
247
+
}
248
+
249
+
// Otherwise we are handing over the control for the replicas field for an existing MachinePool
250
+
// to the autoscaler.
251
+
252
+
switch {
253
+
// If the old MachinePool doesn't have replicas set => Use the min size.
254
+
// Note: As defaulting always sets the replica field, this case should not be possible
255
+
// We only have this handling to be 100% safe against panics.
256
+
caseoldMP.Spec.Replicas==nil:
257
+
if!dryRun {
258
+
log.V(2).Info(fmt.Sprintf("Replica field has been defaulted to %d based on the %s annotation (old MP didn't have replicas set)", minSize, clusterv1.AutoscalerMinSizeAnnotation))
259
+
}
260
+
returnint32(minSize), nil
261
+
// If the old MachinePool replicas are lower than min size => Use the min size.
262
+
// Note: This will result in a scale up to get into the range where autoscaler takes over.
263
+
case*oldMP.Spec.Replicas<int32(minSize):
264
+
if!dryRun {
265
+
log.V(2).Info(fmt.Sprintf("Replica field has been defaulted to %d based on the %s annotation (old MP had replicas below min size)", minSize, clusterv1.AutoscalerMinSizeAnnotation))
266
+
}
267
+
returnint32(minSize), nil
268
+
// If the old MachinePool replicas are higher than max size => Use the max size.
269
+
// Note: This will result in a scale down to get into the range where autoscaler takes over.
270
+
case*oldMP.Spec.Replicas>int32(maxSize):
271
+
if!dryRun {
272
+
log.V(2).Info(fmt.Sprintf("Replica field has been defaulted to %d based on the %s annotation (old MP had replicas above max size)", maxSize, clusterv1.AutoscalerMaxSizeAnnotation))
273
+
}
274
+
returnint32(maxSize), nil
275
+
// If the old MachinePool replicas are between min and max size => Keep the current value.
276
+
default:
277
+
if!dryRun {
278
+
log.V(2).Info(fmt.Sprintf("Replica field has been defaulted to %d based on replicas of the old MachinePool (old MP had replicas within min size / max size range)", *oldMP.Spec.Replicas))
279
+
}
280
+
return*oldMP.Spec.Replicas, nil
281
+
}
282
+
}
283
+
284
+
// If neither the default nor the autoscaler annotations are set => Default to 1.
285
+
if!dryRun {
286
+
log.V(2).Info("Replica field has been defaulted to 1")
0 commit comments