Skip to content

Commit f964c89

Browse files
committed
pass data sources in ctor
Signed-off-by: Etai Lev Ran <[email protected]>
1 parent e6053bc commit f964c89

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

pkg/epp/datalayer/factory.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ import (
2121
"sync"
2222
"time"
2323

24-
"github.com/go-logr/logr"
2524
corev1 "k8s.io/api/core/v1"
2625
"k8s.io/apimachinery/pkg/types"
27-
2826
"sigs.k8s.io/controller-runtime/pkg/log"
27+
2928
v1 "sigs.k8s.io/gateway-api-inference-extension/api/v1"
3029
)
3130

@@ -60,14 +59,17 @@ type EndpointLifecycle struct {
6059

6160
// NewEndpointFactory returns a new endpoint for factory, managing collectors for
6261
// its endpoints.
63-
// TODO: consider making a config object? Only caveat is that sources might not be
64-
// known at creation time (e.g., loaded from configuration file).
65-
func NewEndpointFactory(log logr.Logger, refreshMetricsInterval time.Duration) *EndpointLifecycle {
66-
return &EndpointLifecycle{
67-
sources: []DataSource{},
62+
// Sources might not be known at creation time (e.g., loaded from configuration
63+
// file), so they're not passed at this point.
64+
func NewEndpointFactory(sources []DataSource, refreshMetricsInterval time.Duration) *EndpointLifecycle {
65+
lc := &EndpointLifecycle{
66+
sources: make([]DataSource, len(sources)),
6867
collectors: sync.Map{},
6968
refreshInterval: refreshMetricsInterval,
7069
}
70+
_ = copy(lc.sources, sources)
71+
72+
return lc
7173
}
7274

7375
// NewEndpoint implements EndpointFactory.NewEndpoint.
@@ -115,17 +117,10 @@ func (lc *EndpointLifecycle) ReleaseEndpoint(ep Endpoint) {
115117

116118
// Shutdown gracefully stops all collectors and cleans up all resources.
117119
func (lc *EndpointLifecycle) Shutdown() {
118-
lc.collectors.Range(func(key, value interface{}) bool {
120+
lc.collectors.Range(func(key, value any) bool {
119121
collector := value.(*Collector)
120122
_ = collector.Stop()
121123
lc.collectors.Delete(key)
122124
return true
123125
})
124126
}
125-
126-
// SetSources configures the data sources available for collection.
127-
// This should be called after all data sources have been configured and before
128-
// any endpoint is created.
129-
func (lc *EndpointLifecycle) SetSources(sources []DataSource) {
130-
_ = copy(lc.sources, sources)
131-
}

0 commit comments

Comments
 (0)