Skip to content

Commit

Permalink
Merge pull request #1505 from zhangzhangzf/flannel-zhangzhangzf
Browse files Browse the repository at this point in the history
Fix overwriting etcd data when local subnet file exists
  • Loading branch information
manuelbuil authored Mar 8, 2022
2 parents efaa01b + 720435e commit 7d379f0
Showing 1 changed file with 1 addition and 25 deletions.
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

0 comments on commit 7d379f0

Please sign in to comment.