@@ -470,10 +470,7 @@ func (dc *controller) scale(ctx context.Context, deployment *v1alpha1.MachineDep
470470 // Incorporate any leftovers to the largest machine set.
471471 if i == 0 && deploymentReplicasToAdd != 0 {
472472 leftover := deploymentReplicasToAdd - deploymentReplicasAdded
473- nameToSize [is .Name ] = nameToSize [is .Name ] + leftover
474- if nameToSize [is .Name ] < 0 {
475- nameToSize [is .Name ] = 0
476- }
473+ nameToSize [is .Name ] = max (nameToSize [is .Name ]+ leftover , 0 )
477474 klog .V (3 ).Infof ("leftover proportion increase of %d done in largest machineSet %s" , leftover , is .Name )
478475 }
479476
@@ -586,7 +583,7 @@ func (dc *controller) cleanupMachineDeployment(ctx context.Context, oldISs []*v1
586583 sort .Sort (MachineSetsByCreationTimestamp (cleanableISes ))
587584 klog .V (4 ).Infof ("Looking to cleanup old machine sets for deployment %q" , deployment .Name )
588585
589- for i := int32 ( 0 ); i < diff ; i ++ {
586+ for i := range diff {
590587 is := cleanableISes [i ]
591588 // Avoid delete machine set with non-zero replica counts
592589 if is .Status .Replicas != 0 || (is .Spec .Replicas ) != 0 || is .Generation > is .Status .ObservedGeneration || is .DeletionTimestamp != nil {
@@ -621,12 +618,9 @@ func (dc *controller) syncMachineDeploymentStatus(ctx context.Context, allISs []
621618func calculateDeploymentStatus (allISs []* v1alpha1.MachineSet , newIS * v1alpha1.MachineSet , deployment * v1alpha1.MachineDeployment ) v1alpha1.MachineDeploymentStatus {
622619 availableReplicas := GetAvailableReplicaCountForMachineSets (allISs )
623620 totalReplicas := GetReplicaCountForMachineSets (allISs )
624- unavailableReplicas := totalReplicas - availableReplicas
625621 // If unavailableReplicas is negative, then that means the Deployment has more available replicas running than
626622 // desired, e.g. whenever it scales down. In such a case we should simply default unavailableReplicas to zero.
627- if unavailableReplicas < 0 {
628- unavailableReplicas = 0
629- }
623+ unavailableReplicas := max (totalReplicas - availableReplicas , 0 )
630624
631625 status := v1alpha1.MachineDeploymentStatus {
632626 // TODO: Ensure that if we start retrying status updates, we won't pick up a new Generation value.
0 commit comments