Skip to content

Commit 6dbb5d8

Browse files
committed
Move integration tests perf utils to scheduler_perf package
1 parent 930ebe1 commit 6dbb5d8

File tree

3 files changed

+35
-38
lines changed

3 files changed

+35
-38
lines changed

test/integration/framework/util.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,14 @@ import (
2222
"context"
2323
"fmt"
2424
"testing"
25-
"time"
2625

2726
v1 "k8s.io/api/core/v1"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29-
"k8s.io/apimachinery/pkg/util/wait"
3028
clientset "k8s.io/client-go/kubernetes"
3129
"k8s.io/klog/v2"
3230
nodectlr "k8s.io/kubernetes/pkg/controller/nodelifecycle"
3331
)
3432

35-
const (
36-
// poll is how often to Poll pods, nodes and claims.
37-
poll = 2 * time.Second
38-
39-
// singleCallTimeout is how long to try single API calls (like 'get' or 'list'). Used to prevent
40-
// transient failures from failing tests.
41-
singleCallTimeout = 5 * time.Minute
42-
)
43-
4433
// CreateNamespaceOrDie creates a namespace.
4534
func CreateNamespaceOrDie(c clientset.Interface, baseName string, t testing.TB) *v1.Namespace {
4635
ns := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: baseName}}
@@ -59,22 +48,6 @@ func DeleteNamespaceOrDie(c clientset.Interface, ns *v1.Namespace, t testing.TB)
5948
}
6049
}
6150

62-
// waitListAllNodes is a wrapper around listing nodes supporting retries.
63-
func waitListAllNodes(c clientset.Interface) (*v1.NodeList, error) {
64-
var nodes *v1.NodeList
65-
var err error
66-
if wait.PollImmediate(poll, singleCallTimeout, func() (bool, error) {
67-
nodes, err = c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
68-
if err != nil {
69-
return false, err
70-
}
71-
return true, nil
72-
}) != nil {
73-
return nodes, err
74-
}
75-
return nodes, nil
76-
}
77-
7851
// Filter filters nodes in NodeList in place, removing nodes that do not
7952
// satisfy the given condition
8053
func Filter(nodeList *v1.NodeList, fn func(node v1.Node) bool) {

test/integration/framework/perf_utils.go renamed to test/integration/scheduler_perf/node_util.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,40 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package framework
17+
package benchmark
1818

1919
import (
2020
"context"
2121
"fmt"
22+
"time"
2223

2324
v1 "k8s.io/api/core/v1"
2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
"k8s.io/apimachinery/pkg/util/rand"
27+
"k8s.io/apimachinery/pkg/util/wait"
2628
clientset "k8s.io/client-go/kubernetes"
2729
"k8s.io/klog/v2"
2830
testutils "k8s.io/kubernetes/test/utils"
2931
)
3032

3133
const (
32-
retries = 5
34+
// createNodeRetries defines number of retries when creating nodes.
35+
createNodeRetries = 5
36+
37+
// pollingInterval defines how often to poll when waiting for nodes to be created.
38+
pollingInterval = 2 * time.Second
39+
40+
// singleCallTimeout is how long to try single API calls (like 'get' or 'list'). Used to prevent
41+
// transient failures from failing tests.
42+
singleCallTimeout = 5 * time.Minute
3343
)
3444

3545
// NodeTemplate is responsible for creating a v1.Node instance that is ready
3646
// to be sent to the API server.
3747
type NodeTemplate interface {
3848
// GetNodeTemplate returns a node template for one out of many different nodes.
39-
// Nodes with numbers in the range [index, index+count-1] will be created
40-
// based on what GetNodeTemplate returns. It gets called multiple times
41-
// with a fixed index and increasing count parameters. This number can,
42-
// but doesn't have to be, used to modify parts of the node spec like
49+
// It gets called multiple times with an increasing index and a fixed count parameters.
50+
// This number can, but doesn't have to be, used to modify parts of the node spec like
4351
// for example a named reference to some other object.
4452
GetNodeTemplate(index, count int) (*v1.Node, error)
4553
}
@@ -87,7 +95,7 @@ func (p *IntegrationTestNodePreparer) PrepareNodes(ctx context.Context, nextNode
8795
if err != nil {
8896
return fmt.Errorf("failed to get node template: %w", err)
8997
}
90-
for retry := 0; retry < retries; retry++ {
98+
for retry := 0; retry < createNodeRetries; retry++ {
9199
// Create nodes with the usual kubernetes.io/hostname label.
92100
// For that we need to know the name in advance, if we want to
93101
// do it in one request.
@@ -111,7 +119,7 @@ func (p *IntegrationTestNodePreparer) PrepareNodes(ctx context.Context, nextNode
111119
}
112120
}
113121

114-
nodes, err := waitListAllNodes(p.client)
122+
nodes, err := waitListAllNodes(ctx, p.client)
115123
if err != nil {
116124
return fmt.Errorf("listing nodes: %w", err)
117125
}
@@ -130,7 +138,7 @@ func (p *IntegrationTestNodePreparer) PrepareNodes(ctx context.Context, nextNode
130138
func (p *IntegrationTestNodePreparer) CleanupNodes(ctx context.Context) error {
131139
// TODO(#93794): make CleanupNodes only clean up the nodes created by this
132140
// IntegrationTestNodePreparer to make this more intuitive.
133-
nodes, err := waitListAllNodes(p.client)
141+
nodes, err := waitListAllNodes(ctx, p.client)
134142
if err != nil {
135143
klog.Fatalf("Error listing nodes: %v", err)
136144
}
@@ -143,3 +151,19 @@ func (p *IntegrationTestNodePreparer) CleanupNodes(ctx context.Context) error {
143151
}
144152
return errRet
145153
}
154+
155+
// waitListAllNodes is a wrapper around listing nodes supporting retries.
156+
func waitListAllNodes(ctx context.Context, c clientset.Interface) (*v1.NodeList, error) {
157+
var nodes *v1.NodeList
158+
var err error
159+
if wait.PollUntilContextTimeout(ctx, pollingInterval, singleCallTimeout, true, func(ctx context.Context) (bool, error) {
160+
nodes, err = c.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
161+
if err != nil {
162+
return false, err
163+
}
164+
return true, nil
165+
}) != nil {
166+
return nodes, err
167+
}
168+
return nodes, nil
169+
}

test/integration/scheduler_perf/scheduler_perf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,12 +1688,12 @@ func getNodePreparer(prefix string, cno *createNodesOp, clientset clientset.Inte
16881688
nodeStrategy = cno.UniqueNodeLabelStrategy
16891689
}
16901690

1691-
nodeTemplate := framework.StaticNodeTemplate(makeBaseNode(prefix))
1691+
nodeTemplate := StaticNodeTemplate(makeBaseNode(prefix))
16921692
if cno.NodeTemplatePath != nil {
16931693
nodeTemplate = nodeTemplateFromFile(*cno.NodeTemplatePath)
16941694
}
16951695

1696-
return framework.NewIntegrationTestNodePreparer(
1696+
return NewIntegrationTestNodePreparer(
16971697
clientset,
16981698
[]testutils.CountToStrategy{{Count: cno.Count, Strategy: nodeStrategy}},
16991699
nodeTemplate,

0 commit comments

Comments
 (0)