Skip to content

Commit

Permalink
Add round for killNum (#240)
Browse files Browse the repository at this point in the history
* Add round for killNum

To kill at least one pod if the replicaSet is above 2 replicas.
It correct this issue:  #227
  • Loading branch information
tgaudillat02 authored Dec 6, 2022
1 parent dfb8f46 commit cc6d67b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/pkg/victims/victims.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (v *VictimBase) KillNumberForFixedPercentage(clientset kube.Interface, kill
}

numberOfPodsToKill := float64(numRunningPods) * float64(killPercentage) / 100
killNum := int(math.Floor(numberOfPodsToKill))
killNum := int(math.Round(numberOfPodsToKill))

return killNum, nil
}
Expand All @@ -305,7 +305,7 @@ func (v *VictimBase) KillNumberForMaxPercentage(clientset kube.Interface, maxPer
r := rand.New(rand.NewSource(time.Now().UnixNano()))
killPercentage := r.Intn(maxPercentage + 1) // + 1 because Intn works with half open interval [0,n) and we want [0,n]
numberOfPodsToKill := float64(numRunningPods) * float64(killPercentage) / 100
killNum := int(math.Floor(numberOfPodsToKill))
killNum := int(math.Round(numberOfPodsToKill))

return killNum, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/victims/victims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func TestDeletePodsFixedPercentage(t *testing.T) {
pods: append(
generateNPods("running", 1, corev1.PodRunning),
generateNPods("pending", 1, corev1.PodPending)...),
expectedNum: 0,
expectedNum: 1,
expectedErr: false,
},
}
Expand Down

0 comments on commit cc6d67b

Please sign in to comment.