Skip to content

Commit

Permalink
Refactor on Alvaro's PR
Browse files Browse the repository at this point in the history
Signed-off-by: Danil Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Apr 18, 2024
1 parent 5117265 commit e9e663d
Show file tree
Hide file tree
Showing 30 changed files with 117 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,29 @@ func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl
}

b := ctrl.NewControllerManagedBy(mgr).
Named("kubeadmConfig").
Add(builder.For(mgr,
&bootstrapv1.KubeadmConfig{},
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &bootstrapv1.KubeadmConfig{}),
)).
WithOptions(options).
Add(builder.Watches(mgr,
&clusterv1.Machine{},
handler.EnqueueRequestsFromObjectMap(r.MachineToBootstrapMapFunc),
handler.EnqueueRequestsFromTypedMapFunc(r.MachineToBootstrapMapFunc),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Machine{}),
))

if feature.Gates.Enabled(feature.MachinePool) {
b = b.Add(builder.Watches(mgr,
&expv1.MachinePool{},
handler.EnqueueRequestsFromObjectMap(r.MachinePoolToBootstrapMapFunc),
handler.EnqueueRequestsFromTypedMapFunc(r.MachinePoolToBootstrapMapFunc),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &expv1.MachinePool{}),
))
}

b = b.Add(builder.Watches(mgr,
&clusterv1.Cluster{},
handler.EnqueueRequestsFromObjectMap(r.ClusterToKubeadmConfigs),
handler.EnqueueRequestsFromTypedMapFunc(r.ClusterToKubeadmConfigs),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Cluster{}),
predicates.ClusterUnpausedAndInfrastructureReady(ctrl.LoggerFrom(ctx)),
))
Expand Down
4 changes: 3 additions & 1 deletion controllers/external/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ func (o *ObjectTracker) Watch(log logr.Logger, obj client.Object, handler handle
return nil
}

var c client.Object
u := &unstructured.Unstructured{}
u.SetGroupVersionKind(gvk)
c = u

log.Info(fmt.Sprintf("Adding watch on external object %q", gvk.String()))
err := o.Controller.Watch(
source.Kind(o.Cache, u).Prepare(handler, append(p, predicates.ResourceNotPaused(log, obj))...),
source.Kind(o.Cache, c, handler, append(p, predicates.ResourceNotPaused(log, obj))...),
)
if err != nil {
o.m.Delete(key)
Expand Down
2 changes: 1 addition & 1 deletion controllers/remote/cluster_cache_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ func (t *ClusterCacheTracker) Watch(ctx context.Context, input WatchInput) error
}

