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
Copy file name to clipboardExpand all lines: api/v1beta1/machineset_types.go
+15-2Lines changed: 15 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -41,9 +41,22 @@ type MachineSetSpec struct {
41
41
42
42
// Replicas is the number of desired replicas.
43
43
// This is a pointer to distinguish between explicit zero and unspecified.
44
-
// Defaults to 1.
44
+
//
45
+
// Defaults to:
46
+
// * if the Kubernetes autoscaler min size and max size annotations are set:
47
+
// - if it's a new MachineSet, use min size
48
+
// - if the replicas field of the old MachineSet is < min size, use min size
49
+
// - if the replicas field of the old MachineSet is > max size, use max size
50
+
// - if the replicas field of the old MachineSet is in the (min size, max size) range, keep the value from the oldMS
51
+
// * otherwise use 1
52
+
// Note: Defaulting will be run whenever the replicas field is not set:
53
+
// * A new MachineSet is created with replicas not set.
54
+
// * On an existing MachineSet the replicas field was first set and is now unset.
55
+
// Those cases are especially relevant for the following Kubernetes autoscaler use cases:
56
+
// * A new MachineSet is created and replicas should be managed by the autoscaler
57
+
// * An existing MachineSet which initially wasn't controlled by the autoscaler
58
+
// should be later controlled by the autoscaler
45
59
// +optional
46
-
// +kubebuilder:default=1
47
60
Replicas*int32`json:"replicas,omitempty"`
48
61
49
62
// MinReadySeconds is the minimum number of seconds for which a Node for a newly created machine should be ready before considering the replica available.
return0, errors.Wrapf(err, "failed to caculate MachineSet replicas value: could not parse the value of the %q annotation", clusterv1.AutoscalerMinSizeAnnotation)
return0, errors.Wrapf(err, "failed to caculate MachineSet replicas value: could not parse the value of the %q annotation", clusterv1.AutoscalerMaxSizeAnnotation)
305
+
}
306
+
307
+
// If it's a new MachineSet => Use the min size.
308
+
// Note: This will result in a scale up to get into the range where autoscaler takes over.
309
+
ifoldMS==nil {
310
+
if!dryRun {
311
+
log.V(2).Info(fmt.Sprintf("Replica field has been defaulted to %d based on the %s annotation (MS is a new MS)", minSize, clusterv1.AutoscalerMinSizeAnnotation))
312
+
}
313
+
returnint32(minSize), nil
314
+
}
315
+
316
+
// Otherwise we are handing over the control for the replicas field for an existing MachineSet
317
+
// to the autoscaler.
318
+
319
+
switch {
320
+
// If the old MachineSet doesn't have replicas set => Use the min size.
321
+
// Note: As defaulting always sets the replica field, this case should not be possible
322
+
// We only have this handling to be 100% safe against panics.
323
+
caseoldMS.Spec.Replicas==nil:
324
+
if!dryRun {
325
+
log.V(2).Info(fmt.Sprintf("Replica field has been defaulted to %d based on the %s annotation (old MS didn't have replicas set)", minSize, clusterv1.AutoscalerMinSizeAnnotation))
326
+
}
327
+
returnint32(minSize), nil
328
+
// If the old MachineSet replicas are lower than min size => Use the min size.
329
+
// Note: This will result in a scale up to get into the range where autoscaler takes over.
330
+
case*oldMS.Spec.Replicas<int32(minSize):
331
+
if!dryRun {
332
+
log.V(2).Info(fmt.Sprintf("Replica field has been defaulted to %d based on the %s annotation (old MS had replicas below min size)", minSize, clusterv1.AutoscalerMinSizeAnnotation))
333
+
}
334
+
returnint32(minSize), nil
335
+
// If the old MachineSet replicas are higher than max size => Use the max size.
336
+
// Note: This will result in a scale down to get into the range where autoscaler takes over.
337
+
case*oldMS.Spec.Replicas>int32(maxSize):
338
+
if!dryRun {
339
+
log.V(2).Info(fmt.Sprintf("Replica field has been defaulted to %d based on the %s annotation (old MS had replicas above max size)", maxSize, clusterv1.AutoscalerMaxSizeAnnotation))
340
+
}
341
+
returnint32(maxSize), nil
342
+
// If the old MachineSet replicas are between min and max size => Keep the current value.
343
+
default:
344
+
if!dryRun {
345
+
log.V(2).Info(fmt.Sprintf("Replica field has been defaulted to %d based on replicas of the old MachineSet (old MS had replicas within min size / max size range)", *oldMS.Spec.Replicas))
346
+
}
347
+
return*oldMS.Spec.Replicas, nil
348
+
}
349
+
}
350
+
351
+
// If neither the default nor the autoscaler annotations are set => Default to 1.
352
+
if!dryRun {
353
+
log.V(2).Info("Replica field has been defaulted to 1")
0 commit comments