Unistore: Avoid circular dependency when injecting restcfgprovider into FolderSvc (#99295)

* Avoid circular dependency when getting a restCfgProvider for Folder Svc

Signed-off-by: Maicon Costa <maiconscosta@gmail.com>

---------

Signed-off-by: Maicon Costa <maiconscosta@gmail.com>
This commit is contained in:
maicon
2025-01-21 17:42:38 -03:00
committed by GitHub
parent 1c858caec3
commit 45e2f95a41
6 changed files with 69 additions and 26 deletions
+21
View File
@@ -71,6 +71,10 @@ var (
&metav1.PartialObjectMetadata{},
&metav1.PartialObjectMetadataList{},
}
// internal provider of the package level client Config
restConfig RestConfigProvider
ready = make(chan struct{})
)
func init() {
@@ -79,6 +83,17 @@ func init() {
Scheme.AddUnversionedTypes(unversionedVersion, unversionedTypes...)
}
// GetRestConfig return a client Config mounted at package level
// This resolves circular dependency issues between apiserver, authz,
// and Folder Service.
// The client Config gets initialized during the first call to
// ProvideService.
// Any call to GetRestConfig will block until we have a restConfig available
func GetRestConfig(ctx context.Context) *clientrest.Config {
<-ready
return restConfig.GetRestConfig(ctx)
}
type Service interface {
services.NamedService
registry.BackgroundService
@@ -210,6 +225,12 @@ func ProvideService(
s.rr.Group("/openapi", proxyHandler)
s.rr.Group("/version", proxyHandler)
// only set the package level restConfig once
if restConfig == nil {
restConfig = s
close(ready)
}
return s, nil
}