Skip to content

Commit

Permalink
Merge pull request wildfly#294 from yersan/issue-291
Browse files Browse the repository at this point in the history
Replicas and ScalingdownPods could be wrongly calculated when the…
  • Loading branch information
yersan authored Feb 14, 2024
2 parents 5f0c4c5 + d4cb4a5 commit 22dd669
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions controllers/wildflyserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,20 +573,25 @@ Outer:
result = append(result, v)
}
}
if len(result) != len(w.Status.Pods) {
totalOld := len(w.Status.Pods)
totalNew := len(result)
if totalOld != totalNew {
patch := client.MergeFrom(w.DeepCopy())
w.Status.Pods = result
if w.Status.Replicas > 0 {
w.Status.Replicas--
}
if w.Status.ScalingdownPods > 0 {
w.Status.ScalingdownPods--
}

delta := totalOld - totalNew
w.Status.Replicas = Max(w.Status.Replicas-int32(delta), 0)
w.Status.ScalingdownPods = Max(w.Status.ScalingdownPods-int32(delta), 0)
if err := r.Client.Status().Patch(context.Background(), w, patch); err != nil {
return false, err
}
return true, nil
}
return false, nil
}

func Max(x, y int32) int32 {
if x < y {
return y
}
return x
}

0 comments on commit 22dd669

Please sign in to comment.