@@ -14,32 +14,40 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package framework
17
+ package benchmark
18
18
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "time"
22
23
23
24
v1 "k8s.io/api/core/v1"
24
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
26
"k8s.io/apimachinery/pkg/util/rand"
27
+ "k8s.io/apimachinery/pkg/util/wait"
26
28
clientset "k8s.io/client-go/kubernetes"
27
29
"k8s.io/klog/v2"
28
30
testutils "k8s.io/kubernetes/test/utils"
29
31
)
30
32
31
33
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
33
43
)
34
44
35
45
// NodeTemplate is responsible for creating a v1.Node instance that is ready
36
46
// to be sent to the API server.
37
47
type NodeTemplate interface {
38
48
// 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
43
51
// for example a named reference to some other object.
44
52
GetNodeTemplate (index , count int ) (* v1.Node , error )
45
53
}
@@ -87,7 +95,7 @@ func (p *IntegrationTestNodePreparer) PrepareNodes(ctx context.Context, nextNode
87
95
if err != nil {
88
96
return fmt .Errorf ("failed to get node template: %w" , err )
89
97
}
90
- for retry := 0 ; retry < retries ; retry ++ {
98
+ for retry := 0 ; retry < createNodeRetries ; retry ++ {
91
99
// Create nodes with the usual kubernetes.io/hostname label.
92
100
// For that we need to know the name in advance, if we want to
93
101
// do it in one request.
@@ -111,7 +119,7 @@ func (p *IntegrationTestNodePreparer) PrepareNodes(ctx context.Context, nextNode
111
119
}
112
120
}
113
121
114
- nodes , err := waitListAllNodes (p .client )
122
+ nodes , err := waitListAllNodes (ctx , p .client )
115
123
if err != nil {
116
124
return fmt .Errorf ("listing nodes: %w" , err )
117
125
}
@@ -130,7 +138,7 @@ func (p *IntegrationTestNodePreparer) PrepareNodes(ctx context.Context, nextNode
130
138
func (p * IntegrationTestNodePreparer ) CleanupNodes (ctx context.Context ) error {
131
139
// TODO(#93794): make CleanupNodes only clean up the nodes created by this
132
140
// IntegrationTestNodePreparer to make this more intuitive.
133
- nodes , err := waitListAllNodes (p .client )
141
+ nodes , err := waitListAllNodes (ctx , p .client )
134
142
if err != nil {
135
143
klog .Fatalf ("Error listing nodes: %v" , err )
136
144
}
@@ -143,3 +151,19 @@ func (p *IntegrationTestNodePreparer) CleanupNodes(ctx context.Context) error {
143
151
}
144
152
return errRet
145
153
}
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
+ }
0 commit comments