Skip to content

Commit e93979e

Browse files
committed
Add reconcile.ClusterAwareRequest and matching EventHandlers
On-behalf-of: SAP <[email protected]> Signed-off-by: Marvin Beckers <[email protected]>
1 parent 01ff225 commit e93979e

File tree

12 files changed

+336
-342
lines changed

12 files changed

+336
-342
lines changed

examples/fleet-namespace/cluster.go

-15
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,12 @@ package main
1919
import (
2020
"context"
2121

22-
"k8s.io/apimachinery/pkg/types"
2322
"k8s.io/client-go/tools/record"
2423
"sigs.k8s.io/controller-runtime/pkg/cache"
2524
"sigs.k8s.io/controller-runtime/pkg/client"
2625
"sigs.k8s.io/controller-runtime/pkg/cluster"
27-
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2826
)
2927

30-
type clusterRequest struct {
31-
reconcile.Request
32-
ClusterName string
33-
}
34-
35-
// String returns the general purpose string representation.
36-
func (cr *clusterRequest) String() string {
37-
if cr.ClusterName == "" {
38-
return cr.NamespacedName.String()
39-
}
40-
return "cluster://" + cr.ClusterName + string(types.Separator) + cr.NamespacedName.String()
41-
}
42-
4328
type NamespacedCluster struct {
4429
clusterName string
4530
cluster.Cluster

examples/fleet-namespace/eventhandler.go

-124
This file was deleted.

examples/fleet-namespace/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ func main() {
120120
os.Exit(1)
121121
}
122122

123-
if err := builder.TypedControllerManagedBy[clusterRequest](mgr).
123+
if err := builder.TypedControllerManagedBy[reconcile.ClusterAwareRequest](mgr).
124124
Named("fleet-ns-configmap-controller").
125-
Watches(&corev1.ConfigMap{}, &EnqueueClusterRequestForObject{}).
126-
Complete(reconcile.TypedFunc[clusterRequest](
127-
func(ctx context.Context, req clusterRequest) (ctrl.Result, error) {
125+
For(&corev1.ConfigMap{}).
126+
Complete(reconcile.TypedFunc[reconcile.ClusterAwareRequest](
127+
func(ctx context.Context, req reconcile.ClusterAwareRequest) (ctrl.Result, error) {
128128
log := log.FromContext(ctx).WithValues("cluster", req.ClusterName)
129129

130130
cl, err := mgr.GetCluster(ctx, req.ClusterName)

examples/fleet/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# examples/fleet
2+
3+
The `fleet` example is a basic implementation of a multi-cluster-capable controller. As a cluster provider it uses `kind`: Every local kind cluster with a `fleet-` name prefix will be picked up as dynamic cluster if multi-cluster support is enabled in `fleet`.
4+
5+
`fleet` can switch between multi-cluster mode and single-cluster mode via the `--enable-cluster-provider` flag (defaults to `true`) to demonstrate the seamless switch of using the same code base as a "normal" single-cluster controller and as a multi-cluster controller as easy as plugging in a (third-party) cluster provider. To run `fleet` against the current `KUBECONFIG` in single-cluster mode, just run:
6+
7+
```sh
8+
$ USE_EXISTING_CLUSTER=true go run . --enable-cluster-provider=false
9+
```

examples/fleet/cluster.go

-35
This file was deleted.

examples/fleet/eventhandler.go

-125
This file was deleted.

0 commit comments

Comments
 (0)