Skip to content

Commit

Permalink
Always reconcile ClusterCIDRs even if a finalizer is present. Do not …
Browse files Browse the repository at this point in the history
…append ClusterCIDRs if they are already present in the cidrMap which makes createClusterCIDR idempotent.
  • Loading branch information
mneverov committed Jan 3, 2025
1 parent 3a3ab8c commit d6564d5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/controller/ipam/multi_cidr_range_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"math"
"net"
"slices"
"sync"
"time"

Expand Down Expand Up @@ -1090,12 +1091,10 @@ func (r *multiCIDRRangeAllocator) reconcileCreate(ctx context.Context, clusterCI
defer r.lock.Unlock()

logger := klog.FromContext(ctx)
if needToAddFinalizer(clusterCIDR, clusterCIDRFinalizer) {
logger.V(3).Info("Creating ClusterCIDR", "clusterCIDR", clusterCIDR.Name)
if err := r.createClusterCIDR(ctx, clusterCIDR, false); err != nil {
logger.Error(err, "Unable to create ClusterCIDR", "clusterCIDR", clusterCIDR.Name)
return err
}
logger.V(3).Info("Reconciling ClusterCIDR", "clusterCIDR", clusterCIDR.Name)
if err := r.createClusterCIDR(ctx, clusterCIDR, false); err != nil {
logger.Error(err, "failed to reconcile ClusterCIDR", "clusterCIDR", clusterCIDR.Name)
return err
}
return nil
}
Expand Down Expand Up @@ -1212,7 +1211,13 @@ func (r *multiCIDRRangeAllocator) mapClusterCIDRSet(cidrMap map[string][]*cidrse
}

if clusterCIDRSetList, ok := cidrMap[nodeSelector]; ok {
cidrMap[nodeSelector] = append(clusterCIDRSetList, clusterCIDRSet)
containsClusterCIDRSet := slices.ContainsFunc(clusterCIDRSetList, func(c *cidrset.ClusterCIDR) bool {
return clusterCIDRSet.Name == c.Name
})

if !containsClusterCIDRSet {
cidrMap[nodeSelector] = append(clusterCIDRSetList, clusterCIDRSet)
}
} else {
cidrMap[nodeSelector] = []*cidrset.ClusterCIDR{clusterCIDRSet}
}
Expand Down

0 comments on commit d6564d5

Please sign in to comment.