Files
kube-vip/pkg/instance/instance_bgp_attach_test.go
Justin Cichra 2b126dceed Fix bgp_attach_ip_to_interface not applied to Service VIPs (#1744)
shouldAddServiceIP() checks BGPAttachIPToInterface on a per-service
config struct. NewInstance() builds that struct fresh for each Service,
copying over most fields from the global config, missing this one. As
a result the flag has no effect regardless of its value, and BGP-mode
Service VIPs are never bound to the interface.

Copy the field at both construction sites where it's built, and add
a regression test covering the propagation.

Signed-off-by: Justin Cichra <jrcichra@yahoo.com>
2026-08-31 00:20:08 +02:00

63 lines
1.6 KiB
Go

package instance_test
import (
"context"
"sync"
"testing"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/kube-vip/kube-vip/pkg/arp"
"github.com/kube-vip/kube-vip/pkg/instance"
"github.com/kube-vip/kube-vip/pkg/kubevip"
"github.com/kube-vip/kube-vip/pkg/networkinterface"
"github.com/kube-vip/kube-vip/pkg/route"
)
func TestNewInstance_PropagatesBGPAttachIPToInterface(t *testing.T) {
tests := []struct {
name string
attach bool
}{
{name: "attach enabled is propagated", attach: true},
{name: "attach disabled is propagated", attach: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
globalConfig := &kubevip.Config{
Interface: "lo",
VIPSubnet: "32",
EnableBGP: true,
BGPAttachIPToInterface: tt.attach,
}
svc := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "test-svc",
Namespace: "default",
Annotations: map[string]string{
kubevip.LoadbalancerIPAnnotation: "10.0.1.2",
},
},
}
inst, err := instance.NewInstance(context.Background(), svc, globalConfig,
networkinterface.NewManager(), arp.NewManager(globalConfig), route.NewManager(),
nil, &sync.WaitGroup{})
if err != nil {
t.Fatalf("NewInstance() error = %v", err)
}
if len(inst.VIPConfigs) != 1 {
t.Fatalf("VIPConfigs len = %d, want 1", len(inst.VIPConfigs))
}
if got := inst.VIPConfigs[0].BGPAttachIPToInterface; got != tt.attach {
t.Fatalf("BGPAttachIPToInterface = %t, want %t", got, tt.attach)
}
})
}
}