Skip to content

Commit 9f4472c

Browse files
committed
SQUASH: fixes and cleanup
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
1 parent 25d3e17 commit 9f4472c

File tree

7 files changed

+26
-10
lines changed

7 files changed

+26
-10
lines changed

pkg/cluster/cluster.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ type ByNameGetterFunc func(ctx context.Context, clusterName string) (Cluster, er
6969

7070
// Cluster provides various methods to interact with a cluster.
7171
type Cluster interface {
72-
// Name returns the identifying name of the cluster.
72+
// Name returns the name of the cluster. It identifies the cluster in the
73+
// manager if that is attached to a cluster provider. The value is usually
74+
// empty for the default cluster of a manager.
7375
Name() string
7476

7577
// GetHTTPClient returns an HTTP client that can be used to talk to the apiserver
@@ -110,7 +112,9 @@ type Cluster interface {
110112

111113
// Options are the possible options that can be configured for a Cluster.
112114
type Options struct {
113-
// Name is the identifying name of the cluster.
115+
// name is the name of the cluster. It identifies the cluster in the manager
116+
// if that is attached to a cluster provider. The value is usually empty for
117+
// the default cluster of a manager.
114118
Name string
115119

116120
// Scheme is the scheme used to resolve runtime.Objects to GroupVersionKinds / Resources
@@ -195,6 +199,10 @@ func New(config *rest.Config, opts ...Option) (Cluster, error) {
195199
return nil, errors.New("must specify Config")
196200
}
197201

202+
// the config returned by GetConfig() is not to be modified. Hence, we have
203+
// copy it before modifying it.
204+
originalConfig := config
205+
198206
config = rest.CopyConfig(config)
199207
if config.UserAgent == "" {
200208
config.UserAgent = rest.DefaultKubernetesUserAgent()
@@ -284,7 +292,7 @@ func New(config *rest.Config, opts ...Option) (Cluster, error) {
284292

285293
return &cluster{
286294
name: options.Name,
287-
config: config,
295+
config: originalConfig,
288296
httpClient: options.HTTPClient,
289297
scheme: options.Scheme,
290298
cache: cache,
@@ -351,7 +359,7 @@ func setOptionsDefaults(options Options, config *rest.Config) (Options, error) {
351359
return options, nil
352360
}
353361

354-
// WithName sets the name of the cluster.
362+
// WithName sets the name of the cluster. The name can only be set once.
355363
func WithName(name string) Option {
356364
return func(o *Options) {
357365
if o.Name != "" {

pkg/cluster/internal.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import (
3232
)
3333

3434
type cluster struct {
35+
// name is the name of the cluster. It identifies the cluster in the manager
36+
// if that is attached to a cluster provider. The value is usually empty for
37+
// the default cluster of a manager.
3538
name string
3639

3740
// config is the rest.config used to talk to the apiserver. Required.

pkg/handler/enqueue_mapped.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func EnqueueRequestsFromMapFunc(fn MapFunc) EventHandler {
4949
var _ EventHandler = &enqueueRequestsFromMapFunc{}
5050

5151
type enqueueRequestsFromMapFunc struct {
52+
// cluster is the source of the requeue request.
5253
cluster cluster.Cluster
5354

5455
// Mapper transforms the argument into a slice of keys to be reconciled

pkg/handler/enqueue_owner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func OnlyControllerOwner() OwnerOption {
7070
}
7171

7272
type enqueueRequestForOwner struct {
73+
// cluster is the source of the requeue request.
7374
cluster cluster.Cluster
7475

7576
// ownerType is the type of the Owner object to look for in OwnerReferences. Only Group and Kind are compared.

pkg/manager/internal.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func (cm *controllerManager) getCluster(ctx context.Context, clusterName string)
331331
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
332332
defer cancel()
333333
var watchErr error
334-
if err := wait.PollImmediateUntilWithContext(ctx, 1*time.Second, func(ctx context.Context) (done bool, err error) {
334+
if err := wait.PollUntilContextCancel(ctx, 1*time.Second, true, func(ctx context.Context) (done bool, err error) {
335335
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.
@@ -350,8 +350,10 @@ func (cm *controllerManager) getCluster(ctx context.Context, clusterName string)
350350
if err := cm.Add(cl); err != nil {
351351
return nil, fmt.Errorf("cannot add cluster %q to manager: %w", clusterName, err)
352352
}
353+
353354
// Create a new context for the Cluster, so that it can be stopped independently.
354355
ctx, cancel := context.WithCancel(context.Background())
356+
355357
c = &engagedCluster{
356358
Cluster: cl,
357359
ctx: ctx,
@@ -361,8 +363,8 @@ func (cm *controllerManager) getCluster(ctx context.Context, clusterName string)
361363
return c, nil
362364
}
363365

364-
func (cm *controllerManager) removeLogicalCluster(clusterName string) error {
365-
// Check if the manager was configured with a logical adapter,
366+
func (cm *controllerManager) removeNamedCluster(clusterName string) error {
367+
// Check if the manager was configured with a cluster provider,
366368
// otherwise we cannot retrieve the cluster.
367369
if cm.clusterProvider == nil {
368370
return fmt.Errorf("manager was not configured with a cluster provider, cannot retrieve %q", clusterName)
@@ -596,7 +598,7 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) { //nolint:g
596598
if clusterListSet.Has(name) {
597599
continue
598600
}
599-
if err := cm.removeLogicalCluster(name); err != nil {
601+
if err := cm.removeNamedCluster(name); err != nil {
600602
return err
601603
}
602604
}
@@ -637,7 +639,7 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) { //nolint:g
637639
}
638640
cm.engageClusterAwareRunnables()
639641
case watch.Deleted, watch.Error:
640-
if err := cm.removeLogicalCluster(event.ClusterName); err != nil {
642+
if err := cm.removeNamedCluster(event.ClusterName); err != nil {
641643
return err
642644
}
643645
case watch.Bookmark:

pkg/manager/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ type Options struct {
280280
// clusterProvider is an EXPERIMENTAL feature that allows the manager to
281281
// operate against many Kubernetes clusters at once.
282282
// It can be used by invoking WithExperimentalClusterProvider(adapter) on Options.
283+
// Individual clusters can be accessed by calling GetCluster on the Manager.
283284
clusterProvider cluster.Provider
284285
}
285286

pkg/reconcile/reconcile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (r Request) String() string {
6262
if r.ClusterName == "" {
6363
return r.NamespacedName.String()
6464
}
65-
return "logical://" + string(r.ClusterName) + string(types.Separator) + r.NamespacedName.String()
65+
return "cluster://" + string(r.ClusterName) + string(types.Separator) + r.NamespacedName.String()
6666
}
6767

6868
/*

0 commit comments

Comments
 (0)