From 9f57ad505e88aeb4745e14545f8ae608a726b5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Przychodze=C5=84?= Date: Wed, 4 Mar 2020 15:28:07 +0100 Subject: [PATCH] [NodeKiller] Add randomization on node killing --- clusterloader2/pkg/chaos/nodes.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/clusterloader2/pkg/chaos/nodes.go b/clusterloader2/pkg/chaos/nodes.go index a805147b42..c4b73a7658 100644 --- a/clusterloader2/pkg/chaos/nodes.go +++ b/clusterloader2/pkg/chaos/nodes.go @@ -86,6 +86,7 @@ func (k *NodeKiller) pickNodes() ([]v1.Node, error) { for i := range prometheusPods { if prometheusPods[i].Spec.NodeName != "" { nodesHasPrometheusPod.Insert(prometheusPods[i].Spec.NodeName) + klog.Infof("%s: Node %s removed from killing. Runs pod %s", k, prometheusPods[i].Spec.NodeName, prometheusPods[i].Name) } } @@ -98,11 +99,17 @@ func (k *NodeKiller) pickNodes() ([]v1.Node, error) { rand.Shuffle(len(nodes), func(i, j int) { nodes[i], nodes[j] = nodes[j], nodes[i] }) - numNodes := int(k.config.FailureRate * float64(len(nodes))) - if len(nodes) > numNodes { - return nodes[:numNodes], nil + expectedNodesToFail := k.config.FailureRate * float64(len(nodes)) + nodesToFail := nodes[:0] + klog.Infof("%s: %d nodes available, estimating to select %f nodes", k, len(nodes), expectedNodesToFail) + for _, node := range nodes { + if rand.Float64() < k.config.FailureRate { + klog.Infof("%s: Node %q schedule for failure", k, node.Name) + nodesToFail = append(nodesToFail, node) + } } - return nodes, nil + klog.Infof("%s: Total %d nodes scheduled for failure", k, len(nodesToFail)) + return nodesToFail, nil } func (k *NodeKiller) kill(nodes []v1.Node) {