Replace *core.Factory with CoreFactory interface

Make this field an interface instead of pointer to allow mocking. Not sure why wrangler has a type that returns an interface instead of just making it an interface itself. Wrangler in general is hard to mock for testing.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
(cherry picked from commit e6327652f0)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
Brad Davidson
2024-12-17 23:23:54 +00:00
committed by Brad Davidson
parent 7f8f469a29
commit ba74aa8a1a
3 changed files with 43 additions and 4 deletions

View File

@@ -141,9 +141,13 @@ func (c *Cluster) initClusterAndHTTPS(ctx context.Context) error {
func tlsStorage(ctx context.Context, dataDir string, runtime *config.ControlRuntime) dynamiclistener.TLSStorage {
fileStorage := file.New(filepath.Join(dataDir, "tls/dynamic-cert.json"))
cache := memory.NewBacked(fileStorage)
return kubernetes.New(ctx, func() *core.Factory {
return runtime.Core
}, metav1.NamespaceSystem, version.Program+"-serving", cache)
coreGetter := func() *core.Factory {
if coreFactory, ok := runtime.Core.(*core.Factory); ok {
return coreFactory
}
return nil
}
return kubernetes.New(ctx, coreGetter, metav1.NamespaceSystem, version.Program+"-serving", cache)
}
// wrapHandler wraps the dynamiclistener request handler, adding a User-Agent value to