diff --git a/pkg/controller/ipam/multi_cidr_range_allocator.go b/pkg/controller/ipam/multi_cidr_range_allocator.go index ae3dbd8..a283029 100644 --- a/pkg/controller/ipam/multi_cidr_range_allocator.go +++ b/pkg/controller/ipam/multi_cidr_range_allocator.go @@ -23,6 +23,7 @@ import ( "fmt" "math" "net" + "slices" "sync" "time" @@ -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 } @@ -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} }