Skip to content

Commit 79041e3

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 ea66647 commit 79041e3

3 files changed

Lines changed: 40 additions & 14 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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,23 @@ type BootcNodeReconciler struct {
5858
stageDone chan event.GenericEvent
5959
// rebootIssued tracks whether a reboot has been issued so classifyAction
6060
// can distinguish the Staged→Rebooting.
61-
rebootIssued bool
61+
rebootIssued bool
62+
StatusChanged chan event.GenericEvent
6263
}
6364

6465
func (r *BootcNodeReconciler) SetupWithManager(mgr ctrl.Manager) error {
6566
r.stageDone = make(chan event.GenericEvent, 1)
6667

67-
return ctrl.NewControllerManagedBy(mgr).
68+
builder := ctrl.NewControllerManagedBy(mgr).
6869
For(&bootcv1alpha1.BootcNode{}).
6970
WatchesRawSource(source.Channel(r.stageDone, &handler.EnqueueRequestForObject{})).
70-
Named("bootcnode").
71-
Complete(r)
71+
Named("bootcnode")
72+
73+
if r.StatusChanged != nil {
74+
builder = builder.WatchesRawSource(source.Channel(r.StatusChanged, &handler.EnqueueRequestForObject{}))
75+
}
76+
77+
return builder.Complete(r)
7278
}
7379

7480
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)