@@ -51,7 +51,7 @@ type Provider struct {
5151 once sync.Once
5252 lock sync.RWMutex
5353 indexers []index
54- prefixCh chan string
54+ providerNameCh chan string
5555 providers map [string ]multicluster.Provider
5656 providersCancel map [string ]context.CancelFunc
5757}
@@ -97,73 +97,73 @@ func (p *Provider) start(ctx context.Context, aware multicluster.Aware) {
9797 p .log .Info ("starting multi provider" )
9898
9999 p .lock .Lock ()
100- p .prefixCh = make (chan string , p .opts .ChannelSize )
101- prefixes := slices .Collect (maps .Keys (p .providers ))
100+ p .providerNameCh = make (chan string , p .opts .ChannelSize )
101+ providerNames := slices .Collect (maps .Keys (p .providers ))
102102 p .lock .Unlock ()
103103
104- for _ , prefix := range prefixes {
105- p .startProvider (ctx , prefix , aware )
104+ for _ , providerName := range providerNames {
105+ p .startProvider (ctx , providerName , aware )
106106 }
107107
108108 for {
109109 select {
110110 case <- ctx .Done ():
111111 return
112- case prefix := <- p .prefixCh :
113- p .startProvider (ctx , prefix , aware )
112+ case providerName := <- p .providerNameCh :
113+ p .startProvider (ctx , providerName , aware )
114114 }
115115 }
116116}
117117
118- func (p * Provider ) startProvider (ctx context.Context , prefix string , aware multicluster.Aware ) {
119- p .log .Info ("starting provider" , "prefix " , prefix )
118+ func (p * Provider ) startProvider (ctx context.Context , providerName string , aware multicluster.Aware ) {
119+ p .log .Info ("starting provider" , "providerName " , providerName )
120120
121121 p .lock .RLock ()
122- provider , ok := p .providers [prefix ]
122+ provider , ok := p .providers [providerName ]
123123 p .lock .RUnlock ()
124124 if ! ok {
125- p .log .Error (nil , "provider not found" , "prefix " , prefix )
125+ p .log .Error (nil , "provider not found" , "providerName " , providerName )
126126 return
127127 }
128128
129129 runnable , ok := provider .(multicluster.ProviderRunnable )
130130 if ! ok {
131- p .log .Info ("provider is not runnable, not starting" , "prefix " , prefix )
131+ p .log .Info ("provider is not runnable, not starting" , "providerName " , providerName )
132132 return
133133 }
134134
135135 ctx , cancel := context .WithCancel (ctx )
136136
137137 wrappedAware := & wrappedAware {
138- Aware : aware ,
139- prefix : prefix ,
140- sep : p .opts .Separator ,
138+ Aware : aware ,
139+ providerName : providerName ,
140+ sep : p .opts .Separator ,
141141 }
142142
143143 p .lock .Lock ()
144- if _ , ok := p .providersCancel [prefix ]; ok {
144+ if _ , ok := p .providersCancel [providerName ]; ok {
145145 // This is a failsafe. It should never happen but on the off
146146 // change that it somehow does the provider shouldn't be started
147147 // twice.
148148 cancel ()
149- p .log .Error (nil , "provider already started, not starting again" , "prefix " , prefix )
149+ p .log .Error (nil , "provider already started, not starting again" , "providerName " , providerName )
150150 p .lock .Unlock ()
151151 return
152152 }
153- p .providersCancel [prefix ] = cancel
153+ p .providersCancel [providerName ] = cancel
154154 p .lock .Unlock ()
155155
156156 go func () {
157- defer p .RemoveProvider (prefix )
157+ defer p .RemoveProvider (providerName )
158158 if err := runnable .Start (ctx , wrappedAware ); err != nil {
159- p .log .Error (err , "error in provider" , "prefix " , prefix )
159+ p .log .Error (err , "error in provider" , "providerName " , providerName )
160160 }
161161 }()
162162
163163 p .lock .RLock ()
164164 for _ , indexer := range p .indexers {
165165 if err := provider .IndexField (ctx , indexer .Object , indexer .Field , indexer .Extractor ); err != nil {
166- p .log .Error (err , "failed to apply indexer to provider" , "prefix " , prefix , "object" , fmt .Sprintf ("%T" , indexer .Object ), "field" , indexer .Field )
166+ p .log .Error (err , "failed to apply indexer to provider" , "providerName " , providerName , "object" , fmt .Sprintf ("%T" , indexer .Object ), "field" , indexer .Field )
167167 }
168168 }
169169 p .lock .RUnlock ()
@@ -177,36 +177,36 @@ func (p *Provider) splitClusterName(clusterName string) (string, string) {
177177 return parts [0 ], parts [1 ]
178178}
179179
180- // GetProvider returns the provider for the given prefix .
181- func (p * Provider ) GetProvider (prefix string ) (multicluster.Provider , bool ) {
180+ // GetProvider returns the provider for the given provider name .
181+ func (p * Provider ) GetProvider (providerName string ) (multicluster.Provider , bool ) {
182182 p .lock .RLock ()
183183 defer p .lock .RUnlock ()
184- provider , ok := p .providers [prefix ]
184+ provider , ok := p .providers [providerName ]
185185 return provider , ok
186186}
187187
188- // AddProvider adds a new provider with the given prefix .
188+ // AddProvider adds a new provider with the given provider name .
189189//
190190// The startFunc is called to start the provider - starting the provider
191191// outside of startFunc is an error and will result in undefined
192192// behaviour.
193193// startFunc should block for as long as the provider is running,
194194// If startFunc returns an error the provider is removed and the error
195195// is returned.
196- func (p * Provider ) AddProvider (prefix string , provider multicluster.Provider ) error {
196+ func (p * Provider ) AddProvider (providerName string , provider multicluster.Provider ) error {
197197 p .lock .Lock ()
198198 defer p .lock .Unlock ()
199199
200- _ , ok := p .providers [prefix ]
200+ _ , ok := p .providers [providerName ]
201201 if ok {
202- return fmt .Errorf ("provider already exists for prefix %q" , prefix )
202+ return fmt .Errorf ("provider already exists for provider name %q" , providerName )
203203 }
204204
205- p .log .Info ("adding provider" , "prefix " , prefix )
205+ p .log .Info ("adding provider" , "providerName " , providerName )
206206
207- p .providers [prefix ] = provider
208- if p .prefixCh != nil {
209- p .prefixCh <- prefix
207+ p .providers [providerName ] = provider
208+ if p .providerNameCh != nil {
209+ p .providerNameCh <- providerName
210210 }
211211
212212 return nil
@@ -218,33 +218,33 @@ func (p *Provider) AddProvider(prefix string, provider multicluster.Provider) er
218218// Warning: This can lead to dangling clusters if the provider is not
219219// using the context it is started with to engage the clusters it
220220// manages.
221- func (p * Provider ) RemoveProvider (prefix string ) {
221+ func (p * Provider ) RemoveProvider (providerName string ) {
222222 p .lock .Lock ()
223223 defer p .lock .Unlock ()
224224
225- if cancel , ok := p .providersCancel [prefix ]; ok {
225+ if cancel , ok := p .providersCancel [providerName ]; ok {
226226 cancel ()
227- delete (p .providersCancel , prefix )
227+ delete (p .providersCancel , providerName )
228228 }
229229
230- if _ , ok := p .providers [prefix ]; ! ok {
231- p .log .Info ("provider not found when removing" , "prefix " , prefix )
230+ if _ , ok := p .providers [providerName ]; ! ok {
231+ p .log .Info ("provider not found when removing" , "providerName " , providerName )
232232 }
233- delete (p .providers , prefix )
233+ delete (p .providers , providerName )
234234}
235235
236236// Get returns a cluster by name.
237237func (p * Provider ) Get (ctx context.Context , clusterName string ) (cluster.Cluster , error ) {
238- prefix , clusterName := p .splitClusterName (clusterName )
239- p .log .V (1 ).Info ("getting cluster" , "prefix " , prefix , "name" , clusterName )
238+ providerName , clusterName := p .splitClusterName (clusterName )
239+ p .log .V (1 ).Info ("getting cluster" , "providerName " , providerName , "name" , clusterName )
240240
241241 p .lock .RLock ()
242- provider , ok := p .providers [prefix ]
242+ provider , ok := p .providers [providerName ]
243243 p .lock .RUnlock ()
244244
245245 if ! ok {
246- p .log .Error (multicluster .ErrClusterNotFound , "provider not found for prefix " , "prefix " , prefix )
247- return nil , fmt .Errorf ("provider not found %q: %w" , prefix , multicluster .ErrClusterNotFound )
246+ p .log .Error (multicluster .ErrClusterNotFound , "provider not found for provider name " , "providerName " , providerName )
247+ return nil , fmt .Errorf ("provider not found %q: %w" , providerName , multicluster .ErrClusterNotFound )
248248 }
249249
250250 return provider .Get (ctx , clusterName )
@@ -261,11 +261,11 @@ func (p *Provider) IndexField(ctx context.Context, obj client.Object, field stri
261261 Extractor : extractValue ,
262262 })
263263 var errs error
264- for prefix , provider := range p .providers {
264+ for providerName , provider := range p .providers {
265265 if err := provider .IndexField (ctx , obj , field , extractValue ); err != nil {
266266 errs = errors .Join (
267267 errs ,
268- fmt .Errorf ("failed to index field %q on cluster %q: %w" , field , prefix , err ),
268+ fmt .Errorf ("failed to index field %q on cluster %q: %w" , field , providerName , err ),
269269 )
270270 }
271271 }
0 commit comments