-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change adds a TypedReconciler which allows to customize the type being used in the workqueue. There is a number of situations where a custom type might be better than the default `reconcile.Request`: * Multi-Cluster controllers might want to put the clusters in there * Some controllers do not reconcile individual resources of a given type but all of them at once, for example IngressControllers might do this * Some controllers do not operate on Kubernetes resources at all
- Loading branch information
1 parent
162a113
commit 40c6b5c
Showing
26 changed files
with
633 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
networkingv1 "k8s.io/api/networking/v1" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/builder" | ||
"sigs.k8s.io/controller-runtime/pkg/handler" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
"sigs.k8s.io/controller-runtime/pkg/source" | ||
) | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
fmt.Fprintf(os.Stderr, "%v\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func run() error { | ||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{}) | ||
if err != nil { | ||
return fmt.Errorf("failed to construct manager: %w", err) | ||
} | ||
|
||
// Use a request type that is always equal to itself so the workqueue | ||
// de-duplicates all events. | ||
// This can for example be useful for an ingress-controller that | ||
// generates a config from all ingresses, rather than individual ones. | ||
type request struct{} | ||
|
||
r := reconcile.TypedFunc[request](func(ctx context.Context, _ request) (reconcile.Result, error) { | ||
ingressList := &networkingv1.IngressList{} | ||
if err := mgr.GetClient().List(ctx, ingressList); err != nil { | ||
return reconcile.Result{}, fmt.Errorf("failed to list ingresses: %w", err) | ||
} | ||
|
||
buildIngressConfig(ingressList) | ||
return reconcile.Result{}, nil | ||
}) | ||
if err := builder.TypedControllerManagedBy[request](mgr). | ||
WatchesRawSource(source.TypedKind( | ||
mgr.GetCache(), | ||
&networkingv1.Ingress{}, | ||
handler.TypedEnqueueRequestsFromMapFunc(func(context.Context, *networkingv1.Ingress) []request { | ||
return []request{{}} | ||
})), | ||
). | ||
Named("ingress_controller"). | ||
Complete(r); err != nil { | ||
return fmt.Errorf("failed to construct ingress-controller: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func buildIngressConfig(*networkingv1.IngressList) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.