@@ -58,6 +58,11 @@ func TestGetNode(t *testing.T) {
58
58
}
59
59
60
60
g .Expect (env .Create (ctx , testCluster )).To (Succeed ())
61
+ // Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
62
+ patch := client .MergeFrom (testCluster .DeepCopy ())
63
+ testCluster .Status .InfrastructureReady = true
64
+ g .Expect (env .Status ().Patch (ctx , testCluster , patch )).To (Succeed ())
65
+
61
66
g .Expect (env .CreateKubeconfigSecret (ctx , testCluster )).To (Succeed ())
62
67
defer func (do ... client.Object ) {
63
68
g .Expect (env .Cleanup (ctx , do ... )).To (Succeed ())
@@ -137,7 +142,7 @@ func TestGetNode(t *testing.T) {
137
142
Client : clustercache.ClientOptions {
138
143
UserAgent : remote .DefaultClusterAPIUserAgent ("test-controller-manager" ),
139
144
},
140
- }, controller.Options {MaxConcurrentReconciles : 10 })
145
+ }, controller.Options {MaxConcurrentReconciles : 10 , SkipNameValidation : ptr . To ( true ) })
141
146
if err != nil {
142
147
panic (fmt .Sprintf ("Failed to create new cluster cache tracker: %v" , err ))
143
148
}
@@ -150,15 +155,18 @@ func TestGetNode(t *testing.T) {
150
155
w , err := ctrl .NewControllerManagedBy (env .Manager ).For (& corev1.Node {}).Build (r )
151
156
g .Expect (err ).ToNot (HaveOccurred ())
152
157
153
- g .Expect (clusterCache .Watch (ctx , clustercache.WatchInput {
154
- Name : "TestGetNode" ,
155
- Cluster : util .ObjectKey (testCluster ),
156
- Watcher : w ,
157
- Kind : & corev1.Node {},
158
- EventHandler : handler .EnqueueRequestsFromMapFunc (func (context.Context , client.Object ) []reconcile.Request {
159
- return nil
160
- }),
161
- })).To (Succeed ())
158
+ // Retry because the ClusterCache might not have immediately created the clusterAccessor.
159
+ g .Eventually (func (g Gomega ) {
160
+ g .Expect (clusterCache .Watch (ctx , clustercache.WatchInput {
161
+ Name : "TestGetNode" ,
162
+ Cluster : util .ObjectKey (testCluster ),
163
+ Watcher : w ,
164
+ Kind : & corev1.Node {},
165
+ EventHandler : handler .EnqueueRequestsFromMapFunc (func (context.Context , client.Object ) []reconcile.Request {
166
+ return nil
167
+ }),
168
+ })).To (Succeed ())
169
+ }, 1 * time .Minute , 5 * time .Second ).Should (Succeed ())
162
170
163
171
for _ , tc := range testCases {
164
172
t .Run (tc .name , func (t * testing.T ) {
@@ -339,7 +347,11 @@ func TestNodeLabelSync(t *testing.T) {
339
347
340
348
g .Expect (env .Create (ctx , cluster )).To (Succeed ())
341
349
defaultKubeconfigSecret := kubeconfig .GenerateSecret (cluster , kubeconfig .FromEnvTestConfig (env .Config , cluster ))
342
- g .Expect (env .Create (ctx , defaultKubeconfigSecret )).To (Succeed ())
350
+ g .Expect (env .CreateAndWait (ctx , defaultKubeconfigSecret )).To (Succeed ())
351
+ // Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
352
+ patch := client .MergeFrom (cluster .DeepCopy ())
353
+ cluster .Status .InfrastructureReady = true
354
+ g .Expect (env .Status ().Patch (ctx , cluster , patch )).To (Succeed ())
343
355
344
356
g .Expect (env .Create (ctx , infraMachine )).To (Succeed ())
345
357
// Set InfrastructureMachine .status.interruptible and .status.ready to true.
0 commit comments