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

Fix overwriting etcd data when local subnet file exists #1505

Merged
merged 2 commits into from
Mar 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions subnet/etcdv2/local_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,31 +158,7 @@ func (m *LocalManager) tryAcquireLease(ctx context.Context, config *Config, extI
var sn6 ip.IP6Net
if !m.previousSubnet.Empty() {
// use previous subnet
if l := findLeaseBySubnet(leases, m.previousSubnet); l != nil {
// Make sure the existing subnet is still within the configured network
if isSubnetConfigCompat(config, l.Subnet) && isIPv6SubnetConfigCompat(config, l.IPv6Subnet) {
log.Infof("Found lease (%v) matching previously leased subnet, reusing", l.Subnet)

ttl := time.Duration(0)
if !l.Expiration.IsZero() {
// Not a reservation
ttl = subnetTTL
}
exp, err := m.registry.updateSubnet(ctx, l.Subnet, l.IPv6Subnet, attrs, ttl, 0)
if err != nil {
return nil, err
}

l.Attrs = *attrs
l.Expiration = exp
return l, nil
} else {
log.Infof("Found lease (%v) matching previously leased subnet but not compatible with current config, deleting", l.Subnet)
if err := m.registry.deleteSubnet(ctx, l.Subnet, l.IPv6Subnet); err != nil {
return nil, err
}
}
} else {
if l := findLeaseBySubnet(leases, m.previousSubnet); l == nil {
// Check if the previous subnet is a part of the network and of the right subnet length
if isSubnetConfigCompat(config, m.previousSubnet) && isIPv6SubnetConfigCompat(config, m.previousIPv6Subnet) {
log.Infof("Found previously leased subnet (%v), reusing", m.previousSubnet)
Expand Down