Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 6a64a68

Browse files
committed
todo: rework resource watcher
1 parent 3107cbf commit 6a64a68

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

controllers/cdk8sappproxy/cdk8sappproxy_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func getPluralFromKind(kind string) string {
144144
// SetupWithManager sets up the controller with the Manager.
145145
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
146146
// Initialize the new simplified watch system
147-
r.WatchManager = NewResourceWatchManager(mgr.GetClient(), r.Reconcile)
147+
r.WatchManager = NewResourceWatchManager(mgr.GetClient())
148148

149149
return ctrl.NewControllerManagedBy(mgr).
150150
For(&addonsv1alpha1.Cdk8sAppProxy{}).

controllers/cdk8sappproxy/cdk8sappproxy_resourcewatcher.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ package cdk8sappproxy
33
import (
44
"context"
55
"sync"
6-
"time"
76

87
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
98
"k8s.io/apimachinery/pkg/runtime/schema"
109
"k8s.io/apimachinery/pkg/types"
1110
"k8s.io/apimachinery/pkg/watch"
1211
"k8s.io/client-go/dynamic"
13-
ctrl "sigs.k8s.io/controller-runtime"
1412
"sigs.k8s.io/controller-runtime/pkg/client"
1513
"sigs.k8s.io/controller-runtime/pkg/log"
1614
)
@@ -20,7 +18,6 @@ type ResourceWatchManager struct {
2018
mu sync.RWMutex
2119
watches map[types.NamespacedName]map[string]context.CancelFunc
2220
client client.Client
23-
queue workqueue.RateLimitingInterface
2421
}
2522

2623
// WatchInfo holds information about an active watch
@@ -33,11 +30,10 @@ type WatchInfo struct {
3330
}
3431

3532
// NewResourceWatchManager creates a new resource watch manager.
36-
func NewResourceWatchManager(client client.Client, reconcileFunc func(context.Context, ctrl.Request) (ctrl.Result, error)) *ResourceWatchManager {
33+
func NewResourceWatchManager(client client.Client) *ResourceWatchManager {
3734
return &ResourceWatchManager{
3835
watches: make(map[types.NamespacedName]map[string]context.CancelFunc),
3936
client: client,
40-
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "resource-deletion"),
4137
}
4238
}
4339

@@ -155,21 +151,6 @@ func (m *ResourceWatchManager) watchResource(ctx context.Context, targetClient d
155151
func (m *ResourceWatchManager) triggerReconciliation(ctx context.Context, parentProxy types.NamespacedName) error {
156152
logger := log.FromContext(ctx).WithValues("parentProxy", parentProxy.String())
157153

158-
if m.reconcileFunc != nil {
159-
req := ctrl.Request{NamespacedName: parentProxy}
160-
go func() {
161-
reconcileCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
162-
defer cancel()
163-
164-
_, err := m.reconcileFunc(reconcileCtx, req)
165-
if err != nil {
166-
logger.Error(err, "Failed to reconcile after resource deletion")
167-
} else {
168-
logger.Info("Successfully triggered reconciliation after resource deletion")
169-
}
170-
}()
171-
}
172-
173154
logger.Info("Resource deletion detected, reconciliation triggered")
174155

175156
return nil

0 commit comments

Comments
 (0)