@@ -345,13 +345,21 @@ func (t *ClusterCacheTracker) createClient(ctx context.Context, config *rest.Con
345
345
// Create a http client for the cluster.
346
346
httpClient , err := rest .HTTPClientFor (config )
347
347
if err != nil {
348
- return nil , nil , errors .Wrapf (err , "error creating http client for remote cluster %q" , cluster .String ())
348
+ return nil , nil , errors .Wrapf (err , "error creating client for remote cluster %q: error creating http client " , cluster .String ())
349
349
}
350
350
351
351
// Create a mapper for it
352
352
mapper , err := apiutil .NewDynamicRESTMapper (config , httpClient )
353
353
if err != nil {
354
- return nil , nil , errors .Wrapf (err , "error creating dynamic rest mapper for remote cluster %q" , cluster .String ())
354
+ return nil , nil , errors .Wrapf (err , "error creating client for remote cluster %q: error creating dynamic rest mapper" , cluster .String ())
355
+ }
356
+
357
+ // Verify if we can get a rest mapping from the workload cluster apiserver.
358
+ // Note: This also checks if the apiserver is up in general. We do this already here
359
+ // to avoid further effort creating a cache and a client and to produce a clearer error message.
360
+ _ , err = mapper .RESTMapping (corev1 .SchemeGroupVersion .WithKind ("Node" ).GroupKind (), corev1 .SchemeGroupVersion .Version )
361
+ if err != nil {
362
+ return nil , nil , errors .Wrapf (err , "error creating client for remote cluster %q: error getting rest mapping" , cluster .String ())
355
363
}
356
364
357
365
// Create the cache for the remote cluster
@@ -362,7 +370,7 @@ func (t *ClusterCacheTracker) createClient(ctx context.Context, config *rest.Con
362
370
}
363
371
remoteCache , err := cache .New (config , cacheOptions )
364
372
if err != nil {
365
- return nil , nil , errors .Wrapf (err , "error creating cache for remote cluster %q" , cluster .String ())
373
+ return nil , nil , errors .Wrapf (err , "error creating client for remote cluster %q: error creating cache " , cluster .String ())
366
374
}
367
375
368
376
cacheCtx , cacheCtxCancel := context .WithCancel (ctx )
0 commit comments