From d417a0c8e89ec6f681062c39b2ccd7afb24e8e7c Mon Sep 17 00:00:00 2001 From: Maximilian Rink Date: Sun, 23 Aug 2026 22:22:48 +0200 Subject: [PATCH] fix(manager): handle empty node list in annotations watcher Signed-off-by: Maximilian Rink --- pkg/manager/watch_annotations.go | 3 +++ pkg/manager/watch_annotations_test.go | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 pkg/manager/watch_annotations_test.go diff --git a/pkg/manager/watch_annotations.go b/pkg/manager/watch_annotations.go index 30e2b78a..9b98cd5b 100644 --- a/pkg/manager/watch_annotations.go +++ b/pkg/manager/watch_annotations.go @@ -41,6 +41,9 @@ func annotationsWatcher(ctx context.Context, clientSet, if err != nil { return err } + if len(nodeList.Items) == 0 { + return fmt.Errorf("no node found with hostname %q", config.NodeName) + } // We'll assume there's only one node with the hostname annotation. If that's not true, // there's probably bigger problems diff --git a/pkg/manager/watch_annotations_test.go b/pkg/manager/watch_annotations_test.go new file mode 100644 index 00000000..c25ea528 --- /dev/null +++ b/pkg/manager/watch_annotations_test.go @@ -0,0 +1,21 @@ +package manager + +import ( + "context" + "testing" + + "github.com/kube-vip/kube-vip/pkg/kubevip" + "k8s.io/client-go/kubernetes/fake" +) + +func TestAnnotationsWatcherHandlesEmptyNodeList(t *testing.T) { + client := fake.NewSimpleClientset() + config := &kubevip.Config{ + NodeName: "node-a", + Annotations: "kube-vip.io", + } + + if err := annotationsWatcher(context.Background(), client, client, config); err == nil { + t.Fatal("annotationsWatcher() error = nil, want empty node-list error") + } +}