Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Use min/max funcs from Go SDK #9945

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions controlplane/kubeadm/internal/controllers/remediation.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,6 @@ func (r *KubeadmControlPlaneReconciler) checkRetryLimits(log logr.Logger, machin
return remediationInProgressData, true, nil
}

// max calculates the maximum duration.
func max(x, y time.Duration) time.Duration {
if x < y {
return y
}
return x
}

// canSafelyRemoveEtcdMember assess if it is possible to remove the member hosted on the machine to be remediated
// without loosing etcd quorum.
//
Expand Down
7 changes: 0 additions & 7 deletions hack/tools/internal/log-push/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,3 @@ func pushStreamToLoki(ctx context.Context, lokiURL, lokiOrgID string, body []byt
klog.Infof("Push response: status: %q, body: %q", resp.Status, string(respBody))
return nil
}

func min(a, b int) int {
if a <= b {
return a
}
return b
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"sort"

"github.com/pkg/errors"
"k8s.io/utils/integer"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -217,7 +216,7 @@ func (r *Reconciler) cleanupUnhealthyReplicas(ctx context.Context, oldMSs []*clu

remainingCleanupCount := maxCleanupCount - totalScaledDown
unhealthyCount := oldMSReplicas - oldMSAvailableReplicas
scaledDownCount := integer.Int32Min(remainingCleanupCount, unhealthyCount)
scaledDownCount := min(remainingCleanupCount, unhealthyCount)
newReplicasCount := oldMSReplicas - scaledDownCount

if newReplicasCount > oldMSReplicas {
Expand Down Expand Up @@ -278,7 +277,7 @@ func (r *Reconciler) scaleDownOldMachineSetsForRollingUpdate(ctx context.Context
}

// Scale down.
scaleDownCount := integer.Int32Min(*(targetMS.Spec.Replicas), totalScaleDownCount-totalScaledDown)
scaleDownCount := min(*(targetMS.Spec.Replicas), totalScaleDownCount-totalScaledDown)
newReplicasCount := *(targetMS.Spec.Replicas) - scaleDownCount
if newReplicasCount > *(targetMS.Spec.Replicas) {
return totalScaledDown, errors.Errorf("when scaling down old MachineSet, got invalid request to scale down %v: %d -> %d",
Expand Down
8 changes: 4 additions & 4 deletions internal/controllers/machinedeployment/mdutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@ func GetProportion(ms *clusterv1.MachineSet, md clusterv1.MachineDeployment, dep
// Use the minimum between the machine set fraction and the maximum allowed replicas
// when scaling up. This way we ensure we will not scale up more than the allowed
// replicas we can add.
return integer.Int32Min(msFraction, allowed)
return min(msFraction, allowed)
}
// Use the maximum between the machine set fraction and the maximum allowed replicas
// when scaling down. This way we ensure we will not scale down more than the allowed
// replicas we can remove.
return integer.Int32Max(msFraction, allowed)
return max(msFraction, allowed)
}

// getMachineSetFraction estimates the fraction of replicas a machine set can have in
Expand Down Expand Up @@ -485,7 +485,7 @@ func TotalMachineSetsReplicaSum(machineSets []*clusterv1.MachineSet) int32 {
totalReplicas := int32(0)
for _, ms := range machineSets {
if ms != nil {
totalReplicas += integer.Int32Max(*(ms.Spec.Replicas), ms.Status.Replicas)
totalReplicas += max(*(ms.Spec.Replicas), ms.Status.Replicas)
}
}
return totalReplicas
Expand Down Expand Up @@ -550,7 +550,7 @@ func NewMSNewReplicas(deployment *clusterv1.MachineDeployment, allMSs []*cluster
// Scale up.
scaleUpCount := maxTotalMachines - currentMachineCount
// Do not exceed the number of desired replicas.
scaleUpCount = integer.Int32Min(scaleUpCount, *(deployment.Spec.Replicas)-newMSReplicas)
scaleUpCount = min(scaleUpCount, *(deployment.Spec.Replicas)-newMSReplicas)
return newMSReplicas + scaleUpCount, nil
case clusterv1.OnDeleteMachineDeploymentStrategyType:
// Find the total number of machines
Expand Down