-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
⚠️ Add TypedReconciler #2799
base: main
Are you sure you want to change the base?
⚠️ Add TypedReconciler #2799
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) { | ||
sbueringer marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+33
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To expand on this a bit more can we add some reasoning on why this is better than say have a normal reconciler that just ignores the incoming request? |
||
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). | ||
sbueringer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
WatchesRawSource(source.TypedKind( | ||
mgr.GetCache(), | ||
&networkingv1.Ingress{}, | ||
handler.TypedEnqueueRequestsFromMapFunc(func(context.Context, *networkingv1.Ingress) []request { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume here is one of the most important parts? The custom requests, outside of |
||
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) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description mentions this can be a good use for multiple clusters. Could we add an example that expands on the current
reconcile.Request
to add Cluster information?