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") + } +}