// Need to create the watch
if err := input.Watcher.Watch(source.Kind(accessor.cache, input.Kind), input.EventHandler, input.Predicates...); err != nil {
if err := input.Watcher.Watch(source.Kind(accessor.cache, input.Kind, nil), input.EventHandler, input.Predicates...); err != nil {
return errors.Wrapf(err, "failed to add %s watch on cluster %s: failed to create watch", input.Kind, klog.KRef(input.Cluster.Namespace, input.Cluster.Name))
}

Expand Down
3 changes: 2 additions & 1 deletion controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type KubeadmControlPlaneReconciler struct {

func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
c, err := ctrl.NewControllerManagedBy(mgr).
Named("kubeadmControlPlane").
Add(builder.For(mgr,
&controlplanev1.KubeadmControlPlane{},
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &controlplanev1.KubeadmControlPlane{}),
Expand All @@ -103,7 +104,7 @@ func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mg
WithOptions(options).
Add(builder.Watches(mgr,
&clusterv1.Cluster{},
handler.EnqueueRequestsFromObjectMap(r.ClusterToKubeadmControlPlane),
handler.EnqueueRequestsFromTypedMapFunc(r.ClusterToKubeadmControlPlane),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Cluster{}),
predicates.ClusterUnpausedAndInfrastructureReady(ctrl.LoggerFrom(ctx)),
)).Build(r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ type ClusterResourceSetReconciler struct {

func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
err := ctrl.NewControllerManagedBy(mgr).
Named("clusterResourceSet").
Add(builder.For(mgr, &addonsv1.ClusterResourceSet{},
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &addonsv1.ClusterResourceSet{}),
)).
Add(builder.Watches(mgr,
&clusterv1.Cluster{},
handler.EnqueueRequestsFromObjectMap(r.clusterToClusterResourceSet),
handler.EnqueueRequestsFromTypedMapFunc(r.clusterToClusterResourceSet),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Cluster{}),
)).
WatchesMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ type ClusterResourceSetBindingReconciler struct {

func (r *ClusterResourceSetBindingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
err := ctrl.NewControllerManagedBy(mgr).
Named("clusterResourceSetBinding").
For(&addonsv1.ClusterResourceSetBinding{}).
Add(builder.Watches(mgr,
&clusterv1.Cluster{},
handler.EnqueueRequestsFromObjectMap(r.clusterToClusterResourceSetBinding),
handler.EnqueueRequestsFromTypedMapFunc(r.clusterToClusterResourceSetBinding),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Cluster{}),
)).
WithOptions(options).
Expand Down
5 changes: 3 additions & 2 deletions exp/internal/controllers/machinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
}

c, err := ctrl.NewControllerManagedBy(mgr).
Named("machinepool").
Add(builder.For(mgr,
&expv1.MachinePool{},
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &expv1.MachinePool{}))).
WithOptions(options).
Add(builder.Watches(mgr,
&clusterv1.Cluster{},
handler.EnqueueRequestsFromObjectMap(clusterToMachinePools),
handler.EnqueueRequestsFromTypedMapFunc(clusterToMachinePools),
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Cluster{}),
Expand Down Expand Up @@ -333,7 +334,7 @@ func (r *MachinePoolReconciler) watchClusterNodes(ctx context.Context, cluster *
Cluster: util.ObjectKey(cluster),
Watcher: &controller.ControllerAdapter{Controller: r.controller},

Check failure on line 335 in exp/internal/controllers/machinepool_controller.go

View workflow job for this annotation

GitHub Actions / lint

undefined: controller.ControllerAdapter
Kind: &corev1.Node{},
EventHandler: handler.EnqueueRequestsFromObjectMapFunc(r.nodeToMachinePool),
EventHandler: handler.EnqueueRequestsFromMapFunc(r.nodeToMachinePool),

Check failure on line 337 in exp/internal/controllers/machinepool_controller.go

View workflow job for this annotation

GitHub Actions / lint

cannot use r.nodeToMachinePool (value of type func(ctx context.Context, node *"k8s.io/api/core/v1".Node) []reconcile.Request) as handler.TypedMapFunc[client.Object] value in argument to handler.EnqueueRequestsFromMapFunc) (typecheck)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Reconciler struct {

func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
err := ctrl.NewControllerManagedBy(mgr).
Named("extensionconfig").
Add(builder.For(mgr,
&runtimev1.ExtensionConfig{},
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &runtimev1.ExtensionConfig{}),
Expand Down
2 changes: 1 addition & 1 deletion exp/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func GetMachinePoolByLabels(ctx context.Context, c client.Client, namespace stri

// MachinePoolToInfrastructureMapFunc returns a handler.MapFunc that watches for
// MachinePool events and returns reconciliation requests for an infrastructure provider object.
func MachinePoolToInfrastructureMapFunc(gvk schema.GroupVersionKind, log logr.Logger) handler.ObjectMapFunc[*expv1.MachinePool] {
func MachinePoolToInfrastructureMapFunc(gvk schema.GroupVersionKind, log logr.Logger) handler.TypedMapFunc[*expv1.MachinePool] {
log = log.WithValues("machine-pool-to-infra-map-func", gvk.String())
return func(_ context.Context, m *expv1.MachinePool) []reconcile.Request {
log := log.WithValues("MachinePool", klog.KObj(m))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module sigs.k8s.io/cluster-api

go 1.22.0

replace sigs.k8s.io/controller-runtime => github.com/Danil-Grigorev/controller-runtime v0.6.1-0.20240417125124-8984b3049571
replace sigs.k8s.io/controller-runtime => github.com/Danil-Grigorev/controller-runtime v0.6.1-0.20240417201603-e18909c2932e

require (
github.com/MakeNowJust/heredoc v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOEl
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Danil-Grigorev/controller-runtime v0.6.1-0.20240417125124-8984b3049571 h1:a1Oaf+Zk1mbhUP0wVULBOLZ+b4MXLW6g/2kadPQg5yw=
github.com/Danil-Grigorev/controller-runtime v0.6.1-0.20240417125124-8984b3049571/go.mod h1:TLM3OvUJgcqHVBLVRlNylmfbOlOukMLFHtc6jo3EtIQ=
github.com/Danil-Grigorev/controller-runtime v0.6.1-0.20240417201603-e18909c2932e h1:hEGMiTp7lLNM666lIVpXzlyjkTpAMV+iYcnofBNKAYk=
github.com/Danil-Grigorev/controller-runtime v0.6.1-0.20240417201603-e18909c2932e/go.mod h1:TLM3OvUJgcqHVBLVRlNylmfbOlOukMLFHtc6jo3EtIQ=
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ type Reconciler struct {

func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
c, err := ctrl.NewControllerManagedBy(mgr).
Named("cluster").
Add(builder.For(mgr, &clusterv1.Cluster{}, predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Cluster{}))).
Add(builder.Watches(mgr,
&clusterv1.Machine{},
handler.EnqueueRequestsFromObjectMap(r.controlPlaneMachineToCluster),
handler.EnqueueRequestsFromTypedMapFunc(r.controlPlaneMachineToCluster),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Machine{}),
)).
WithOptions(options).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
Named("clusterclass").
WithOptions(options).
Add(builder.Watches(mgr, &runtimev1.ExtensionConfig{},
handler.EnqueueRequestsFromObjectMap(r.extensionConfigToClusterClass),
handler.EnqueueRequestsFromTypedMapFunc(r.extensionConfigToClusterClass),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &runtimev1.ExtensionConfig{}))).
Complete(r)

Expand Down
13 changes: 7 additions & 6 deletions internal/controllers/machine/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
}

c, err := ctrl.NewControllerManagedBy(mgr).
Named("machine").
Add(builder.For(mgr, &clusterv1.Machine{}, predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Machine{}))).
WithOptions(options).
Add(builder.Watches(mgr,
&clusterv1.Cluster{},
handler.EnqueueRequestsFromObjectMap(clusterToMachines),
handler.EnqueueRequestsFromTypedMapFunc(clusterToMachines),
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
predicate.Any(
predicate.Any(
predicate.Or(
predicate.Or(
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
predicates.ClusterControlPlaneInitialized(ctrl.LoggerFrom(ctx)),
),
Expand All @@ -132,12 +133,12 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
)).
Add(builder.Watches(mgr,
&clusterv1.MachineSet{},
handler.EnqueueRequestsFromObjectMap(msToMachines),
handler.EnqueueRequestsFromTypedMapFunc(msToMachines),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.MachineSet{}),
)).
Add(builder.Watches(mgr,
&clusterv1.MachineDeployment{},
handler.EnqueueRequestsFromObjectMap(mdToMachines),
handler.EnqueueRequestsFromTypedMapFunc(mdToMachines),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.MachineDeployment{}),
)).
Build(r)
Expand Down Expand Up @@ -861,7 +862,7 @@ func (r *Reconciler) watchClusterNodes(ctx context.Context, cluster *clusterv1.C
Cluster: util.ObjectKey(cluster),
Watcher: &controller.ControllerAdapter{Controller: r.controller},

Check failure on line 863 in internal/controllers/machine/machine_controller.go

View workflow job for this annotation

GitHub Actions / lint

undefined: controller.ControllerAdapter
Kind: &corev1.Node{},
EventHandler: handler.EnqueueRequestsFromObjectMapFunc(r.nodeToMachine),
EventHandler: handler.EnqueueRequestsFromTypedMapFuncFunc(r.nodeToMachine),

Check failure on line 865 in internal/controllers/machine/machine_controller.go

View workflow job for this annotation

GitHub Actions / lint

undefined: handler.EnqueueRequestsFromTypedMapFuncFunc) (typecheck)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
}

err = ctrl.NewControllerManagedBy(mgr).
Named("machineDeployment").
Add(builder.For(mgr,
&clusterv1.MachineDeployment{},
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.MachineDeployment{}))).
Expand All @@ -88,13 +89,13 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
// Watches enqueues MachineDeployment for corresponding MachineSet resources, if no managed controller reference (owner) exists.
Add(builder.Watches(mgr,
&clusterv1.MachineSet{},
handler.EnqueueRequestsFromObjectMap(r.MachineSetToDeployments),
handler.EnqueueRequestsFromTypedMapFunc(r.MachineSetToDeployments),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.MachineSet{})),
).
WithOptions(options).
Add(builder.Watches(mgr,
&clusterv1.Cluster{},
handler.EnqueueRequestsFromObjectMap(clusterToMachineDeployments),
handler.EnqueueRequestsFromTypedMapFunc(clusterToMachineDeployments),
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Cluster{}),
)).Complete(r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ type Reconciler struct {

func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
c, err := ctrl.NewControllerManagedBy(mgr).
Named("machineHealthCheck").
Add(builder.For(mgr,
&clusterv1.MachineHealthCheck{},
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.MachineHealthCheck{}))).
Add(builder.Watches(mgr,
&clusterv1.Machine{},
handler.EnqueueRequestsFromObjectMap(r.machineToMachineHealthCheck),
handler.EnqueueRequestsFromTypedMapFunc(r.machineToMachineHealthCheck),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Machine{}),
)).
WithOptions(options).
Add(builder.Watches(mgr,
&clusterv1.Cluster{},
handler.EnqueueRequestsFromObjectMap(r.clusterToMachineHealthCheck),
handler.EnqueueRequestsFromTypedMapFunc(r.clusterToMachineHealthCheck),
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Cluster{}),
Expand Down Expand Up @@ -517,7 +518,7 @@ func (r *Reconciler) watchClusterNodes(ctx context.Context, cluster *clusterv1.C
Cluster: util.ObjectKey(cluster),
Watcher: &controller.ControllerAdapter{Controller: r.controller},
Kind: &corev1.Node{},
EventHandler: handler.EnqueueRequestsFromObjectMapFunc(r.nodeToMachineHealthCheck),
EventHandler: handler.EnqueueRequestsFromTypedMapFunc(r.nodeToMachineHealthCheck),
})
}

Expand Down
5 changes: 3 additions & 2 deletions internal/controllers/machineset/machineset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,19 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
}

