mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/kube-vip/kube-vip.git
synced 2026-09-20 08:03:47 +08:00
Merge pull request #1712 from MaxRink/fix/fix-annotations-nodelist
fix(manager): handle empty node list in annotations watcher
This commit is contained in:
@@ -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
|
||||
|
||||
21
pkg/manager/watch_annotations_test.go
Normal file
21
pkg/manager/watch_annotations_test.go
Normal file
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user