Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service: Always allocate higher ID for svc/backend #18113

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/service/id_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func (alloc *IDAllocator) acquireLocalID(svc loadbalancer.L3n4Addr, desiredID ui
if desiredID != 0 {
foundSVC, ok := alloc.entitiesID[desiredID]
if !ok {
if desiredID >= alloc.nextID {
// We don't set nextID to desiredID+1 here, as we don't want to
// duplicate the logic which deals with the rollover. Next
// invocation of acquireLocalID(..., 0) will fix the nextID.
alloc.nextID = desiredID
}
return alloc.addID(svc, desiredID), nil
}
return nil, fmt.Errorf("Service ID %d is already registered to %q",
Expand Down
18 changes: 18 additions & 0 deletions pkg/service/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ var _ = Suite(&IDAllocTestSuite{})

func (e *IDAllocTestSuite) SetUpTest(c *C) {
serviceIDAlloc.resetLocalID()
backendIDAlloc.resetLocalID()
}

func (e *IDAllocTestSuite) TearDownTest(c *C) {
serviceIDAlloc.resetLocalID()
backendIDAlloc.resetLocalID()
}

var (
Expand All @@ -50,6 +52,14 @@ var (
IP: net.IPv6loopback,
L4Addr: loadbalancer.L4Addr{Port: 2, Protocol: "UDP"},
}
l3n4Addr5 = loadbalancer.L3n4Addr{
IP: net.ParseIP("::2"),
L4Addr: loadbalancer.L4Addr{Port: 2, Protocol: "UDP"},
}
l3n4Addr6 = loadbalancer.L3n4Addr{
IP: net.ParseIP("::3"),
L4Addr: loadbalancer.L4Addr{Port: 2, Protocol: "UDP"},
}
wantL3n4AddrID = &loadbalancer.L3n4AddrID{
ID: 123,
L3n4Addr: l3n4Addr2,
Expand Down Expand Up @@ -178,6 +188,14 @@ func (s *IDAllocTestSuite) TestBackendID(c *C) {
existingID1, err := LookupBackendID(l3n4Addr1)
c.Assert(err, Equals, nil)
c.Assert(existingID1, Equals, id1)

// Check that the backend ID restoration advances the nextID
err = RestoreBackendID(l3n4Addr5, firstBackendID+10)
c.Assert(err, Equals, nil)
id3, err := AcquireBackendID(l3n4Addr6)
c.Assert(err, Equals, nil)
c.Assert(id3, Equals, firstBackendID+11)

}

func (s *IDAllocTestSuite) BenchmarkAllocation(c *C) {
Expand Down