mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/kube-vip/kube-vip.git
synced 2026-09-20 08:03:47 +08:00
* fix(kubevip): reject out-of-range routing protocol values Netlink carries the address and route protocol in a single byte, so a configured value above 255 was silently truncated on the wire and never matched again on readback. Reject it during config validation instead. Signed-off-by: Marcel Fest <marcel.fest@telekom.de> * feat(wireguard): qualify service tunnel IDs by protocol Sanitisation maps '-' onto the '_' separator, so "a-b/c" and "a/b-c" shared one nftables chain, and TCP and UDP on the same port collided. ServicePortIDs appends the protocol and, when sanitisation changed the name or the ID grew too long, a hash of the raw name. It also returns the previous port-only ID so existing chains can be migrated. Signed-off-by: Marcel Fest <marcel.fest@telekom.de> * fix(arp): guard manager state behind a single mutex Instances were kept in a sync.Map with a per-instance mutex for the refcount, so lookup and refcount update were not atomic: concurrent Insert and Remove could resurrect a deleted instance or drop a live one. Hold one manager mutex across both, and buffer link subscriptions so a netlink sender is never parked on an unread channel during shutdown. Signed-off-by: Marcel Fest <marcel.fest@telekom.de> * fix(instance): roll back partially created instances Instance creation added addresses, VLAN or macvlan links and DHCP clients incrementally, so a failure part way through left the node holding state nobody owned. Initialization now unwinds what it created, and link cleanup only deletes attachments this instance created that no remaining instance still uses. Namespace-dependent tests now skip unless KUBE_VIP_REQUIRE_NETNS is set, which CI sets on the privileged job so lost capabilities turn it red instead of silently skipping. Signed-off-by: Marcel Fest <marcel.fest@telekom.de> * test(e2e): give docker kill more time under parallel load The ARP suite runs four kind clusters against one Docker daemon, so acknowledging a leader kill regularly exceeded the 5s budget and failed the IPv6 failover specs before any assertion ran. Signed-off-by: Marcel Fest <marcel.fest@telekom.de> * fix: regression on preserveOnLeadershipLoss Signed-off-by: Marcel Fest <marcel.fest@telekom.de> * fix: use the introduced wireguard service_id Signed-off-by: Marcel Fest <marcel.fest@telekom.de> * fix(services): reuse link attachment ownership on service delete deleteService removed VLAN and macvlan links unconditionally, which tore down interfaces kube-vip had only adopted and interfaces another Service still used. Route the delete path through CleanupLinkAttachments and pass the remaining instances so ownership is handed over instead. Signed-off-by: Marcel Fest <marcel.fest@telekom.de> --------- Signed-off-by: Marcel Fest <marcel.fest@telekom.de>
103 lines
3.1 KiB
Go
103 lines
3.1 KiB
Go
//go:build linux
|
|
|
|
package instance
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/vishvananda/netlink"
|
|
"github.com/vishvananda/netns"
|
|
)
|
|
|
|
// requireNetworkNamespaces makes the privileged CI job fail instead of silently
|
|
// skipping when it cannot enter a network namespace.
|
|
var requireNetworkNamespaces = os.Getenv("KUBE_VIP_REQUIRE_NETNS") != ""
|
|
|
|
func TestCleanupLinkAttachmentsOnlyDeletesOwnedVLAN(t *testing.T) {
|
|
for _, test := range []struct {
|
|
name string
|
|
preexists bool
|
|
inUse bool
|
|
}{
|
|
{name: "owned VLAN", preexists: false},
|
|
{name: "adopted VLAN", preexists: true},
|
|
{name: "owned VLAN used by another Service", inUse: true},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
runtime.LockOSThread()
|
|
defer runtime.UnlockOSThread()
|
|
|
|
originalNamespace, err := netns.Get()
|
|
if err != nil {
|
|
t.Fatalf("getting current network namespace: %v", err)
|
|
}
|
|
defer originalNamespace.Close()
|
|
testNamespace, err := netns.New()
|
|
if err != nil {
|
|
if requireNetworkNamespaces {
|
|
t.Fatalf("creating isolated network namespace: %v", err)
|
|
}
|
|
t.Skipf("creating isolated network namespace: %v", err)
|
|
}
|
|
defer testNamespace.Close()
|
|
defer func() {
|
|
if err := netns.Set(originalNamespace); err != nil {
|
|
t.Errorf("restoring network namespace: %v", err)
|
|
}
|
|
}()
|
|
|
|
parent := &netlink.Dummy{LinkAttrs: netlink.LinkAttrs{Name: "kvattach0"}}
|
|
if err := netlink.LinkAdd(parent); err != nil {
|
|
t.Fatalf("creating parent interface: %v", err)
|
|
}
|
|
if err := netlink.LinkSetUp(parent); err != nil {
|
|
t.Fatalf("bringing up parent interface: %v", err)
|
|
}
|
|
if test.preexists {
|
|
vlan := &netlink.Vlan{LinkAttrs: netlink.LinkAttrs{Name: "kvattach0.42", ParentIndex: parent.Attrs().Index}, VlanId: 42}
|
|
if err := netlink.LinkAdd(vlan); err != nil {
|
|
t.Fatalf("creating existing VLAN: %v", err)
|
|
}
|
|
}
|
|
|
|
instance := &Instance{}
|
|
if err := instance.addVLAN(parent.Attrs().Name, 42); err != nil {
|
|
t.Fatalf("adding VLAN attachment: %v", err)
|
|
}
|
|
if instance.vlanOwned.Load() == test.preexists {
|
|
t.Fatalf("vlanOwned = %t, want %t", instance.vlanOwned.Load(), !test.preexists)
|
|
}
|
|
var remaining []*Instance
|
|
if test.inUse {
|
|
remaining = []*Instance{{IsVLAN: true, VLANInterface: instance.VLANInterface}}
|
|
}
|
|
if err := instance.CleanupLinkAttachments(remaining...); err != nil {
|
|
t.Fatalf("cleaning attachments: %v", err)
|
|
}
|
|
if test.inUse {
|
|
if !remaining[0].vlanOwned.Load() {
|
|
t.Fatal("remaining Service did not receive VLAN cleanup ownership")
|
|
}
|
|
if _, err := netlink.LinkByName("kvattach0.42"); err != nil {
|
|
t.Fatalf("VLAN was removed while a Service still used it: %v", err)
|
|
}
|
|
if err := remaining[0].CleanupLinkAttachments(); err != nil {
|
|
t.Fatalf("cleaning transferred attachment: %v", err)
|
|
}
|
|
}
|
|
|
|
_, err = netlink.LinkByName("kvattach0.42")
|
|
var notFound netlink.LinkNotFoundError
|
|
if test.preexists && err != nil {
|
|
t.Fatalf("adopted VLAN was removed: %v", err)
|
|
}
|
|
if !test.preexists && !errors.As(err, ¬Found) {
|
|
t.Fatalf("owned VLAN remains after cleanup: %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|