Skip to content

Commit 119bf15

Browse files
committed
ClusterCacheTracker: improve error when workload cluster is not
reachable Signed-off-by: Stefan Büringer [email protected]
1 parent dc5f916 commit 119bf15

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

controllers/remote/cluster_cache_tracker.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,21 @@ func (t *ClusterCacheTracker) createClient(ctx context.Context, config *rest.Con
345345
// Create a http client for the cluster.
346346
httpClient, err := rest.HTTPClientFor(config)
347347
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())
349349
}
350350

351351
// Create a mapper for it
352352
mapper, err := apiutil.NewDynamicRESTMapper(config, httpClient)
353353
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())
355363
}
356364

357365
// Create the cache for the remote cluster
@@ -362,7 +370,7 @@ func (t *ClusterCacheTracker) createClient(ctx context.Context, config *rest.Con
362370
}
363371
remoteCache, err := cache.New(config, cacheOptions)
364372
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())
366374
}
367375

368376
cacheCtx, cacheCtxCancel := context.WithCancel(ctx)

0 commit comments

Comments
 (0)