Skip to content

Commit

Permalink
SQUASH: revert ForceDefaultCluster()
Browse files Browse the repository at this point in the history
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>
  • Loading branch information
sttts committed Mar 25, 2024
1 parent e769c9a commit 5f6764a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 36 deletions.
26 changes: 3 additions & 23 deletions pkg/builder/controller.go
Expand Up @@ -287,10 +287,7 @@ func (blder *Builder) doWatch() error {
if err != nil {
return err
}
src := clusterAwareSource{
DeepCopyableSyncingSource: source.Kind(blder.cluster.GetCache(), obj),
forceDefaultCluster: blder.forInput.forceDefaultCluster,
}
src := source.Kind(blder.cluster.GetCache(), obj)
hdler := &handler.EnqueueRequestForObject{}
allPredicates := append([]predicate.Predicate(nil), blder.globalPredicates...)
allPredicates = append(allPredicates, blder.forInput.predicates...)
Expand All @@ -308,10 +305,7 @@ func (blder *Builder) doWatch() error {
if err != nil {
return err
}
src := clusterAwareSource{
DeepCopyableSyncingSource: source.Kind(blder.cluster.GetCache(), obj),
forceDefaultCluster: own.forceDefaultCluster,
}
src := source.Kind(blder.cluster.GetCache(), obj)
opts := []handler.OwnerOption{}
if !own.matchEveryOwner {
opts = append(opts, handler.OnlyControllerOwner())
Expand All @@ -334,17 +328,12 @@ func (blder *Builder) doWatch() error {
}
for _, w := range blder.watchesInput {
// If the source of this watch is of type Kind, project it.
src := w.src
if srcKind, ok := w.src.(*internalsource.Kind); ok {
typeForSrc, err := blder.project(srcKind.Type, w.objectProjection)
if err != nil {
return err
}
srcKind.Type = typeForSrc
src = clusterAwareSource{
DeepCopyableSyncingSource: srcKind,
forceDefaultCluster: w.forceDefaultCluster,
}
} else if !ok {
// If we're building a cluster-aware controller, raw watches are not allowed
// given that the cache cannot be validated to be coming from the same cluster.
Expand All @@ -356,7 +345,7 @@ func (blder *Builder) doWatch() error {
}
allPredicates := append([]predicate.Predicate(nil), blder.globalPredicates...)
allPredicates = append(allPredicates, w.predicates...)
if err := blder.ctrl.Watch(src, w.eventHandler, allPredicates...); err != nil {
if err := blder.ctrl.Watch(w.src, w.eventHandler, allPredicates...); err != nil {
return err
}
}
Expand Down Expand Up @@ -445,12 +434,3 @@ func (blder *Builder) doController(r reconcile.Reconciler) error {
blder.ctrl, err = newController(controllerName, blder.mgr, ctrlOptions)
return err
}

type clusterAwareSource struct {
source.DeepCopyableSyncingSource
forceDefaultCluster bool
}

func (s clusterAwareSource) ForceDefaultCluster() bool {
return s.forceDefaultCluster
}
15 changes: 2 additions & 13 deletions pkg/internal/controller/controller.go
Expand Up @@ -103,13 +103,6 @@ type Controller struct {
LeaderElected *bool
}

// ClusterAwareSource is a source that knows whether to watch in the default cluster
// in the clusters engaged by the cluster provider.
type ClusterAwareSource interface {
source.Source
ForceDefaultCluster() bool
}

type clusterDescription struct {
cluster.Cluster
ctx context.Context
Expand Down Expand Up @@ -157,12 +150,8 @@ func (c *Controller) Watch(src source.Source, evthdler handler.EventHandler, prc
c.mu.Lock()
defer c.mu.Unlock()

// If the source is cluster aware, store it in a separate list.
var forceDefaultCluster bool
if src, ok := src.(ClusterAwareSource); ok {
forceDefaultCluster = src.ForceDefaultCluster()
}
if c.WatchProviderClusters && !forceDefaultCluster {
// If a cluster provider is in-place, run src for every provided cluster
if c.WatchProviderClusters {
src, ok := src.(source.DeepCopyableSyncingSource)
if !ok {
return fmt.Errorf("source %T is not cluster aware, but WatchProviderClusters is true", src)
Expand Down

0 comments on commit 5f6764a

Please sign in to comment.