From 20d7fa27718c9b32f70ae93eba6ecb4b134586a4 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 25 Jan 2023 19:50:06 +0100 Subject: [PATCH] e2e dra: fix resource limits in a mixed cluster The check for "resources available on a node" must treat nodes that are not listed as "no resources available". The previous logic only worked because all nodes were listed during E2E testing. The upcoming integration testing is covering additional scenarios and triggered this broken case. --- test/e2e/dra/test-driver/app/controller.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/e2e/dra/test-driver/app/controller.go b/test/e2e/dra/test-driver/app/controller.go index 8ddd46ffa53..243a62ffef0 100644 --- a/test/e2e/dra/test-driver/app/controller.go +++ b/test/e2e/dra/test-driver/app/controller.go @@ -198,8 +198,9 @@ func (c *ExampleController) allocate(ctx context.Context, claim *resourcev1alpha // number of allocations (even spreading) or the most (packing). node = viableNodes[rand.Intn(len(viableNodes))] logger.Info("picked a node ourselves", "selectedNode", selectedNode) - } else if c.resources.MaxAllocations > 0 && - c.countAllocations(node) >= c.resources.MaxAllocations { + } else if !contains(c.resources.Nodes, node) || + c.resources.MaxAllocations > 0 && + c.countAllocations(node) >= c.resources.MaxAllocations { return nil, fmt.Errorf("resources exhausted on node %q", node) } } else { @@ -292,7 +293,7 @@ func (c *ExampleController) UnsuitableNodes(ctx context.Context, pod *v1.Pod, cl // can only work if a node has capacity left // for all of them. Also, nodes that the driver // doesn't run on cannot be used. - if contains(c.resources.Nodes, node) && + if !contains(c.resources.Nodes, node) || allocationsPerNode[node]+len(claims) > c.resources.MaxAllocations { claim.UnsuitableNodes = append(claim.UnsuitableNodes, node) } @@ -305,7 +306,7 @@ func (c *ExampleController) UnsuitableNodes(ctx context.Context, pod *v1.Pod, cl for _, claim := range claims { claim.UnsuitableNodes = nil for _, node := range potentialNodes { - if contains(c.resources.Nodes, node) && + if !contains(c.resources.Nodes, node) || allocations+len(claims) > c.resources.MaxAllocations { claim.UnsuitableNodes = append(claim.UnsuitableNodes, node) }