From ceca314b971078515ab465e11256a96fd0cee3d4 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] Change rounding of a number of selected nodes --- clusterloader2/pkg/chaos/nodes.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/clusterloader2/pkg/chaos/nodes.go b/clusterloader2/pkg/chaos/nodes.go index a805147b42..2a81c2ab7b 100644 --- a/clusterloader2/pkg/chaos/nodes.go +++ b/clusterloader2/pkg/chaos/nodes.go @@ -18,6 +18,7 @@ package chaos import ( "fmt" + "math" "math/rand" "sync" "time" @@ -86,6 +87,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,9 +100,13 @@ 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))) + numNodes := int(math.Ceil(k.config.FailureRate * float64(len(nodes)))) + klog.Infof("%s: %d nodes available, wants to fail %d nodes", k, len(nodes), numNodes) if len(nodes) > numNodes { - return nodes[:numNodes], nil + nodes = nodes[:numNodes] + } + for _, node := range nodes { + klog.Infof("%s: Node %q schedule for failure", k, node.Name) } return nodes, nil }