err = ctrl.NewControllerManagedBy(mgr).
Named("machineset").
Add(builder.For(mgr, &clusterv1.MachineSet{}, predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.MachineSet{}))).
Add(builder.Owns(mgr, &clusterv1.MachineSet{}, &clusterv1.Machine{}, predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Machine{}))).
// Watches enqueues MachineSet for corresponding Machine resources, if no managed controller reference (owner) exists.
Add(builder.Watches(mgr,
&clusterv1.Machine{},
handler.EnqueueRequestsFromObjectMap(r.MachineToMachineSets),
handler.EnqueueRequestsFromTypedMapFunc(r.MachineToMachineSets),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Machine{}),
)).
WithOptions(options).
Add(builder.Watches(mgr,
&clusterv1.Cluster{},
handler.EnqueueRequestsFromObjectMap(clusterToMachineSets),
handler.EnqueueRequestsFromTypedMapFunc(clusterToMachineSets),
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Cluster{}),
)).Complete(r)
Expand Down
11 changes: 6 additions & 5 deletions internal/controllers/topology/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
kerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -99,19 +100,19 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
Named("topology/cluster").
Add(builder.Watches(mgr,
&clusterv1.ClusterClass{},
handler.EnqueueRequestsFromObjectMap(r.clusterClassToCluster),
handler.EnqueueRequestsFromTypedMapFunc(r.clusterClassToCluster),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.ClusterClass{}),
)).
Add(builder.Watches(mgr,
&clusterv1.MachineDeployment{},
handler.EnqueueRequestsFromObjectMap(r.machineDeploymentToCluster),
handler.EnqueueRequestsFromTypedMapFunc(r.machineDeploymentToCluster),
// Only trigger Cluster reconciliation if the MachineDeployment is topology owned.
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.MachineDeployment{}),
predicates.ResourceIsTopologyOwned(ctrl.LoggerFrom(ctx), &clusterv1.MachineDeployment{}),
)).
Add(builder.Watches(mgr,
&expv1.MachinePool{},
handler.EnqueueRequestsFromObjectMap(r.machinePoolToCluster),
handler.EnqueueRequestsFromTypedMapFunc(r.machinePoolToCluster),
// Only trigger Cluster reconciliation if the MachinePool is topology owned.
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &expv1.MachinePool{}),
predicates.ResourceIsTopologyOwned(ctrl.LoggerFrom(ctx), &expv1.MachinePool{}),
Expand Down Expand Up @@ -305,9 +306,9 @@ func (r *Reconciler) setupDynamicWatches(ctx context.Context, s *scope.Scope) er
}
if s.Current.ControlPlane.Object != nil {
if err := r.externalTracker.Watch(ctrl.LoggerFrom(ctx), s.Current.ControlPlane.Object,
handler.EnqueueRequestForOwner(r.Client.Scheme(), r.Client.RESTMapper(), &clusterv1.Cluster{}),
handler.TypedEnqueueRequestForOwner[*unstructured.Unstructured](r.Client.Scheme(), r.Client.RESTMapper(), &clusterv1.Cluster{}),

Check failure on line 309 in internal/controllers/topology/cluster/cluster_controller.go

View workflow job for this annotation

GitHub Actions / lint

cannot use handler.TypedEnqueueRequestForOwner[*unstructured.Unstructured](r.Client.Scheme(), r.Client.RESTMapper(), &clusterv1.Cluster{}) (value of type handler.TypedEventHandler[*unstructured.Unstructured]) as handler.EventHandler value in argument to r.externalTracker.Watch: handler.TypedEventHandler[*unstructured.Unstructured] does not implement handler.EventHandler (wrong type for method Create)
// Only trigger Cluster reconciliation if the ControlPlane is topology owned.
predicates.ResourceIsTopologyOwned(ctrl.LoggerFrom(ctx), &clusterv1.Cluster{})); err != nil {
predicates.ResourceIsTopologyOwned(ctrl.LoggerFrom(ctx), &unstructured.Unstructured{})); err != nil {

Check failure on line 311 in internal/controllers/topology/cluster/cluster_controller.go

View workflow job for this annotation

GitHub Actions / lint

cannot use predicates.ResourceIsTopologyOwned(ctrl.LoggerFrom(ctx), &unstructured.Unstructured{}) (value of type predicate.TypedPredicate[*unstructured.Unstructured]) as predicate.TypedPredicate["sigs.k8s.io/controller-runtime/pkg/client".Object] value in argument to r.externalTracker.Watch: predicate.TypedPredicate[*unstructured.Unstructured] does not implement predicate.TypedPredicate["sigs.k8s.io/controller-runtime/pkg/client".Object] (wrong type for method Create)
return errors.Wrap(err, "error watching ControlPlane CR")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
WithOptions(options).
Add(builder.Watches(mgr,
&clusterv1.Cluster{},
handler.EnqueueRequestsFromObjectMap(clusterToMachineDeployments),
handler.EnqueueRequestsFromTypedMapFunc(clusterToMachineDeployments),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Cluster{}),
predicates.ClusterHasTopology(ctrl.LoggerFrom(ctx)),
)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
WithOptions(options).
Add(builder.Watches(mgr,
&clusterv1.Cluster{},
handler.EnqueueRequestsFromObjectMap(clusterToMachineSets),
handler.EnqueueRequestsFromTypedMapFunc(clusterToMachineSets),
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue, &clusterv1.Cluster{}),
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
predicates.ClusterHasTopology(ctrl.LoggerFrom(ctx)),
Expand Down
Loading

0 comments on commit e9e663d

Please sign in to comment.