Skip to content

Commit 8c4bb61

Browse files
committed
daemon: wire StatusWatcher into reconciler and daemon
Add --poll-interval flag to the daemon binary and wire the StatusWatcher channel into the reconciler as a second WatchesRawSource alongside switchDone. Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Alice Frosi <afrosi@redhat.com>
1 parent bfad741 commit 8c4bb61

3 files changed

Lines changed: 41 additions & 15 deletions

File tree

cmd/daemon/main.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"flag"
77
"fmt"
88
"os"
9+
"time"
910

1011
"k8s.io/apimachinery/pkg/fields"
1112
"k8s.io/apimachinery/pkg/runtime"
@@ -14,6 +15,7 @@ import (
1415
ctrl "sigs.k8s.io/controller-runtime"
1516
"sigs.k8s.io/controller-runtime/pkg/cache"
1617
"sigs.k8s.io/controller-runtime/pkg/client"
18+
"sigs.k8s.io/controller-runtime/pkg/event"
1719
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1820

1921
bootcv1alpha1 "github.com/jlebon/bootc-operator/api/v1alpha1"
@@ -32,6 +34,9 @@ func init() {
3234
}
3335

3436
func main() {
37+
var pollInterval time.Duration
38+
flag.DurationVar(&pollInterval, "poll-interval", 5*time.Minute, "Interval for polling bootc status as a fallback to fsnotify")
39+
3540
opts := zap.Options{
3641
Development: true,
3742
}
@@ -62,17 +67,32 @@ func main() {
6267
os.Exit(1)
6368
}
6469

70+
statusChanged := make(chan event.GenericEvent, 1)
71+
6572
if err := (&daemon.BootcNodeReconciler{
66-
Client: mgr.GetClient(),
67-
Scheme: mgr.GetScheme(),
68-
NodeName: nodeName,
69-
Executor: bootc.NewHostExecutor(),
73+
Client: mgr.GetClient(),
74+
Scheme: mgr.GetScheme(),
75+
NodeName: nodeName,
76+
Executor: bootc.NewHostExecutor(),
77+
StatusChanged: statusChanged,
7078
}).SetupWithManager(mgr); err != nil {
7179
setupLog.Error(err, "Failed to create controller", "controller", "bootcnode")
7280
os.Exit(1)
7381
}
7482

75-
setupLog.Info("Starting daemon", "node", nodeName)
83+
watcher := &daemon.StatusWatcher{
84+
PollInterval: pollInterval,
85+
PrimaryPath: daemon.DefaultPrimaryPath,
86+
FallbackPath: daemon.DefaultFallbackPath,
87+
Events: statusChanged,
88+
NodeName: nodeName,
89+
}
90+
if err := mgr.Add(watcher); err != nil {
91+
setupLog.Error(err, "Failed to add status watcher")
92+
os.Exit(1)
93+
}
94+
95+
setupLog.Info("Starting daemon", "node", nodeName, "pollInterval", pollInterval)
7696
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
7797
setupLog.Error(err, "Failed to run daemon")
7898
os.Exit(1)

internal/daemon/reconciler.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,24 @@ type BootcNodeReconciler struct {
4444
NodeName string
4545
Executor bootc.Executor
4646

47-
inflight switchOp
48-
switchDone chan event.GenericEvent
47+
inflight switchOp
48+
switchDone chan event.GenericEvent
49+
StatusChanged chan event.GenericEvent
4950
}
5051

5152
func (r *BootcNodeReconciler) SetupWithManager(mgr ctrl.Manager) error {
5253
r.switchDone = make(chan event.GenericEvent, 1)
5354

54-
return ctrl.NewControllerManagedBy(mgr).
55+
builder := ctrl.NewControllerManagedBy(mgr).
5556
For(&bootcv1alpha1.BootcNode{}).
5657
WatchesRawSource(source.Channel(r.switchDone, &handler.EnqueueRequestForObject{})).
57-
Named("bootcnode").
58-
Complete(r)
58+
Named("bootcnode")
59+
60+
if r.StatusChanged != nil {
61+
builder = builder.WatchesRawSource(source.Channel(r.StatusChanged, &handler.EnqueueRequestForObject{}))
62+
}
63+
64+
return builder.Complete(r)
5965
}
6066

6167
func (r *BootcNodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {

internal/daemon/watcher_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ func startWatcher(t *testing.T, w *StatusWatcher) (done <-chan error, cancel con
2323

2424
func TestWatcherEvents(t *testing.T) {
2525
tests := []struct {
26-
name string
27-
mkPrimary bool
28-
mkFallback bool
29-
touchPrimary bool
26+
name string
27+
mkPrimary bool
28+
mkFallback bool
29+
touchPrimary bool
3030
touchFallback bool
31-
pollInterval time.Duration
31+
pollInterval time.Duration
3232
}{
3333
{
3434
name: "Fsnotify",

0 commit comments

Comments
 (0)