1
0
Fork 0
mirror of https://github.com/imjasonh/git-k8s synced 2026-07-18 06:55:48 +00:00

Refactor reconcilers to use Knative ReconcileKind pattern

Move the key-splitting, resource-fetching, and not-found handling into a
generic internal.NewReconciler wrapper so that each reconciler only
implements ReconcileKind(ctx, *TypedResource) — matching the Knative
generated reconciler convention. The controller setup wraps the
reconciler with internal.NewReconciler, which bridges Reconcile(ctx, key)
to ReconcileKind(ctx, *T).

This removes duplicated boilerplate from all three reconcilers (push,
sync, resolver), eliminates their Reconcile/LeaderAware methods, and
makes splitKey an unexported implementation detail.

https://claude.ai/code/session_01Eu3LyxX3G1KCcw4aDzmHvp
This commit is contained in:
Claude 2026-02-28 05:06:22 +00:00
parent f6e819e939
commit b122fb297f
No known key found for this signature in database
9 changed files with 106 additions and 96 deletions

View file

@ -4,6 +4,7 @@ import (
"context"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/dynamic/dynamicinformer"
@ -15,6 +16,7 @@ import (
gitv1alpha1 "github.com/imjasonh/git-k8s/pkg/apis/git/v1alpha1"
gitclient "github.com/imjasonh/git-k8s/pkg/client"
"github.com/imjasonh/git-k8s/pkg/reconciler/internal"
)
var pushTransactionGVR = schema.GroupVersionResource{
@ -45,7 +47,12 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl
gitClient: gitClient,
}
impl := controller.NewContext(ctx, r, controller.ControllerOptions{
impl := controller.NewContext(ctx, internal.NewReconciler(
func(ctx context.Context, namespace, name string) (*gitv1alpha1.GitPushTransaction, error) {
return gitClient.GitPushTransactions(namespace).Get(ctx, name, metav1.GetOptions{})
},
r,
), controller.ControllerOptions{
WorkQueueName: "GitPushTransactions",
Logger: logger,
})
@ -67,4 +74,3 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl
return impl
}