Skip to content

Commit 25d3e17

Browse files
committed
SQUASH: address comments
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
1 parent fe69d96 commit 25d3e17

File tree

10 files changed

+54
-49
lines changed

10 files changed

+54
-49
lines changed

examples/fleet/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (k *KindClusterProvider) Get(ctx context.Context, clusterName string, opts
110110
return cluster.New(cfg, opts...)
111111
}
112112

113-
func (k *KindClusterProvider) List() ([]string, error) {
113+
func (k *KindClusterProvider) List(ctx context.Context) ([]string, error) {
114114
provider := kind.NewProvider()
115115
list, err := provider.List()
116116
if err != nil {
@@ -144,6 +144,7 @@ func (k *KindWatcher) Stop() {
144144
k.wg.Wait()
145145
close(k.ch)
146146
}
147+
147148
func (k *KindWatcher) ResultChan() <-chan cluster.WatchEvent {
148149
k.init.Do(func() {
149150
ctx, cancel := context.WithCancel(context.Background())

pkg/builder/controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,12 @@ func (blder *Builder) doWatch() error {
332332
}
333333
srcKind.Type = typeForSrc
334334
} else if !ok {
335-
// If we're building a logical controller, raw watches are not allowed
336-
// given that the cache cannot be validated to be coming from the same cluter.
335+
// If we're building a cluster-aware controller, raw watches are not allowed
336+
// given that the cache cannot be validated to be coming from the same cluster.
337337
// In the future, we could consider allowing this by satisfying a new interface
338338
// that sets and uses the cluster.
339339
if blder.clusterName != "" {
340-
return fmt.Errorf("when using a logical adapter, custom raw watches %T are not allowed", w.src)
340+
return fmt.Errorf("when using a cluster adapter, custom raw watches %T are not allowed", w.src)
341341
}
342342
}
343343
allPredicates := append([]predicate.Predicate(nil), blder.globalPredicates...)

pkg/builder/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ var _ = Describe("application", func() {
558558
})
559559
})
560560

561-
Context("with logical adapter", func() {
561+
Context("with cluster provider", func() {
562562
It("should support watching across clusters", func() {
563563
adapter := &fakeClusterProvider{
564564
clusterNameList: []string{
@@ -847,7 +847,7 @@ func (f *fakeClusterProvider) Get(ctx context.Context, clusterName string, opts
847847
return cluster.New(testenv.Config, opts...)
848848
}
849849

850-
func (f *fakeClusterProvider) List() ([]string, error) {
850+
func (f *fakeClusterProvider) List(ctx context.Context) ([]string, error) {
851851
return f.clusterNameList, f.listErr
852852
}
853853

pkg/cluster/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type AwareDeepCopy[T any] interface {
6464
DeepCopyFor(Cluster) T
6565
}
6666

67-
// ByNameGetterFunc is a function that returns a cluster for a given logical cluster name.
67+
// ByNameGetterFunc is a function that returns a cluster for a given identifying cluster name.
6868
type ByNameGetterFunc func(ctx context.Context, clusterName string) (Cluster, error)
6969

7070
// Cluster provides various methods to interact with a cluster.

pkg/cluster/provider.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ import (
1414
// clusters that are backed by Cluster API resources, which can live
1515
// in multiple namespaces in a single management cluster.
1616
type Provider interface {
17+
// Get returns a cluster for the given identifying cluster name. The
18+
// options are passed to the cluster constructor in case the cluster has
19+
// not been created yet. Get returns an existing cluster if it has been
20+
// created before.
1721
Get(ctx context.Context, clusterName string, opts ...Option) (Cluster, error)
1822

19-
// List returns a list of logical clusters.
20-
// This method is used to discover the initial set of logical clusters
21-
// and to refresh the list of logical clusters periodically.
22-
List() ([]string, error)
23+
// List returns a list of known identifying clusters names.
24+
// This method is used to discover the initial set of known cluster names
25+
// and to refresh the list of cluster names periodically.
26+
List(ctx context.Context) ([]string, error)
2327

24-
// Watch returns a Watcher that watches for changes to a list of logical clusters
28+
// Watch returns a Watcher that watches for changes to a list of known clusters
2529
// and react to potential changes.
2630
Watch() (Watcher, error)
2731
}
@@ -44,15 +48,15 @@ type WatchEvent struct {
4448
// Type is the type of event that occurred.
4549
//
4650
// - ADDED or MODIFIED
47-
// The logical cluster was added or updated: a new RESTConfig is available, or needs to be refreshed.
51+
// The cluster was added or updated: a new RESTConfig is available, or needs to be refreshed.
4852
// - DELETED
49-
// The logical cluster was deleted: the cluster is removed.
53+
// The cluster was deleted: the cluster is removed.
5054
// - ERROR
51-
// An error occurred while watching the logical cluster: the cluster is removed.
55+
// An error occurred while watching the cluster: the cluster is removed.
5256
// - BOOKMARK
5357
// A periodic event is sent that contains no new data: ignored.
5458
Type watch.EventType
5559

56-
// ClusterName is the name of the cluster related to the event.
60+
// ClusterName is the identifying name of the cluster related to the event.
5761
ClusterName string
5862
}

pkg/handler/enqueue_mapped.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (e *enqueueRequestsFromMapFunc) mapAndEnqueue(ctx context.Context, q workqu
8686
// reqs is a map of requests to avoid enqueueing the same request multiple times.
8787
continue
8888
}
89-
// If the request doesn't specify a cluster, use the cluster from the context.
89+
// If the request doesn't specify a cluster, use the cluster from the handler.
9090
if req.ClusterName == "" && e.cluster != nil {
9191
req.ClusterName = e.cluster.Name()
9292
}

pkg/internal/controller/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type Controller struct {
8484
// clusterAwareWatches maintains a list of cluster aware sources, handlers, and predicates to start when the controller is started.
8585
clusterAwareWatches []*watchDescription
8686

87-
// clustersByName is used to manage the logical clustersByName.
87+
// clustersByName is used to manage the fleet of clusters.
8888
clustersByName map[string]*clusterDescription
8989

9090
// LogConstructor is used to construct a logger to then log messages to users during reconciliation,

pkg/manager/internal.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var _ Runnable = &controllerManager{}
6565
var _ Manager = &controllerManager{}
6666
var _ cluster.ByNameGetterFunc = (&controllerManager{}).GetCluster
6767

68-
type logicalCluster struct {
68+
type engagedCluster struct {
6969
cluster.Cluster
7070
ctx context.Context
7171
cancel context.CancelFunc
@@ -83,10 +83,10 @@ type controllerManager struct {
8383
defaultCluster cluster.Cluster
8484
defaultClusterOptions cluster.Option
8585

86-
logicalProvider cluster.Provider
86+
clusterProvider cluster.Provider
8787

8888
clusterLock sync.RWMutex // protects clusters
89-
clusters map[string]*logicalCluster
89+
clusters map[string]*engagedCluster
9090
clusterAwareRunnables []cluster.AwareRunnable
9191

9292
// recorderProvider is used to generate event recorders that will be injected into Controllers
@@ -282,8 +282,8 @@ func (cm *controllerManager) engageClusterAwareRunnables() {
282282
cm.Lock()
283283
defer cm.Unlock()
284284

285-
// If we don't have a logical adapter, we cannot sync the runnables.
286-
if cm.logicalProvider == nil {
285+
// If we don't have a cluster provider, we cannot sync the runnables.
286+
if cm.clusterProvider == nil {
287287
return
288288
}
289289

@@ -299,11 +299,11 @@ func (cm *controllerManager) engageClusterAwareRunnables() {
299299
}
300300
}
301301

302-
func (cm *controllerManager) getCluster(ctx context.Context, clusterName string) (c *logicalCluster, err error) {
303-
// Check if the manager was configured with a logical adapter,
302+
func (cm *controllerManager) getCluster(ctx context.Context, clusterName string) (c *engagedCluster, err error) {
303+
// Check if the manager was configured with a cluster provider,
304304
// otherwise we cannot retrieve the cluster.
305-
if cm.logicalProvider == nil {
306-
return nil, fmt.Errorf("manager was not configured with a logical adapter, cannot retrieve %q", clusterName)
305+
if cm.clusterProvider == nil {
306+
return nil, fmt.Errorf("manager was not configured with a cluster provider, cannot retrieve %q", clusterName)
307307
}
308308

309309
// Check if the cluster already exists.
@@ -332,13 +332,13 @@ func (cm *controllerManager) getCluster(ctx context.Context, clusterName string)
332332
defer cancel()
333333
var watchErr error
334334
if err := wait.PollImmediateUntilWithContext(ctx, 1*time.Second, func(ctx context.Context) (done bool, err error) {
335-
cl, watchErr = cm.logicalProvider.Get(ctx, clusterName, cm.defaultClusterOptions, cluster.WithName(clusterName))
335+
cl, watchErr = cm.clusterProvider.Get(ctx, clusterName, cm.defaultClusterOptions, cluster.WithName(clusterName))
336336
if watchErr != nil {
337337
return false, nil //nolint:nilerr // We want to keep trying.
338338
}
339339
return true, nil
340340
}); err != nil {
341-
return nil, fmt.Errorf("failed create logical cluster %q: %w", clusterName, kerrors.NewAggregate([]error{err, watchErr}))
341+
return nil, fmt.Errorf("failed create cluster %q: %w", clusterName, kerrors.NewAggregate([]error{err, watchErr}))
342342
}
343343
}
344344

@@ -348,11 +348,11 @@ func (cm *controllerManager) getCluster(ctx context.Context, clusterName string)
348348
// Once added, if the manager has already started, it waits for the Cache to sync before returning
349349
// otherwise it enqueues the Runnable to be started when the manager starts.
350350
if err := cm.Add(cl); err != nil {
351-
return nil, fmt.Errorf("cannot add logical cluster %q to manager: %w", clusterName, err)
351+
return nil, fmt.Errorf("cannot add cluster %q to manager: %w", clusterName, err)
352352
}
353353
// Create a new context for the Cluster, so that it can be stopped independently.
354354
ctx, cancel := context.WithCancel(context.Background())
355-
c = &logicalCluster{
355+
c = &engagedCluster{
356356
Cluster: cl,
357357
ctx: ctx,
358358
cancel: cancel,
@@ -364,8 +364,8 @@ func (cm *controllerManager) getCluster(ctx context.Context, clusterName string)
364364
func (cm *controllerManager) removeLogicalCluster(clusterName string) error {
365365
// Check if the manager was configured with a logical adapter,
366366
// otherwise we cannot retrieve the cluster.
367-
if cm.logicalProvider == nil {
368-
return fmt.Errorf("manager was not configured with a logical adapter, cannot retrieve %q", clusterName)
367+
if cm.clusterProvider == nil {
368+
return fmt.Errorf("manager was not configured with a cluster provider, cannot retrieve %q", clusterName)
369369
}
370370

371371
cm.clusterLock.Lock()
@@ -578,11 +578,11 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) { //nolint:g
578578
}()
579579
}
580580

581-
// If the manager has been configured with a logical adapter, start it.
582-
if cm.logicalProvider != nil {
581+
// If the manager has been configured with a cluster provider, start it.
582+
if cm.clusterProvider != nil {
583583
if err := cm.add(RunnableFunc(func(ctx context.Context) error {
584584
resync := func() error {
585-
clusterList, err := cm.logicalProvider.List()
585+
clusterList, err := cm.clusterProvider.List(ctx)
586586
if err != nil {
587587
return err
588588
}
@@ -610,7 +610,7 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) { //nolint:g
610610
}
611611

612612
// Create a watcher and start watching for changes.
613-
watcher, err := cm.logicalProvider.Watch()
613+
watcher, err := cm.clusterProvider.Watch()
614614
if err != nil {
615615
return err
616616
}
@@ -648,7 +648,7 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) { //nolint:g
648648
}
649649
}
650650
})); err != nil {
651-
return fmt.Errorf("failed to add logical adapter to runnables: %w", err)
651+
return fmt.Errorf("failed to add cluster provider to runnables: %w", err)
652652
}
653653
}
654654

pkg/manager/manager.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type Manager interface {
7979
// lock was lost.
8080
Start(ctx context.Context) error
8181

82-
// GetCluster retrieves a Cluster from a given logical name.
82+
// GetCluster retrieves a Cluster from a given identifying cluster name.
8383
GetCluster(ctx context.Context, clusterName string) (cluster.Cluster, error)
8484

8585
// GetWebhookServer returns a webhook.Server
@@ -277,10 +277,10 @@ type Options struct {
277277
newHealthProbeListener func(addr string) (net.Listener, error)
278278
newPprofListener func(addr string) (net.Listener, error)
279279

280-
// logicalClusterProvider is an EXPERIMENTAL feature that allows the manager to
280+
// clusterProvider is an EXPERIMENTAL feature that allows the manager to
281281
// operate against many Kubernetes clusters at once.
282-
// It can be used by invoking WithExperimentalLogicalAdapter(adapter) on Options.
283-
logicalClusterProvider cluster.Provider
282+
// It can be used by invoking WithExperimentalClusterProvider(adapter) on Options.
283+
clusterProvider cluster.Provider
284284
}
285285

286286
// BaseContextFunc is a function used to provide a base Context to Runnables
@@ -422,8 +422,8 @@ func New(config *rest.Config, options Options) (Manager, error) {
422422
stopProcedureEngaged: ptr.To(int64(0)),
423423
defaultCluster: cluster,
424424
defaultClusterOptions: clusterOptions,
425-
logicalProvider: options.logicalClusterProvider,
426-
clusters: make(map[string]*logicalCluster),
425+
clusterProvider: options.clusterProvider,
426+
clusters: make(map[string]*engagedCluster),
427427
runnables: newRunnables(options.BaseContext, errChan),
428428
errChan: errChan,
429429
recorderProvider: recorderProvider,
@@ -531,13 +531,13 @@ func (o Options) AndFromOrDie(loader config.ControllerManagerConfiguration) Opti
531531
return o
532532
}
533533

534-
// WithExperimentalClusterProvider sets the logical adapter to use for the manager.
534+
// WithExperimentalClusterProvider sets the cluster adapter to use for the manager.
535535
// This is an EXPERIMENTAL feature that allows a Manager to be used against a fleet
536536
// of Kubernetes clusters.
537537
//
538538
// NOTE: The method signature may change or be removed in the future.
539539
func (o Options) WithExperimentalClusterProvider(provider cluster.Provider) Options {
540-
o.logicalClusterProvider = provider
540+
o.clusterProvider = provider
541541
return o
542542
}
543543

pkg/manager/manager_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,8 +1849,8 @@ var _ = Describe("manger.Manager", func() {
18491849
Expect(m.GetAPIReader()).NotTo(BeNil())
18501850
})
18511851

1852-
Context("with logical clusters", func() {
1853-
It("should be able to create a manager with a logical cluster", func() {
1852+
Context("with cluster provider", func() {
1853+
It("should be able to create a manager with a cluster provider", func() {
18541854
adapter := &fakeClusterAdapter{
18551855
clusterNameList: []string{
18561856
"test-cluster",
@@ -2027,7 +2027,7 @@ func (f *fakeClusterAdapter) Get(ctx context.Context, clusterName string, opts .
20272027
return cluster.New(testenv.Config, opts...)
20282028
}
20292029

2030-
func (f *fakeClusterAdapter) List() ([]string, error) {
2030+
func (f *fakeClusterAdapter) List(ctx context.Context) ([]string, error) {
20312031
return f.clusterNameList, f.listErr
20322032
}
20332033

0 commit comments

Comments
 (0)